OAuth2 component for Yew

crates.io docs.rs CI

Add to your Cargo.toml:

toml yew-oauth2 = "0.6"

By default, the router integration is disabled, you can enable it using:

toml yew-oauth2 = { version = "0.6", features = ["router"] }

OpenID Connect

OpenID Connect requires an additional dependency and can be enabled using the feature openid.

Starting with version 0.6.0-alpha.1, it is possible to use openidconnect-rs version 3, which is the first version supporting WebAssembly targets without patching. However, for the moment, only an alpha version of openidconnect-rs 3 is released.

Examples

A quick example how to use it (see below for more complete examples):

``rust use yew::prelude::*; use yew_oauth2::prelude::*; use yew_oauth2::oauth2::*; // useopenid::*` when using OpenID connect

[function_component(MyApplication)]

fn myapp() -> Html { let config = Config { clientid: "my-client".into(), authurl: "https://my-sso/auth/realms/my-realm/protocol/openid-connect/auth".into(), tokenurl: "https://my-sso/auth/realms/my-realm/protocol/openid-connect/token".into(), };

html!( ) }

[function_component(MyApplicationMain)]

fn myappmain() -> Html { let agent = useauthagent().expect("Must be nested inside an OAuth2 component");

let login = { let agent = agent.clone(); Callback::from(move || { let _ = agent.startlogin(); }) }; let logout = Callback::from(move |_| { let _ = agent.logout(); });

html!( <>