public void TestSetup(TokenCredentialOptions options = null) { expectedTenantId = null; expectedReplyUri = null; authCode = Guid.NewGuid().ToString(); options = options ?? new TokenCredentialOptions(); expectedToken = TokenGenerator.GenerateToken(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow.AddHours(1)); expectedUserAssertion = Guid.NewGuid().ToString(); expiresOn = DateTimeOffset.Now.AddHours(1); result = new AuthenticationResult( expectedToken, false, null, expiresOn, expiresOn, TenantId, new MockAccount("username"), null, new[] { Scope }, Guid.NewGuid(), null, "Bearer"); mockConfidentialMsalClient = new MockMsalConfidentialClient(null, null, null, null, null, options) .WithSilentFactory( (_, _tenantId, _replyUri, _) => { Assert.AreEqual(expectedTenantId, _tenantId); Assert.AreEqual(expectedReplyUri, _replyUri); return(new ValueTask <AuthenticationResult>(result)); }) .WithAuthCodeFactory( (_, _tenantId, _replyUri, _) => { Assert.AreEqual(expectedTenantId, _tenantId); Assert.AreEqual(expectedReplyUri, _replyUri); return(result); }) .WithOnBehalfOfFactory( (_, _, userAssertion, _, _) => { Assert.AreEqual(expectedUserAssertion, userAssertion.Assertion); return(new ValueTask <AuthenticationResult>(result)); }) .WithClientFactory( (_, _tenantId) => { Assert.AreEqual(expectedTenantId, _tenantId); return(result); }); expectedCode = Guid.NewGuid().ToString(); mockPublicMsalClient = new MockMsalPublicClient(null, null, null, null, options); deviceCodeResult = MockMsalPublicClient.GetDeviceCodeResult(deviceCode: expectedCode); mockPublicMsalClient.DeviceCodeResult = deviceCodeResult; var publicResult = new AuthenticationResult( expectedToken, false, null, expiresOn, expiresOn, TenantId, new MockAccount("username"), null, new[] { Scope }, Guid.NewGuid(), null, "Bearer"); mockPublicMsalClient.SilentAuthFactory = (_, tId) => { Assert.AreEqual(expectedTenantId, tId); return(publicResult); }; mockPublicMsalClient.DeviceCodeAuthFactory = (_, _) => { // Assert.AreEqual(tenantId, tId); return(publicResult); }; mockPublicMsalClient.InteractiveAuthFactory = (_, _, _, _, tenant, _, _) => { Assert.AreEqual(expectedTenantId, tenant, "TenantId passed to msal should match"); return(result); }; mockPublicMsalClient.SilentAuthFactory = (_, tenant) => { Assert.AreEqual(expectedTenantId, tenant, "TenantId passed to msal should match"); return(result); }; mockPublicMsalClient.ExtendedSilentAuthFactory = (_, _, _, tenant, _, _) => { Assert.AreEqual(expectedTenantId, tenant, "TenantId passed to msal should match"); return(result); }; mockPublicMsalClient.UserPassAuthFactory = (_, tenant) => { Assert.AreEqual(expectedTenantId, tenant, "TenantId passed to msal should match"); return(result); }; mockPublicMsalClient.RefreshTokenFactory = (_, _, _, _, tenant, _, _) => { Assert.AreEqual(expectedTenantId, tenant, "TenantId passed to msal should match"); return(result); }; }
public void Setup() { _encodedToken = TokenGenerator.GenerateToken(tenantId, clientId, objectId, myUpn, DateTime.Now.AddHours(1)); }