internal AdalAuthenticationProviderBase( string clientId, string returnUrl, AuthenticationContext authenticationContext) { if (string.IsNullOrEmpty(clientId)) { throw new ServiceException( new Error { Code = OAuthConstants.ErrorCodes.AuthenticationFailure, Message = "AdalAuthenticationProvider requires a client ID for authenticating users." }); } this.clientId = clientId; this.returnUrl = returnUrl; if (authenticationContext != null) { this.authenticationContextWrapper = new AuthenticationContextWrapper(authenticationContext); } else { this.authenticationContextWrapper = new AuthenticationContextWrapper( new AuthenticationContext(OAuthConstants.ActiveDirectoryAuthenticationServiceUrl)); } this.adalCredentialCache = new AdalCredentialCache(this.authenticationContextWrapper.TokenCache); }
/// <summary> /// Initialises a new instance of the <see cref="AdalWrapper"/> class. /// </summary> /// <param name="authContext"><see cref="IAuthenticationContextWrapper"/> instance.</param> public AdalWrapper(IAuthenticationContextWrapper authContext) { if (authContext == null) { throw new ArgumentNullException(nameof(authContext)); } this._authContext = authContext; }
/// <summary> /// Constructor for unit testing. /// </summary> /// <param name="clientId">The ID of the client.</param> /// <param name="returnUrl">The return URL for the client.</param> /// <param name="authenticationContextWrapper">The context for authenticating against AAD.</param> internal AdalAuthenticationProviderBase( string clientId, string returnUrl, IAuthenticationContextWrapper authenticationContextWrapper) { this.clientId = clientId; this.returnUrl = returnUrl; this.adalCredentialCache = new AdalCredentialCache(authenticationContextWrapper.TokenCache); this.authenticationContextWrapper = authenticationContextWrapper; }
internal AdalAuthenticationProvider( string clientId, string returnUrl, IAuthenticationContextWrapper authenticationContextWrapper) : base(clientId, returnUrl, authenticationContextWrapper) { this.AuthenticateUser = this.PromptUserForAuthenticationAsync; this.AuthenticateUserSilently = this.SilentlyAuthenticateUserAsync; this.oAuthHelper = new OAuthHelper(); }
internal AdalAuthenticationProvider( string clientId, X509Certificate2 clientCertificate, string returnUrl, IAuthenticationContextWrapper authenticationContextWrapper) : base(clientId, returnUrl, authenticationContextWrapper) { this.clientCertificate = clientCertificate; this.AuthenticateUser = this.PromptUserForAuthenticationWithClientCertificateAsync; this.AuthenticateUserSilently = this.SilentlyAuthenticateUserWithClientCertificateAsync; this.oAuthHelper = new OAuthHelper(); }
/// <summary> /// Initialises a new instance of the <see cref="WebTestService"/> class. /// </summary> /// <param name="settings"><see cref="IWebTestSettingsElement"/> instance.</param> /// <param name="authenticationContext"><see cref="IAuthenticationContextWrapper"/> instance.</param> public WebTestService(IWebTestSettingsElement settings, IAuthenticationContextWrapper authenticationContext) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } this._auth = settings.Authentication.Clone(); this._appInsights = settings.ApplicationInsight.Clone(); this._webTests = settings.WebTests.Clone().OfType <WebTestElement>().ToList(); if (authenticationContext == null) { throw new ArgumentNullException(nameof(authenticationContext)); } this._authenticationContext = authenticationContext; }
public async Task AuthenticateAsync_AuthenticateWithoutDiscoveryService( IAuthenticationContextWrapper authenticationContextWrapper, IAuthenticationResult authenticationResult) { this.serviceInfo.BaseUrl = "https://localhost"; this.serviceInfo.ServiceResource = serviceResourceId; this.authenticationProvider.authenticationContextWrapper = authenticationContextWrapper; var accountSession = await this.authenticationProvider.AuthenticateAsync(); Assert.AreEqual(accountSession, this.authenticationProvider.CurrentAccountSession, "Account session not cached correctly."); Assert.AreEqual(authenticationResult.AccessToken, accountSession.AccessToken, "Unexpected access token set."); Assert.AreEqual(authenticationResult.AccessTokenType, accountSession.AccessTokenType, "Unexpected access token type set."); Assert.AreEqual(AccountType.ActiveDirectory, accountSession.AccountType, "Unexpected account type set."); Assert.IsTrue(accountSession.CanSignOut, "CanSignOut set to false."); Assert.AreEqual(this.serviceInfo.AppId, accountSession.ClientId, "Unexpected client ID set."); Assert.AreEqual(authenticationResult.ExpiresOn, accountSession.ExpiresOnUtc, "Unexpected expiration set."); Assert.IsNull(accountSession.UserId, "Unexpected user ID set."); }
public async Task AuthenticateAsync_AuthenticateWithoutDiscoveryService( IAuthenticationContextWrapper authenticationContextWrapper, IAuthenticationResult authenticationResult) { this.serviceInfo.BaseUrl = "https://localhost"; this.serviceInfo.ServiceResource = serviceResourceId; this.authenticationProvider.authenticationContextWrapper = authenticationContextWrapper; var accountSession = await this.authenticationProvider.AuthenticateAsync(); Assert.AreEqual(accountSession, this.authenticationProvider.CurrentAccountSession, "Account session not cached correctly."); Assert.AreEqual(authenticationResult.AccessToken, accountSession.AccessToken, "Unexpected access token set."); Assert.AreEqual(authenticationResult.AccessTokenType, accountSession.AccessTokenType, "Unexpected access token type set."); Assert.AreEqual(AccountType.ActiveDirectory, accountSession.AccountType, "Unexpected account type set."); Assert.IsTrue(accountSession.CanSignOut, "CanSignOut set to false."); Assert.AreEqual(this.serviceInfo.AppId, accountSession.ClientId, "Unexpected client ID set."); Assert.AreEqual(authenticationResult.ExpiresOn, accountSession.ExpiresOnUtc, "Unexpected expiration set."); Assert.IsNull(accountSession.UserId, "Unexpected user ID set."); }
/// <summary> /// Instantiates a new instance of <see cref="AdalRedeemRefreshTokenHelper"/>. /// </summary> /// <param name="serviceInfo">The information for authenticating against the service.</param> /// <param name="authenticationContextWrapper"></param> public AdalRedeemRefreshTokenHelper(ServiceInfo serviceInfo, IAuthenticationContextWrapper authenticationContextWrapper) { this.authenticationContextWrapper = authenticationContextWrapper; this.serviceInfo = serviceInfo; }
/// <summary> /// Instantiates a new instance of <see cref="AdalRedeemRefreshTokenHelper"/>. /// </summary> /// <param name="serviceInfo">The information for authenticating against the service.</param> /// <param name="authenticationContextWrapper"></param> public AdalRedeemRefreshTokenHelper(ServiceInfo serviceInfo, IAuthenticationContextWrapper authenticationContextWrapper) { this.authenticationContextWrapper = authenticationContextWrapper; this.serviceInfo = serviceInfo; }