Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance populated with values from the form encoded body parameters.
        /// </summary>
        /// <param name="parameters">Form encoded body parameters from a request.</param>
        public TokenEndpointRequest(IReadableStringCollection parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            Func <string, string> getParameter = parameters.Get;

            Parameters = parameters;
            GrantType  = getParameter(Constants.Parameters.GrantType);
            ClientId   = getParameter(Constants.Parameters.ClientId);
            if (String.Equals(GrantType, Constants.GrantTypes.AuthorizationCode, StringComparison.Ordinal))
            {
                AuthorizationCodeGrant = new TokenEndpointRequestAuthorizationCode
                {
                    Code        = getParameter(Constants.Parameters.Code),
                    RedirectUri = getParameter(Constants.Parameters.RedirectUri),
                };
            }
            else if (String.Equals(GrantType, Constants.GrantTypes.ClientCredentials, StringComparison.Ordinal))
            {
                ClientCredentialsGrant = new TokenEndpointRequestClientCredentials
                {
                    Scope = (getParameter(Constants.Parameters.Scope) ?? string.Empty).Split(' ')
                };
            }
            else if (String.Equals(GrantType, Constants.GrantTypes.RefreshToken, StringComparison.Ordinal))
            {
                RefreshTokenGrant = new TokenEndpointRequestRefreshToken
                {
                    RefreshToken = getParameter(Constants.Parameters.RefreshToken),
                    Scope        = (getParameter(Constants.Parameters.Scope) ?? string.Empty).Split(' ')
                };
            }
            else if (String.Equals(GrantType, Constants.GrantTypes.Password, StringComparison.Ordinal))
            {
                ResourceOwnerPasswordCredentialsGrant = new TokenEndpointRequestResourceOwnerPasswordCredentials
                {
                    UserName = getParameter(Constants.Parameters.Username),
                    Password = getParameter(Constants.Parameters.Password),
                    Scope    = (getParameter(Constants.Parameters.Scope) ?? string.Empty).Split(' ')
                };
            }
            else if (!String.IsNullOrEmpty(GrantType))
            {
                CustomExtensionGrant = new TokenEndpointRequestCustomExtension
                {
                    Parameters = parameters,
                };
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance populated with values from the form encoded body parameters.
        /// </summary>
        /// <param name="parameters">Form encoded body parameters from a request.</param>
        public TokenEndpointRequest(IReadableStringCollection parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            Func<string, string> getParameter = parameters.Get;

            Parameters = parameters;
            GrantType = getParameter(Constants.Parameters.GrantType);
            ClientId = getParameter(Constants.Parameters.ClientId);
            if (String.Equals(GrantType, Constants.GrantTypes.AuthorizationCode, StringComparison.Ordinal))
            {
                AuthorizationCodeGrant = new TokenEndpointRequestAuthorizationCode
                {
                    Code = getParameter(Constants.Parameters.Code),
                    RedirectUri = getParameter(Constants.Parameters.RedirectUri),
                };
            }
            else if (String.Equals(GrantType, Constants.GrantTypes.ClientCredentials, StringComparison.Ordinal))
            {
                ClientCredentialsGrant = new TokenEndpointRequestClientCredentials
                {
                    Scope = (getParameter(Constants.Parameters.Scope) ?? string.Empty).Split(' ')
                };
            }
            else if (String.Equals(GrantType, Constants.GrantTypes.RefreshToken, StringComparison.Ordinal))
            {
                RefreshTokenGrant = new TokenEndpointRequestRefreshToken
                {
                    RefreshToken = getParameter(Constants.Parameters.RefreshToken),
                    Scope = (getParameter(Constants.Parameters.Scope) ?? string.Empty).Split(' ')
                };
            }
            else if (String.Equals(GrantType, Constants.GrantTypes.Password, StringComparison.Ordinal))
            {
                ResourceOwnerPasswordCredentialsGrant = new TokenEndpointRequestResourceOwnerPasswordCredentials
                {
                    UserName = getParameter(Constants.Parameters.Username),
                    Password = getParameter(Constants.Parameters.Password),
                    Scope = (getParameter(Constants.Parameters.Scope) ?? string.Empty).Split(' ')
                };
            }
            else if (!String.IsNullOrEmpty(GrantType))
            {
                CustomExtensionGrant = new TokenEndpointRequestCustomExtension
                {
                    Parameters = parameters,
                };
            }
        }