示例#1
0
        private static async Task RequestModifier(ClientCredentialsGrantHandler x, HttpRequestMessage request, CancellationToken token)
        {
            var auth = request.Headers.Authorization;

            if (auth != null)
            {
                var model = await x.GetAccessTokenAsync();

                request.Headers.Authorization = new AuthenticationHeaderValue(auth.Scheme, model.AccessToken);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            var handler = new ClientCredentialsGrantHandler("http://localhost:9090");

            var api = OAuth2RestClient.For <IMyApp>("http://localhost:9090", handler);

            string result = api.GetHelloAsync().Result;

            Console.WriteLine(result);

            int x = 0;
        }
示例#3
0
 public static T For <T>(string url, ClientCredentialsGrantHandler grantHandlerType)
 {
     return(RestClient.For <T>(url, (request, token) => RequestModifier(grantHandlerType, request, token)));
 }