Пример #1
0
 ///<summary>This is the required method for IHttpExecuteInterceptor.  This method allows us to hijack our own requests and add headers or other values to the context.
 ///Google assumes that this method will attach needed Authorization headers, which we must use a Bearer token for.</summary>
 public System.Threading.Tasks.Task InterceptAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     BearerToken.AuthorizationHeaderAccessMethod bearerTokenInterceptor = new BearerToken.AuthorizationHeaderAccessMethod();
     //Overwrite the Authorization header with a bearer token.
     bearerTokenInterceptor.Intercept(request, AccessToken);
     //We can't use Task.CompletedTask because we are not on .NET 4.6 at this time.  Simply run an empty task.
     return(System.Threading.Tasks.Task.Run(() => { }));
 }
Пример #2
0
            public async Task InterceptAsync(HttpRequestMessage request, CancellationToken taskCancellationToken)
            {
                var tokenResult = await _accessTokenProvider.RequestAccessToken(
                    new AccessTokenRequestOptions
                {
                    Scopes = new[] { "https://www.googleapis.com/auth/drive.appdata" }
                });

                if (tokenResult.TryGetToken(out AccessToken token))
                {
                    Console.WriteLine(
                        $"token:[ expires: {token.Expires} scopes: {string.Join("|", token.GrantedScopes)}");

                    _accessMethod.Intercept(request, token.Value);
                }
            }