public void CtorValidation() { OnBehalfOfCredential cred; string userAssertion = Guid.NewGuid().ToString(); string clientSecret = Guid.NewGuid().ToString(); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(null, ClientId, clientSecret, userAssertion, null)); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, null, clientSecret, userAssertion, null)); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, ClientId, default(string), userAssertion)); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, ClientId, clientSecret, null, null)); cred = new OnBehalfOfCredential(TenantId, ClientId, clientSecret, userAssertion, null); // Assert Assert.AreEqual(clientSecret, cred._client._clientSecret); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(null, ClientId, new X509Certificate2(), userAssertion)); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, null, new X509Certificate2(), userAssertion)); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, ClientId, default(string), userAssertion)); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, ClientId, new X509Certificate2(), null)); cred = new OnBehalfOfCredential(TenantId, ClientId, new X509Certificate2(), userAssertion); // Assert Assert.NotNull(cred._client._certificateProvider); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(null, ClientId, new X509Certificate2(), userAssertion, new OnBehalfOfCredentialOptions())); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, null, new X509Certificate2(), userAssertion, new OnBehalfOfCredentialOptions())); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, ClientId, default(X509Certificate2), userAssertion, new OnBehalfOfCredentialOptions())); Assert.Throws <ArgumentNullException>(() => new OnBehalfOfCredential(TenantId, ClientId, new X509Certificate2(), null, new OnBehalfOfCredentialOptions())); cred = new OnBehalfOfCredential(TenantId, ClientId, new X509Certificate2(), userAssertion, new OnBehalfOfCredentialOptions()); // Assert Assert.NotNull(cred._client._certificateProvider); }
public async Task UsesTenantIdHint( [Values(null, TenantIdHint)] string tenantId, [Values(true)] bool allowMultiTenantAuthentication, [Values(null, TenantId)] string explicitTenantId) { TestSetup(); options = new OnBehalfOfCredentialOptions(); options.AllowMultiTenantAuthentication = allowMultiTenantAuthentication; var context = new TokenRequestContext(new[] { Scope }, tenantId: tenantId); expectedTenantId = TenantIdResolver.Resolve(explicitTenantId, context, options.AllowMultiTenantAuthentication); OnBehalfOfCredential client = InstrumentClient( new OnBehalfOfCredential( TenantId, ClientId, "secret", expectedUserAssertion, options as OnBehalfOfCredentialOptions, null, mockConfidentialMsalClient)); var token = await client.GetTokenAsync(new TokenRequestContext(MockScopes.Default), default); Assert.AreEqual(token.Token, expectedToken, "Should be the expected token value"); }
public void OnBehalfOfCredentialUsage() { string clientSecret = "00000000-0000-0000-0000-000000000000"; string clientId = "00000000-0000-0000-0000-000000000000"; string userAccessToken = "00000000-0000-0000-0000-000000000000"; #region Snippet:OnBehalfOfCredentialUsage var oboCredential = new OnBehalfOfCredential(clientId, clientSecret, userAccessToken); var client = new SecretClient(new Uri("https://myvault.vault.azure.net/"), oboCredential); #endregion }