public void FriendlyInformationTest() { var ac = new ApplicationCredential("appId", "appSecret"); var expected = "appId: appId, appSecret: appSecret"; Assert.Equal(expected, ac.ToString()); }
public void ConstructorNullParametersTest() { Assert.Throws<ArgumentNullException>(() => { var ac = new ApplicationCredential(null, null); }); }
public InMemoryTokenManager(ITokenRetriever tokenRetriever, ICredentialProvider credentialProvider) { _tokenRetriever = tokenRetriever; _credential = credentialProvider.GenerateCredential(); _memoryTokens = new ConcurrentDictionary <ApplicationCredential, ApplicationToken>(); }
public InMemoryTokenManager(ITokenRetriever tokenRetriever, ICredentialProvider credentialProvider) { _tokenRetriever = tokenRetriever; _credential = credentialProvider.GenerateCredential(); _memoryTokens = new ConcurrentDictionary<ApplicationCredential, ApplicationToken>(); }
public void ConstructorNullParametersTest() { Assert.Throws <ArgumentNullException>(() => { var ac = new ApplicationCredential(null, null); }); }
// Credentials ----------------------------- /// <summary> /// Get the credential with the specified name. /// </summary> /// <param name="name">Name</param> /// <returns></returns> public virtual IApplicationCredential GetCredential(string name) { IApplicationCredential credential = new ApplicationCredential { Name = "[unkwnon]" }; return(Options?.Settings?.AppConfiguration?.Credentials.Find(p => p.KeyEquals(name))); }
public void EqualityTest() { var appId = Guid.NewGuid().ToString(); var appSecret = Guid.NewGuid().ToString(); var ac1 = new ApplicationCredential(appId, appSecret); var ac2 = new ApplicationCredential(appId, appSecret); Assert.Equal(ac1, ac2); Assert.Equal(ac1.GetHashCode(), ac2.GetHashCode()); }
public async Task <AuthenticationResult> AcquireTokenByAuthorizationCodeAsync(string authority, string code, ApplicationCredential credential, Uri redirectUri, string resource) { AuthenticationContext authContext; ISecureClientSecret secret; authority.AssertNotEmpty(nameof(authority)); code.AssertNotEmpty(nameof(code)); redirectUri.AssertNotNull(nameof(redirectUri)); resource.AssertNotEmpty(nameof(resource)); try { authContext = new AuthenticationContext(authority); secret = new SecureClientSecret(credential.ApplicationSecret); return(await authContext.AcquireTokenByAuthorizationCodeAsync( code, redirectUri, new ClientCredential( credential.ApplicationId, secret), resource).ConfigureAwait(false)); } finally { authContext = null; secret = null; } }
/// <summary> /// Gets an access token from the authority. /// </summary> /// <param name="authority">Address of the authority to issue the token.</param> /// <param name="resource">Identifier of the target resource that is the recipient of the requested token.</param> /// <param name="credential">The application credential to use for token acquisition.</param> /// <param name="token">Assertion token representing the user.</param> /// <returns>An instance of <see cref="AuthenticationResult"/> that represented the access token.</returns> /// <exception cref="System.ArgumentException"> /// <paramref name="authority"/> is empty or null. /// or /// <paramref name="resource"/> is empty or null. /// or /// <paramref name="token"/> is empty or null. /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="credential"/> is null. /// </exception> public async Task <AuthenticationResult> GetAccessTokenAsync(string authority, string resource, ApplicationCredential credential, string token) { AuthenticationContext authContext; AuthenticationResult authResult; DistributedTokenCache tokenCache; ISecureClientSecret secret; authority.AssertNotEmpty(nameof(authority)); resource.AssertNotEmpty(nameof(authority)); credential.AssertNotNull(nameof(credential)); token.AssertNotEmpty(nameof(token)); try { if (credential.UseCache) { tokenCache = new DistributedTokenCache(provider, resource); authContext = new AuthenticationContext(authority, tokenCache); } else { authContext = new AuthenticationContext(authority); } secret = new SecureClientSecret(credential.ApplicationSecret); authResult = await authContext.AcquireTokenAsync( resource, new ClientCredential( credential.ApplicationId, secret), new UserAssertion(token, AssertionType)).ConfigureAwait(false); return(authResult); } finally { authContext = null; tokenCache = null; secret = null; } }
public void ConstructorEmptyStringParametersTest() { Assert.Throws<ArgumentNullException>(() => { var ac = new ApplicationCredential("", ""); }); }
/// <summary> /// Gets an access token from the authority. /// </summary> /// <param name="authority">Address of the authority to issue the token.</param> /// <param name="resource">Identifier of the target resource that is the recipient of the requested token.</param> /// <param name="credential">The application credential to use for token acquisition.</param> /// <returns>An instance of <see cref="AuthenticationResult"/> that represented the access token.</returns> /// <exception cref="System.ArgumentException"> /// <paramref name="authority"/> is empty or null. /// or /// <paramref name="resource"/> is empty or null. /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="credential"/> is null. /// </exception> public async Task <AuthenticationResult> GetAccessTokenAsync(string authority, string resource, ApplicationCredential credential) { AuthenticationContext authContext; AuthenticationResult authResult; DistributedTokenCache tokenCache; Microsoft.IdentityModel.Clients.ActiveDirectory.ISecureClientSecret secret; authority.AssertNotEmpty(nameof(authority)); resource.AssertNotEmpty(nameof(resource)); credential.AssertNotNull(nameof(credential)); try { if (credential.UseCache) { tokenCache = new DistributedTokenCache(provider, resource, $"AppOnly::{authority}::{resource}"); authContext = new AuthenticationContext(authority, tokenCache); } else { authContext = new AuthenticationContext(authority); } secret = new SecureClientSecret(credential.ApplicationSecret); authResult = await authContext.AcquireTokenAsync( resource, new ClientCredential( credential.ApplicationId, secret)).ConfigureAwait(false); return(authResult); } finally { authContext = null; authResult = null; secret = null; tokenCache = null; } }
public Task<ApplicationToken> RetrieveTokenRemotely(ApplicationCredential credential) { throw new NotImplementedException(); }
public Task <ApplicationToken> RetrieveTokenRemotely(ApplicationCredential credential) { throw new NotImplementedException(); }
public void ConstructorEmptyStringParametersTest() { Assert.Throws <ArgumentNullException>(() => { var ac = new ApplicationCredential("", ""); }); }