Exemple #1
0
        /// <summary>
        /// Apply this authenticator to the given authentication parameters.
        /// </summary>
        /// <param name="parameters">The complex object containing authentication specific information.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>
        /// An instance of <see cref="AuthenticationResult" /> that represents the access token generated as result of a successful authenication.
        /// </returns>
        public override async Task <AuthenticationResult> AuthenticateAsync(AuthenticationParameters parameters, CancellationToken cancellationToken = default)
        {
            IClientApplicationBase app = GetClient(parameters.Account, parameters.Environment);

            ServiceClientTracing.Information("[RefreshTokenAuthenticator] Calling GetAccountsAysnc");
            IAccount account = await app.GetAccountAsync(parameters.Account.Identifier).ConfigureAwait(false);

            if (account != null)
            {
                ServiceClientTracing.Information($"[RefreshTokenAuthenticator] Calling AcquireTokenSilent - Scopes: '{string.Join(", ", parameters.Scopes)}'");
                return(await app.AcquireTokenSilent(parameters.Scopes, account).ExecuteAsync(cancellationToken).ConfigureAwait(false));
            }

            ServiceClientTracing.Information($"[RefreshTokenAuthenticator] Calling AcquireTokenByRefreshToken - Scopes: '{string.Join(", ", parameters.Scopes)}'");
            return(await app.AsRefreshTokenClient().AcquireTokenByRefreshToken(
                       parameters.Scopes,
                       parameters.Account.GetProperty(MgmtAccountPropertyType.RefreshToken)).ExecuteAsync(cancellationToken).ConfigureAwait(false));
        }
Exemple #2
0
        /// <summary>
        /// Apply this authenticator to the given authentication parameters.
        /// </summary>
        /// <param name="parameters">The complex object containing authentication specific information.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>
        /// An instance of <see cref="AuthenticationResult" /> that represents the access token generated as result of a successful authenication.
        /// </returns>
        public override async Task <AuthenticationResult> AuthenticateAsync(AuthenticationParameters parameters, CancellationToken cancellationToken = default)
        {
            IClientApplicationBase app = GetClient(parameters.Account, parameters.Environment);

            IEnumerable <IAccount> data = await app.GetAccountsAsync().ConfigureAwait(false);

            ServiceClientTracing.Information($"[SilentAuthenticator] data count is {data.Count()}");

            ServiceClientTracing.Information("[SilentAuthenticator] Calling GetAccountsAsync");
            IEnumerable <IAccount> accounts = await app.AsPublicClient().GetAccountsAsync().ConfigureAwait(false);

            ServiceClientTracing.Information($"[SilentAuthenticator] Calling AcquireTokenSilent - Scopes: '{string.Join(",", parameters.Scopes)}', UserId: '{((SilentParameters)parameters).UserId}', Number of accounts: '{accounts.Count()}'");
            AuthenticationResult authResult = await app.AsPublicClient().AcquireTokenSilent(
                parameters.Scopes,
                accounts.FirstOrDefault(a => a.HomeAccountId.ObjectId.Equals(((SilentParameters)parameters).UserId, StringComparison.InvariantCultureIgnoreCase)))
                                              .ExecuteAsync(cancellationToken).ConfigureAwait(false);

            return(authResult);
        }
Exemple #3
0
 /// <summary>
 /// Determine if this authenticator can apply to the given authentication parameters.
 /// </summary>
 /// <param name="parameters">The complex object containing authentication specific information.</param>
 /// <returns><c>true</c> if this authenticator can apply; otherwise <c>false</c>.</returns>
 public override bool CanAuthenticate(AuthenticationParameters parameters)
 {
     return(parameters is AccessTokenParameters);
 }
Exemple #4
0
 /// <summary>
 /// Determine if this authenticator can apply to the given authentication parameters.
 /// </summary>
 /// <param name="parameters">The complex object containing authentication specific information.</param>
 /// <returns><c>true</c> if this authenticator can apply; otherwise <c>false</c>.</returns>
 public override bool CanAuthenticate(AuthenticationParameters parameters)
 {
     return(parameters is ServicePrincipalParameters);
 }
Exemple #5
0
        /// <summary>
        /// Apply this authenticator to the given authentication parameters.
        /// </summary>
        /// <param name="parameters">The complex object containing authentication specific information.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>
        /// An instance of <see cref="AuthenticationResult" /> that represents the access token generated as result of a successful authenication.
        /// </returns>
        public override async Task <AuthenticationResult> AuthenticateAsync(AuthenticationParameters parameters, CancellationToken cancellationToken = default)
        {
            IClientApplicationBase app = GetClient(parameters.Account, parameters.Environment);

            return(await app.AsConfidentialClient().AcquireTokenForClient(parameters.Scopes).ExecuteAsync(cancellationToken).ConfigureAwait(false));
        }
 /// <summary>
 /// Determine if this authenticator can apply to the given authentication parameters.
 /// </summary>
 /// <param name="parameters">The complex object containing authentication specific information.</param>
 /// <returns><c>true</c> if this authenticator can apply; otherwise <c>false</c>.</returns>
 public override bool CanAuthenticate(AuthenticationParameters parameters)
 {
     return(parameters is DeviceCodeParameters);
 }
 /// <summary>
 /// Determine if this authenticator can apply to the given authentication parameters.
 /// </summary>
 /// <param name="parameters">The complex object containing authentication specific information.</param>
 /// <returns><c>true</c> if this authenticator can apply; otherwise <c>false</c>.</returns>
 public abstract bool CanAuthenticate(AuthenticationParameters parameters);
 /// <summary>
 /// Apply this authenticator to the given authentication parameters.
 /// </summary>
 /// <param name="parameters">The complex object containing authentication specific information.</param>
 /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
 /// <returns>
 /// An instance of <see cref="AuthenticationResult" /> that represents the access token generated as result of a successful authenication.
 /// </returns>
 public abstract Task <AuthenticationResult> AuthenticateAsync(AuthenticationParameters parameters, CancellationToken cancellationToken = default);
Exemple #9
0
 /// <summary>
 /// Determine if this authenticator can apply to the given authentication parameters.
 /// </summary>
 /// <param name="parameters">The complex object containing authentication specific information.</param>
 /// <returns><c>true</c> if this authenticator can apply; otherwise <c>false</c>.</returns>
 public override bool CanAuthenticate(AuthenticationParameters parameters)
 {
     return(parameters is InteractiveParameters);
 }
Exemple #10
0
 /// <summary>
 /// Determine if this authenticator can apply to the given authentication parameters.
 /// </summary>
 /// <param name="parameters">The complex object containing authentication specific information.</param>
 /// <returns><c>true</c> if this authenticator can apply; otherwise <c>false</c>.</returns>
 public override bool CanAuthenticate(AuthenticationParameters parameters)
 {
     return(parameters is SilentParameters);
 }