/// <summary> /// Obtains a token from the Azure Active Directory service, using the specified client secret to authenticate. This method is called by Azure SDK clients. It isn't intended for use in application code. /// </summary> /// <param name="requestContext">The details of the authentication request.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>An <see cref="AccessToken"/> which can be used to authenticate service client calls.</returns> public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken = default) { using CredentialDiagnosticScope scope = _pipeline.StartGetTokenScope("ClientSecretCredential.GetToken", requestContext); try { return(scope.Succeeded(_client.Authenticate(TenantId, ClientId, ClientSecret, requestContext.Scopes, cancellationToken))); } catch (Exception e) { throw scope.FailWrapAndThrow(e); } }
/// <summary> /// Obtains a token from the Azure Active Directory service, using the specified X509 certificate to authenticate. /// </summary> /// <param name="requestContext">The details of the authentication request.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>An <see cref="AccessToken"/> which can be used to authenticate service client calls.</returns> public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken = default) { using CredentialDiagnosticScope scope = _pipeline.StartGetTokenScope("Azure.Identity.ClientCertificateCredential.GetToken", requestContext); try { return(scope.Succeeded(_client.Authenticate(TenantId, ClientId, ClientCertificate, requestContext.Scopes, cancellationToken))); } catch (OperationCanceledException e) { scope.Failed(e); throw; } catch (Exception e) { throw scope.Failed(e); } }
/// <summary> /// Obtains a token from the Azure Active Directory service, using the specified X509 certificate to authenticate. /// </summary> /// <param name="scopes">The list of scopes for which the token will have access.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>An <see cref="AccessToken"/> which can be used to authenticate service client calls.</returns> public override AccessToken GetToken(string[] scopes, CancellationToken cancellationToken = default) { return(_client.Authenticate(TenantId, ClientId, ClientCertificate, scopes, cancellationToken)); }
/// <summary> /// Obtains a token from the Azure Active Directory service, using the specified X509 certificate to authenticate. /// </summary> /// <param name="requestContext">The details of the authentication request.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>An <see cref="AccessToken"/> which can be used to authenticate service client calls.</returns> public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken = default) { return(_client.Authenticate(TenantId, ClientId, ClientCertificate, requestContext.Scopes, cancellationToken)); }