Exemple #1
0
        protected virtual OAuthMessage CreateTypedOAuthMessageFromParameters(Uri baseUri, NameValueCollection parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            OAuthMessage request = null;

            if (parameters["response_type"] == "code" || parameters["response_type"] == "token")
            {
                request = new EndUserAuthorizationRequest(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["code"]) || (!string.IsNullOrEmpty(parameters["access_token"]) && string.IsNullOrEmpty(parameters["refresh_token"])))
            {
                request = new EndUserAuthorizationResponse(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["error"]))
            {
                request = new EndUserAuthorizationFailedResponse(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["grant_type"]) && parameters["grant_type"] == "authorization_code")
            {
                request = new AccessTokenRequestWithAuthorizationCode(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["grant_type"]) && parameters["grant_type"] == OAuthConstants.AccessGrantType.ClientCredentials)
            {
                request = new AccessTokenRequest(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["access_token"]))
            {
                request = new AccessTokenResponse(baseUri);
            }
            if (request == null)
            {
                throw new OAuthMessageSerializationException(Resources.ID3723);
            }

            request.Parameters.Add(parameters);
            request.Validate();
            return(request);
        }
        protected virtual OAuthMessage CreateTypedOAuthMessageFromParameters(Uri baseUri, NameValueCollection parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            OAuthMessage request = null;
            if (parameters["response_type"] == "code" || parameters["response_type"] == "token")
            {
                request = new EndUserAuthorizationRequest(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["code"]) || (!string.IsNullOrEmpty(parameters["access_token"]) && string.IsNullOrEmpty(parameters["refresh_token"])))
            {
                request = new EndUserAuthorizationResponse(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["error"]))
            {
                request = new EndUserAuthorizationFailedResponse(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["grant_type"]) && parameters["grant_type"] == "authorization_code")
            {
                request = new AccessTokenRequestWithAuthorizationCode(baseUri);
            }
            if (!string.IsNullOrEmpty(parameters["access_token"]))
            {
                request = new AccessTokenResponse(baseUri);
            }
            if (request == null)
            {
                throw new OAuthMessageSerializationException(Resources.ID3723);
            }

            request.Parameters.Add(parameters);
            request.Validate();
            return request;
        }