Exemple #1
0
        private async Task <Option <GrantedToken> > GetGrantedToken(
            TokenRequest tokenRequest,
            AuthenticationHeaderValue?authenticationHeaderValue,
            X509Certificate2?certificate,
            string issuerName,
            CancellationToken cancellationToken)
        {
            switch (tokenRequest.grant_type)
            {
            case GrantTypes.Device:
                return(await _tokenActions.GetTokenByDeviceGrantType(
                           tokenRequest.client_id,
                           tokenRequest.device_code,
                           issuerName,
                           cancellationToken).ConfigureAwait(false));

            case GrantTypes.Password:
                var resourceOwnerParameter = tokenRequest.ToResourceOwnerGrantTypeParameter();
                return(await _tokenActions.GetTokenByResourceOwnerCredentialsGrantType(
                           resourceOwnerParameter,
                           authenticationHeaderValue,
                           certificate,
                           issuerName,
                           cancellationToken)
                       .ConfigureAwait(false));

            case GrantTypes.AuthorizationCode:
                var authCodeParameter = tokenRequest.ToAuthorizationCodeGrantTypeParameter();
                return(await _tokenActions.GetTokenByAuthorizationCodeGrantType(
                           authCodeParameter,
                           authenticationHeaderValue,
                           certificate,
                           issuerName,
                           cancellationToken)
                       .ConfigureAwait(false));

            case GrantTypes.RefreshToken:
                var refreshTokenParameter = tokenRequest.ToRefreshTokenGrantTypeParameter();
                return(await _tokenActions.GetTokenByRefreshTokenGrantType(
                           refreshTokenParameter,
                           authenticationHeaderValue,
                           certificate,
                           issuerName,
                           cancellationToken)
                       .ConfigureAwait(false));

            case GrantTypes.ClientCredentials:
                var clientCredentialsParameter = tokenRequest.ToClientCredentialsGrantTypeParameter();
                return(await _tokenActions.GetTokenByClientCredentialsGrantType(
                           clientCredentialsParameter,
                           authenticationHeaderValue,
                           certificate,
                           issuerName,
                           cancellationToken)
                       .ConfigureAwait(false));

            case GrantTypes.UmaTicket:
                var tokenIdParameter = tokenRequest.ToTokenIdGrantTypeParameter();

                return(await _umaTokenActions.GetTokenByTicketId(
                           tokenIdParameter,
                           authenticationHeaderValue,
                           certificate,
                           issuerName,
                           cancellationToken)
                       .ConfigureAwait(false));

            case GrantTypes.ValidateBearer:
            //return null;
            default:
                throw new ArgumentOutOfRangeException(nameof(tokenRequest));
            }
        }