public static string ConvertGrantTypeToString(OAuth2GrantType value)
        {
            switch (value)
            {
            case OAuth2GrantType.AuthorizationCode:
                return(GRANT_TYPE_STRING_AUTHORIZATION_CODE);

            case OAuth2GrantType.ClientCredentials:
                return(GRANT_TYPE_CLIENT_CREDENTIALS);

            case OAuth2GrantType.Implicit:
                return(GRANT_TYPE_STRING_IMPLICIT);

            case OAuth2GrantType.Password:
                return(GRANT_TYPE_STRING_RESOURCE_OWNER_PASSWORD_CREDENTIALS);

            case OAuth2GrantType.RefreshToken:
                return(GRANT_TYPE_REFRESH_TOKEN);

            default:
                return(null);
            }
        }
Beispiel #2
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Gets refresh token.
        /// </summary>
        ///
        /// <param name="endPoint">
        ///     The end point.
        /// </param>
        /// <param name="refreshToken">
        ///     The refresh token.
        /// </param>
        /// <param name="grantType">
        ///     (optional) type of the grant.
        /// </param>
        ///
        /// <returns>
        ///     The refresh token.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        protected RestResponse <OAuth2TokenCredential> GetRefreshToken(string endPoint, string refreshToken, OAuth2GrantType grantType = OAuth2GrantType.RefreshToken)
        {
            RestRequest request = new RestRequest(endPoint, RequestMode.UrlEncoded, AcceptMode.Json);

            switch (this.TokenAccessType)
            {
            case OAuth2TokenAccessType.Querystring:
                request.Parameters.Add(RestConstants.OAuth2ClientID, this.AppID);
                request.Parameters.Add(RestConstants.OAuth2ClientSecret, this.AppSecret);
                request.Parameters.Add(RestConstants.OAuth2RefreshToken, refreshToken);
                request.Parameters.Add(RestConstants.OAuth2GrantType, grantType.ToDescription());
                break;

            default:
                request.AddBody(RestConstants.OAuth2ClientID, this.AppID);
                request.AddBody(RestConstants.OAuth2ClientSecret, this.AppSecret);
                request.AddBody(RestConstants.OAuth2RefreshToken, refreshToken);
                request.AddBody(RestConstants.OAuth2GrantType, grantType.ToDescription());
                break;
            }

            return(this.Post <OAuth2TokenCredential>(request));
        }
Beispiel #3
0
 /// <inheritdoc/>
 public virtual IOAuth2AuthenticationBuilder UseGranType(OAuth2GrantType grantType)
 {
     this.Properties.GrantType = grantType;
     return(this);
 }