Implement From<&str> for OAuth2ErrorCode

This commit is contained in:
Curtis McEnroe 2015-12-22 00:59:58 -05:00
parent 225f156bb6
commit 565ee93113
1 changed files with 14 additions and 0 deletions

View File

@ -36,6 +36,20 @@ pub enum OAuth2ErrorCode {
Unrecognized(String),
}
impl<'a> From<&'a str> for OAuth2ErrorCode {
fn from(s: &str) -> OAuth2ErrorCode {
match s {
"invalid_request" => OAuth2ErrorCode::InvalidRequest,
"invalid_client" => OAuth2ErrorCode::InvalidClient,
"invalid_grant" => OAuth2ErrorCode::InvalidGrant,
"unauthorized_client" => OAuth2ErrorCode::UnauthorizedClient,
"unsupported_grant_type" => OAuth2ErrorCode::UnsupportedGrantType,
"invalid_scope" => OAuth2ErrorCode::InvalidScope,
s => OAuth2ErrorCode::Unrecognized(s.to_string()),
}
}
}
/// OAuth 2.0 error.
///
/// See [RFC 6749, section 5.2](http://tools.ietf.org/html/rfc6749#section-5.2).