[][src]Struct rocket_oauth2::OAuth2

pub struct OAuth2<K>(_);

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, config)))
        }))
        .launch();
}

pub fn get_redirect(
    &self,
    cookies: &mut Cookies,
    scopes: &[&str]
) -> Result<Redirect, Error>
[src]

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 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]

type Error = ()

The associated error to be returned if derivation fails.

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]

impl<T, I> AsResult<T, I> for T where
    I: Input, 

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoCollection<T> for T

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Typeable for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,