Implement Client::refresh_token
This commit is contained in:
parent
4fbe31693f
commit
43bc9f4e48
|
@ -9,6 +9,7 @@ use url::{form_urlencoded, Url};
|
||||||
|
|
||||||
use error::OAuth2Error;
|
use error::OAuth2Error;
|
||||||
use provider::Provider;
|
use provider::Provider;
|
||||||
|
use token::{Token, Expiring};
|
||||||
|
|
||||||
use self::response::FromResponse;
|
use self::response::FromResponse;
|
||||||
pub mod response;
|
pub mod response;
|
||||||
|
@ -159,6 +160,29 @@ impl<P: Provider> Client<P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<P: Provider> Client<P> where P::Token: Token<Expiring> {
|
||||||
|
/// Refreshes an access token.
|
||||||
|
///
|
||||||
|
/// See [RFC 6749, section 6](http://tools.ietf.org/html/rfc6749#section-6).
|
||||||
|
pub fn refresh_token(
|
||||||
|
&self,
|
||||||
|
token: P::Token,
|
||||||
|
scope: Option<&str>
|
||||||
|
) -> Result<P::Token, ClientError> {
|
||||||
|
let mut body_pairs = vec![
|
||||||
|
("grant_type", "refresh_token"),
|
||||||
|
("refresh_token", token.lifetime().refresh_token()),
|
||||||
|
];
|
||||||
|
if let Some(scope) = scope {
|
||||||
|
body_pairs.push(("scope", scope));
|
||||||
|
}
|
||||||
|
|
||||||
|
let json = try!(self.post_token(body_pairs));
|
||||||
|
let token = try!(P::Token::from_response_inherit(&json, &token));
|
||||||
|
Ok(token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use token::{Bearer, Static};
|
use token::{Bearer, Static};
|
||||||
|
|
Loading…
Reference in New Issue