pub struct IssuedToken { /* private fields */ }Expand description
A successfully redeemed grant.
Obtained only from IssuedToken::parse, so an IssuedToken that exists
is one that parsed. token_type is not carried because the only value that
can produce this type is Bearer — the check happened at the door.
Implementations§
Source§impl IssuedToken
impl IssuedToken
Sourcepub const fn access_token(&self) -> &AccessToken
pub const fn access_token(&self) -> &AccessToken
The token to present as a bearer credential.
Sourcepub const fn refresh_token(&self) -> Option<&RefreshToken>
pub const fn refresh_token(&self) -> Option<&RefreshToken>
The refresh token, if the server issued one.
Sourcepub fn scope(&self) -> Option<&str>
pub fn scope(&self) -> Option<&str>
The scope actually granted.
RFC 6749 §5.1 makes this OPTIONAL, and an absent value does not
mean “everything that was asked for” — §5.1 says the server treated it
as equal to the requested scope, and §3.3 lets it narrow that
silently. A client that reads None as “unlimited” would present a
token for a grant it never received.
Sourcepub const fn extra(&self) -> &Map<String, Value>
pub const fn extra(&self) -> &Map<String, Value>
Members of the response this build does not model.
Sourcepub fn parse(body: &[u8]) -> Result<Self, TokenResponseError>
pub fn parse(body: &[u8]) -> Result<Self, TokenResponseError>
Parse an RFC 6749 §5.1 success body, or an RFC 6749 §5.2 error body.
§Errors
TokenResponseError::AuthorizationServer when the body names an
error, carrying the server’s own error code rather than a guess.
TokenResponseError::Malformed when the body is not JSON, or omits
the two REQUIRED members. TokenResponseError::UnsupportedTokenType
when token_type is something other than Bearer under a
case-insensitive comparison.
§Examples
let body = br#"{"access_token":"at-1","token_type":"Bearer","expires_in":3600}"#;
let issued = IssuedToken::parse(body)?;
assert_eq!(issued.access_token().as_str(), "at-1");
assert!(issued.refresh_token().is_none());
let refused = br#"{"error":"invalid_grant","error_description":"expired"}"#;
assert!(matches!(
IssuedToken::parse(refused),
Err(TokenResponseError::AuthorizationServer { error, .. })
if error == "invalid_grant"
));