[−][src]Struct rocket_oauth2::OAuth2
Utilities for OAuth authentication in Rocket applications.
Implementations
impl<K: 'static> OAuth2<K>
[src]
pub fn fairing(config_name: &str) -> impl Fairing
[src]
Create an OAuth2 fairing. The fairing will read the configuration in
config_name
and register itself in the application so that
TokenResponse<K>
can be used.
Example
use rocket::fairing::AdHoc; use rocket_oauth2::{HyperSyncRustlsAdapter, OAuth2, OAuthConfig}; struct GitHub; fn main() { rocket::ignite() .attach(OAuth2::<GitHub>::fairing("github")) .launch(); }
pub fn custom<A: Adapter>(adapter: A, config: OAuthConfig) -> impl Fairing
[src]
Create an OAuth2 fairing with a custom adapter and configuration.
Example
use rocket::fairing::AdHoc; use rocket_oauth2::{HyperSyncRustlsAdapter, OAuth2, OAuthConfig, StaticProvider}; struct MyProvider; fn main() { rocket::ignite() .attach(AdHoc::on_attach("OAuth Config", |rocket| { let config = OAuthConfig::new( StaticProvider { auth_uri: "auth uri".into(), token_uri: "token uri".into(), }, "client id".to_string(), "client secret".to_string(), Some("http://localhost:8000/auth".to_string()), ); Ok(rocket.attach(OAuth2::<MyProvider>::custom(HyperSyncRustlsAdapter::default(), config))) })) .launch(); }
pub fn get_redirect(
&self,
cookies: &mut Cookies<'_>,
scopes: &[&str]
) -> Result<Redirect, Error>
[src]
&self,
cookies: &mut Cookies<'_>,
scopes: &[&str]
) -> Result<Redirect, Error>
Prepare an authentication redirect. This sets a state cookie and returns
a Redirect
to the authorization endpoint.
Example
use rocket::http::Cookies; use rocket::response::Redirect; use rocket_oauth2::OAuth2; struct GitHub; #[rocket::get("/login/github")] fn github_login(oauth2: OAuth2<GitHub>, mut cookies: Cookies<'_>) -> Redirect { oauth2.get_redirect(&mut cookies, &["user:read"]).unwrap() }
pub fn get_redirect_extras(
&self,
cookies: &mut Cookies<'_>,
scopes: &[&str],
extras: &[(&str, &str)]
) -> Result<Redirect, Error>
[src]
&self,
cookies: &mut Cookies<'_>,
scopes: &[&str],
extras: &[(&str, &str)]
) -> Result<Redirect, Error>
Prepare an authentication redirect. This sets a state cookie and returns
a Redirect
to the authorization endpoint. Unlike get_redirect
,
this method accepts additional query parameters in extras
; this can be
used to provide or request additional information to or from providers.
Example
use rocket::http::Cookies; use rocket::response::Redirect; use rocket_oauth2::OAuth2; struct Reddit; #[rocket::get("/login/reddit")] fn reddit_login(oauth2: OAuth2<Reddit>, mut cookies: Cookies<'_>) -> Redirect { oauth2.get_redirect_extras(&mut cookies, &["identity"], &[("duration", "permanent")]).unwrap() }
pub fn refresh(&self, refresh_token: &str) -> Result<TokenResponse<K>, Error>
[src]
Request a new access token given a refresh token. The refresh token
must have been returned by the provider in a previous TokenResponse
.
Example
use rocket_oauth2::OAuth2; struct GitHub; #[rocket::get("/")] fn index(oauth2: OAuth2<GitHub>) { // get previously stored refresh_token oauth2.refresh(refresh_token).unwrap(); }
Trait Implementations
impl<C: Debug> Debug for OAuth2<C>
[src]
impl<'a, 'r, K: 'static> FromRequest<'a, 'r> for OAuth2<K>
[src]
Auto Trait Implementations
impl<K> !RefUnwindSafe for OAuth2<K>
impl<K> Send for OAuth2<K>
impl<K> Sync for OAuth2<K>
impl<K> Unpin for OAuth2<K>
impl<K> !UnwindSafe for OAuth2<K>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, I> AsResult<T, I> for T where
I: Input,
I: Input,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,