Beispiel #1
0
        public async Task Scoped_MaybeWithScopes_WithCustomTokenUrl(string[] scopes, string customTokenUrl, string expectedTokenUrl)
        {
            var fakeMessageHandler = new FetchesTokenMessageHandler();
            var credential         = (new ComputeCredential(new ComputeCredential.Initializer(customTokenUrl)
            {
                HttpClientFactory = new MockHttpClientFactory(fakeMessageHandler)
            }) as IGoogleCredential).MaybeWithScopes(scopes) as ComputeCredential;

            AssertScoped(credential, scopes, expectedTokenUrl);
            await AssertUsesScopedUrl(credential, fakeMessageHandler, expectedTokenUrl);
        }
Beispiel #2
0
        public async Task Scoped_Initializer_WithDefaultTokenUrl(string[] scopes, string expectedTokenUrl)
        {
            var fakeMessageHandler = new FetchesTokenMessageHandler();
            var credential         = new ComputeCredential(new ComputeCredential.Initializer()
            {
                Scopes            = scopes,
                HttpClientFactory = new MockHttpClientFactory(fakeMessageHandler)
            });

            AssertScoped(credential, scopes, expectedTokenUrl);
            await AssertUsesScopedUrl(credential, fakeMessageHandler, expectedTokenUrl);
        }
Beispiel #3
0
        public async Task Jwt_WithUser_AccessToken(bool useJwtAccessWithScopes)
        {
            var clock       = new MockClock(new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));
            var handler     = new FetchesTokenMessageHandler();
            var initializer = new ServiceAccountCredential.Initializer("some-id")
            {
                UseJwtAccessWithScopes = useJwtAccessWithScopes,
                Clock             = clock,
                User              = "******",
                HttpClientFactory = new MockHttpClientFactory(handler)
            }.FromPrivateKey(PrivateKey);
            var cred = new ServiceAccountCredential(initializer);

            Assert.False(cred.HasExplicitScopes); // Must be false for the remainder of this test to be valid.

            var token = await cred.GetAccessTokenForRequestAsync("uri0");

            Assert.Equal("a", token);
        }
Beispiel #4
0
 private async Task AssertUsesScopedUrl(ComputeCredential credential, FetchesTokenMessageHandler fakeMessageHandler, string expectedTokenUrl)
 {
     Assert.NotNull(await credential.GetAccessTokenForRequestAsync());
     Assert.Equal(1, fakeMessageHandler.Calls);
     Assert.Equal(expectedTokenUrl, fakeMessageHandler.Requests.First().RequestUri.AbsoluteUri);
 }