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); } }
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; }
public static T For <T>(string url, ClientCredentialsGrantHandler grantHandlerType) { return(RestClient.For <T>(url, (request, token) => RequestModifier(grantHandlerType, request, token))); }