private static BearerTokenAuthenticationHandler CreateHandler(
            IOAuth2TokenStore tokenStore = null,
            IGogoKitConfiguration config = null,
            IOAuth2Client client         = null,
            OAuth2Token token            = null,
            HttpResponseMessage resp     = null)
        {
            var mockTokenStore = new Mock <IOAuth2TokenStore>(MockBehavior.Loose);

            mockTokenStore.Setup(s => s.GetTokenAsync()).Returns(Task.FromResult(token));

            var mockOAuthClient = new Mock <IOAuth2Client>(MockBehavior.Loose);

            mockOAuthClient.Setup(o => o.GetAccessTokenAsync(
                                      It.IsAny <string>(),
                                      It.IsAny <IEnumerable <string> >(),
                                      It.IsAny <IDictionary <string, string> >()))
            .Returns(Task.FromResult(token));
            return(new BearerTokenAuthenticationHandler(
                       client ?? mockOAuthClient.Object,
                       tokenStore ?? mockTokenStore.Object,
                       config ?? new GogoKitConfiguration("c", "s"))
            {
                InnerHandler = new FakeDelegatingHandler(resp: resp)
            });
        }
예제 #2
0
        public BearerTokenAuthenticationHandler(
            IOAuth2Client oauthClient,
            IOAuth2TokenStore tokenStore,
            IGogoKitConfiguration configuration)
        {
            Requires.ArgumentNotNull(oauthClient, nameof(oauthClient));
            Requires.ArgumentNotNull(tokenStore, nameof(tokenStore));
            Requires.ArgumentNotNull(configuration, nameof(configuration));

            _oauthClient   = oauthClient;
            _tokenStore    = tokenStore;
            _configuration = configuration;
        }
 public AccessTokenStore(IOAuth2Client client)
 {
     _client = client;
 }