Exemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <AccessTokenResponse> GetTokenAsync(AuthorizationCodePkceTokenRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var body = new Dictionary <string, string> {
                { "grant_type", "authorization_code" },
                { "client_id", request.ClientId },
                { "code", request.Code },
                { "code_verifier", request.CodeVerifier },
                { "redirect_uri", request.RedirectUri }
            };

            var response = await connection.SendAsync <AccessTokenResponse>(
                HttpMethod.Post,
                tokenUri,
                body
                ).ConfigureAwait(false);

            await AssertIdTokenValid(response.IdToken, request.ClientId, request.SigningAlgorithm, request.ClientSecret, request.Organization).ConfigureAwait(false);

            return(response);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Request an Access Token using the Authorization Code (PKCE) flow.
 /// </summary>
 /// <param name="request">The <see cref="AuthorizationCodePkceTokenRequest"/> containing the information of the request.</param>
 /// <returns>An <see cref="AccessTokenResponse"/> containing the token information</returns>
 public Task <AccessTokenResponse> GetTokenAsync(AuthorizationCodePkceTokenRequest request)
 {
     return(Connection.PostAsync <AccessTokenResponse>("oauth/token", null, new Dictionary <string, object>
     {
         { "grant_type", "authorization_code" },
         { "client_id", request.ClientId },
         { "code", request.Code },
         { "code_verifier", request.CodeVerifier },
         { "redirect_uri", request.RedirectUri }
     },
                                                       null,
                                                       null,
                                                       null,
                                                       null));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Request an Access Token using the Authorization Code (PKCE) flow.
        /// </summary>
        /// <param name="request">The <see cref="AuthorizationCodePkceTokenRequest"/> containing the information of the request.</param>
        /// <returns>An <see cref="AccessTokenResponse"/> containing the token information</returns>
        public async Task <AccessTokenResponse> GetTokenAsync(AuthorizationCodePkceTokenRequest request)
        {
            var response = await Connection.PostAsync <AccessTokenResponse>("oauth/token", null, new Dictionary <string, object>
            {
                { "grant_type", "authorization_code" },
                { "client_id", request.ClientId },
                { "code", request.Code },
                { "code_verifier", request.CodeVerifier },
                { "redirect_uri", request.RedirectUri }
            },
                                                                            null,
                                                                            null,
                                                                            null,
                                                                            null).ConfigureAwait(false);

            await AssertIdTokenValid(response.IdToken, request.ClientId);

            return(response);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Request an Access Token using the Authorization Code (PKCE) flow.
        /// </summary>
        /// <param name="request">The <see cref="AuthorizationCodePkceTokenRequest"/> containing the information of the request.</param>
        /// <returns>An <see cref="AccessTokenResponse"/> containing the token information</returns>
        public async Task <AccessTokenResponse> GetTokenAsync(AuthorizationCodePkceTokenRequest request)
        {
            var response = await Connection.PostAsync <AccessTokenResponse>("oauth/token", null, new Dictionary <string, object>
            {
                { "grant_type", "authorization_code" },
                { "client_id", request.ClientId },
                { "code", request.Code },
                { "code_verifier", request.CodeVerifier },
                { "redirect_uri", request.RedirectUri }
            },
                                                                            null,
                                                                            null,
                                                                            null,
                                                                            null);

            IdentityTokenValidator validator = new IdentityTokenValidator();
            await validator.ValidateAsync(response.IdToken, _baseUri.AbsoluteUri, request.ClientId);

            return(response);
        }
 private string _getKey(AuthorizationCodePkceTokenRequest r)
 {
     return($"AuthorizationCodePkceTokenRequest{r.ClientId}{r.Code}{r.CodeVerifier}");
 }
 public Task <AccessTokenResponse> GetTokenAsync(AuthorizationCodePkceTokenRequest request)
 {
     return(_getToken(request));
 }
 public Task <AccessTokenResponse> GetTokenAsync(AuthorizationCodePkceTokenRequest request, CancellationToken cancellationToken = default)
 {
     return(_getToken(request, cancellationToken));
 }