Skip to content

OpenID Connect helpers for Rocket

Notifications You must be signed in to change notification settings

iainh/rocket_oidc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rocket_oidc

OpenID Connect support for Rocket.

Example usage

use oauth2::{url::Url, ClientId, ClientSecret};
use openidconnect::IssuerUrl;
use rocket::{get, launch, response::Redirect, routes, Build, Rocket};
use rocket_oidc::{OidcApplication, OidcUser};

#[get("/")]
async fn authed_user(user: OidcUser) -> String {
    format!(
        "Hello, {}!",
        user.name().unwrap_or_else(|| "nameless user".to_string())
    )
}

#[get("/", rank = 2)]
async fn user() -> Redirect {
    Redirect::to("/oidc_goto_auth")
}

#[launch]
async fn rocket() -> Rocket<Build> {
    let issuer_url = IssuerUrl::new("https://oidc.endpoint.here/".to_string()).unwrap();
    let client_id = ClientId::new("client-id".to_string());
    let client_secret = ClientSecret::new("YOUR_CLIENT_SECRET".to_string());

    let oidc = OidcApplication::new(
        Url::parse("http://your.application.host/").unwrap(),
        issuer_url,
        client_id,
        client_secret,
    )
    .await
    .unwrap();

    rocket_oidc::attach(rocket::build(), oidc).mount("/", routes![authed_user, user])
}

About

OpenID Connect helpers for Rocket

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%