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); }
public virtual string GetHttpContentType(OAuthMessage message) { if (message == null) { throw new ArgumentNullException("message"); } AccessTokenRequest atRequestMessage = message as AccessTokenRequest; if (atRequestMessage != null) { return("application/x-www-form-urlencoded"); } AccessTokenResponse atResponseMessage = message as AccessTokenResponse; if (atResponseMessage != null) { return("application/json"); } return("text/plain; charset=us-ascii"); }
public virtual string GetHttpMethod(OAuthMessage message) { if (message == null) { throw new ArgumentNullException("message"); } AccessTokenRequest atRequestMessage = message as AccessTokenRequest; if (atRequestMessage != null) { return("POST"); } AccessTokenResponse atResponseMessage = message as AccessTokenResponse; if (atResponseMessage != null) { return("POST"); } return("GET"); }
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; }
private static bool IsValidGrantType(string grantType) { return(grantType == "authorization_code" || grantType == "password" || grantType == "client_credentials" || grantType == "refresh_token" || AccessTokenRequest.IsValidAbsoluteUri(grantType)); }