public async Task AuthenticateWithAuthCodeHonorsReplyUrl([Values(null, ReplyUrl)] string replyUri) { AuthorizationCodeCredentialOptions options = null; if (replyUri != null) { options = new AuthorizationCodeCredentialOptions { RedirectUri = new Uri(replyUri) }; } var context = new TokenRequestContext(new[] { Scope }); expectedReplyUri = replyUri; AuthorizationCodeCredential cred = InstrumentClient( new AuthorizationCodeCredential(TenantId, ClientId, clientSecret, authCode, options, mockConfidentialMsalClient)); AccessToken token = await cred.GetTokenAsync(context); Assert.AreEqual(token.Token, expectedToken, "Should be the expected token value"); AccessToken token2 = await cred.GetTokenAsync(context); Assert.AreEqual(token2.Token, expectedToken, "Should be the expected token value"); }
public async Task AuthenticateWithAuthCodeMockAsync() { var expectedToken = Guid.NewGuid().ToString(); var authCode = Guid.NewGuid().ToString(); var clientId = Guid.NewGuid().ToString(); var tenantId = Guid.NewGuid().ToString(); var clientSecret = Guid.NewGuid().ToString(); MockResponse response = CreateAuthorizationResponse(expectedToken); var mockTransport = new MockTransport(request => ProcessMockRequest(request, tenantId, expectedToken)); var options = new TokenCredentialOptions() { Transport = mockTransport }; AuthorizationCodeCredential cred = InstrumentClient(new AuthorizationCodeCredential(tenantId, clientId, clientSecret, authCode, options)); AccessToken token = await cred.GetTokenAsync(new TokenRequestContext(new string[] { "https://vault.azure.net/.default" })); Assert.AreEqual(token.Token, expectedToken); AccessToken token2 = await cred.GetTokenAsync(new TokenRequestContext(new string[] { "https://managemnt.azure.com/.default" })); Assert.AreEqual(token.Token, expectedToken); }
public async Task AuthenticateWithAutCodeHonorsRedirectUri([Values(null, redirectUriString)] string redirectUri) { var mockTransport = new MockTransport(req => { if (redirectUri is not null && req.Uri.Path.EndsWith("/token")) { var content = ReadMockRequestContent(req).GetAwaiter().GetResult(); Assert.That(WebUtility.UrlDecode(content), Does.Contain(redirectUri ?? string.Empty)); } return(CreateMockMsalTokenResponse(200, expectedToken, TenantId, "foo")); }); var options = new AuthorizationCodeCredentialOptions { Transport = mockTransport }; if (redirectUri != null) { options.RedirectUri = new Uri(redirectUri); } options.Retry.MaxDelay = TimeSpan.Zero; var pipeline = CredentialPipeline.GetInstance(options); AuthorizationCodeCredential credential = InstrumentClient(new AuthorizationCodeCredential(TenantId, ClientId, clientSecret, authCode, options, null, pipeline)); var context = new TokenRequestContext(new[] { Scope }, tenantId: TenantId); await credential.GetTokenAsync(context); }
public async Task AuthenticateWithAuthCodeHonorsTenantId([Values(null, TenantIdHint)] string tenantId, [Values(true)] bool allowMultiTenantAuthentication) { var context = new TokenRequestContext(new[] { Scope }, tenantId: tenantId); expectedTenantId = TenantIdResolver.Resolve(TenantId, context); AuthorizationCodeCredential cred = InstrumentClient( new AuthorizationCodeCredential(TenantId, ClientId, clientSecret, authCode, options, mockConfidentialMsalClient)); AccessToken token = await cred.GetTokenAsync(context); Assert.AreEqual(token.Token, expectedToken, "Should be the expected token value"); AccessToken token2 = await cred.GetTokenAsync(context); Assert.AreEqual(token2.Token, expectedToken, "Should be the expected token value"); }