dioxus-oauth

Crates.iodioxus-oauth
lib.rsdioxus-oauth
version
sourcesrc
created_at2024-11-12 00:02:02.430615
updated_at2024-12-11 02:57:16.773668
descriptionLibrary for using OAuth in dioxus
homepage
repositoryhttps://github.com/biyard/dioxus-oauth.git
max_upload_size
id1444344
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
hackartist (hackartists)

documentation

README

Dioxus OAuth2

Add dependancy

  • Must add features per server and web.
  • This library focuses on web implementation.
[dependencies]
dioxus-oauth = { version = "0.1.0", path = "../dioxus-oauth" }

[features]
server = ["dioxus-oauth/server"]
web = ["dioxus-oauth/web"]

Add a component to redirect URI

  • By using dioxus-router, add OAuthPopup to your redirect URI.
use dioxus_oauth::component::OAuthPopup;

#[derive(Clone, Routable, Debug, PartialEq)]
#[rustfmt::skip]
pub enum Route {
    #[route("/oauth/code")]
    OAuthPopup { },

}

Add handling an action

  • Setting up authorize, token URLs.
  • Add button click.
#[component]
pub fn OAuthLoginPage() -> Element {
    rsx! {
       div {
           onclick: move |_| {
              #[cfg(feature = "web")]
              {
                  spawn(async move {
                      let client = dioxus_oauth::prelude::OAuthClient::new(
                          env!("CLIENT_ID"),
                          env!("REDIRECT_URI"),
                          "https://kauth.kakao.com/oauth/authorize",
                          "https://kauth.kakao.com/oauth/token",
                      )
                      .set_openid_url("https://kauth.kakao.com/oauth/tokeninfo");

                      let code: String = match client.get_auth_code().await {
                          Ok(code) => code,
                          Err(e) => {
                              tracing::error!("Auth code failed: {:?}", e);
                              return;
                          }
                      };

                      let token_response: dioxus_oauth::prelude::TokenResponse =
                          match client.get_token(code.as_str()).await {
                              Ok(token_response) => token_response,
                              Err(e) => {
                                  tracing::error!("Token response failed: {:?}", e);
                                  return;
                              }
                          };
                      tracing::debug!("Token response: {:?}", token_response);

                      let oid_response: dioxus_oauth::prelude::OpenIdResponse =
                          match client.get_openid(&token_response.id_token).await {
                              Ok(oid_response) => oid_response,
                              Err(e) => {
                                  tracing::error!("Token response failed: {:?}", e);
                                  return;
                              }
                          };

                      tracing::debug!("OID response: {:?}", oid_response);
                  });
              }
           }
       }
    }
}
Commit count: 5

cargo fmt