Exemple #1
0
            /// <summary>Constructs a new initializer using the given token server URL.</summary>
            public Initializer(string tokenServerUrl)
            {
                TokenServerUrl = tokenServerUrl;

                AccessMethod = new BearerToken.AuthorizationHeaderAccessMethod();
                Clock        = SystemClock.Default;
                DefaultExponentialBackOffPolicy = ExponentialBackOffPolicy.UnsuccessfulResponse503;
            }
 ///<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(() => { }));
 }
Exemple #3
0
            /// <summary>Constructs a new initializer.</summary>
            /// <param name="authorizationServerUrl">Authorization server URL</param>
            /// <param name="tokenServerUrl">Token server URL</param>
            public Initializer(string authorizationServerUrl, string tokenServerUrl)
            {
                AuthorizationServerUrl = authorizationServerUrl;
                TokenServerUrl         = tokenServerUrl;

                Scopes       = new List <string>();
                AccessMethod = new BearerToken.AuthorizationHeaderAccessMethod();
                DefaultExponentialBackOffPolicy = ExponentialBackOffPolicy.UnsuccessfulResponse503;
                Clock = SystemClock.Default;
            }
        public void AuthorizationHeaderAccessMethod_GetAccessToken()
        {
            var request = new HttpRequestMessage();

            request.Headers.Authorization = new AuthenticationHeaderValue("a", "1");
            var accessToken = new BearerToken.AuthorizationHeaderAccessMethod().GetAccessToken(request);

            Assert.Null(accessToken);

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "abc");
            accessToken = new BearerToken.AuthorizationHeaderAccessMethod().GetAccessToken(request);
            Assert.Equal("abc", accessToken);
        }
            /// <summary>Constructs a new initializer.</summary>
            /// <param name="authorizationServerUrl">Authorization server URL</param>
            /// <param name="tokenServerUrl">Token server URL</param>
            public Initializer(string authorizationServerUrl, string tokenServerUrl)
            {
                AuthorizationServerUrl = authorizationServerUrl;
                TokenServerUrl = tokenServerUrl;

                Scopes = new List<string>();
                AccessMethod = new BearerToken.AuthorizationHeaderAccessMethod();
                DefaultExponentialBackOffPolicy = ExponentialBackOffPolicy.UnsuccessfulResponse503;
                Clock = SystemClock.Default;
            }