{"id":13807304,"url":"https://github.com/ctron/yew-oauth2","last_synced_at":"2025-08-20T06:32:29.876Z","repository":{"id":43392033,"uuid":"479032456","full_name":"ctron/yew-oauth2","owner":"ctron","description":"General purpose OAuth2 component for Yew","archived":false,"fork":false,"pushed_at":"2024-04-19T07:04:08.000Z","size":194,"stargazers_count":42,"open_issues_count":2,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-19T05:41:59.039Z","etag":null,"topics":["authentication","oauth2","oidc","openid-connect","yew"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-07T14:59:19.000Z","updated_at":"2024-08-04T01:07:24.309Z","dependencies_parsed_at":"2023-02-14T16:01:53.663Z","dependency_job_id":"8b56b88b-b1b5-47ef-82dd-23c1f8e2115c","html_url":"https://github.com/ctron/yew-oauth2","commit_stats":{"total_commits":99,"total_committers":2,"mean_commits":49.5,"dds":"0.010101010101010055","last_synced_commit":"dfd790913660a66ce660c5b8c98c3a8c7f1bf7c7"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctron%2Fyew-oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctron%2Fyew-oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctron%2Fyew-oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctron%2Fyew-oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctron","download_url":"https://codeload.github.com/ctron/yew-oauth2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230400615,"owners_count":18219831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","oauth2","oidc","openid-connect","yew"],"created_at":"2024-08-04T01:01:23.884Z","updated_at":"2024-12-19T08:08:04.590Z","avatar_url":"https://github.com/ctron.png","language":"Rust","funding_links":[],"categories":["Crates"],"sub_categories":["Components"],"readme":"# OAuth2 (and OIDC) component for Yew\n\n[![crates.io](https://img.shields.io/crates/v/yew-oauth2.svg)](https://crates.io/crates/yew-oauth2)\n[![docs.rs](https://docs.rs/yew-oauth2/badge.svg)](https://docs.rs/yew-oauth2)\n[![CI](https://github.com/ctron/yew-oauth2/actions/workflows/ci.yaml/badge.svg)](https://github.com/ctron/yew-oauth2/actions/workflows/ci.yaml)\n\nAdd to your `Cargo.toml`:\n\n```toml\nyew-oauth2 = \"0.11\"\n```\n\nBy default, the `yew-nested-router` integration for [`yew-nested-router`](https://github.com/ctron/yew-nested-router) is\ndisabled. You can enable it using:\n\n```toml\nyew-oauth2 = { version = \"0.10\", features = [\"yew-nested-router\"] }\n```\n\n## OpenID Connect\n\nOpenID Connect requires an additional dependency and can be enabled using the feature `openid`.\n\n## Examples\n\nA quick example of how to use it (see below for more complete examples):\n\n```rust\nuse yew::prelude::*;\nuse yew_oauth2::prelude::*;\nuse yew_oauth2::oauth2::*; // use `openid::*` when using OpenID connect\n\n#[function_component(MyApplication)]\nfn my_app() -\u003e Html {\n    let config = Config::new(\n        \"my-client\",\n        \"https://my-sso/auth/realms/my-realm/protocol/openid-connect/auth\",\n        \"https://my-sso/auth/realms/my-realm/protocol/openid-connect/token\"\n    );\n\n    html!(\n    \u003cOAuth2 {config}\u003e\n      \u003cMyApplicationMain/\u003e\n    \u003c/OAuth2\u003e\n  )\n}\n\n#[function_component(MyApplicationMain)]\nfn my_app_main() -\u003e Html {\n    let agent = use_auth_agent().expect(\"Must be nested inside an OAuth2 component\");\n\n    let login = use_callback(agent.clone(), |_, agent| {\n        let _ = agent.start_login();\n    });\n    let logout = use_callback(agent, |_, agent| {\n        let _ = agent.logout();\n    });\n\n    html!(\n    \u003c\u003e\n      \u003cFailure\u003e\u003cFailureMessage/\u003e\u003c/Failure\u003e\n      \u003cAuthenticated\u003e\n        \u003cbutton onclick={logout}\u003e{ \"Logout\" }\u003c/button\u003e\n      \u003c/Authenticated\u003e\n      \u003cNotAuthenticated\u003e\n        \u003cbutton onclick={login}\u003e{ \"Login\" }\u003c/button\u003e\n      \u003c/NotAuthenticated\u003e\n    \u003c/\u003e\n  )\n}\n```\n\nThis repository also has some complete examples:\n\n\u003cdl\u003e\n\u003cdt\u003e\n\n[yew-oauth2-example](yew-oauth2-example/) \u003c/dt\u003e\n\u003cdd\u003e\nA complete example, hiding everything behind a \"login\" page, and revealing the content once the user logged in.\n\nUse with either OpenID Connect or OAuth2.\n\u003c/dd\u003e\n\n\u003cdt\u003e\n\n[yew-oauth2-redirect-example](yew-oauth2-redirect-example/) \u003c/dt\u003e\n\u003cdd\u003e\nA complete example, showing the full menu structure, but redirecting the user automatically to the login server\nwhen required.\n\nUse with either OpenID Connect or OAuth2.\n\u003c/dd\u003e\n\n\u003c/dl\u003e\n\n### Testing\n\nTesting the example projects locally can be done using a local Keycloak instance and `trunk`.\n\nStart the Keycloak instance using:\n\n```shell\npodman-compose -f develop/docker-compose.yaml up\n```\n\nThen start `trunk` with the local developer instance:\n\n```shell\ncd yew-oauth2-example # or yew-oauth2-redirect-example\ntrunk serve\n```\n\nAnd navigate your browser to [http://localhost:8080](http://localhost:8080).\n\n**NOTE:** It is important to use `http://localhost:8080` instead of e.g. `http://127.0.0.1:8080`, as Keycloak is\nconfigured by default to use `http://localhost:*` as a valid redirect URL when in dev-mode. Otherwise, you will get\nan \"invalid redirect\" error from Keycloak.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctron%2Fyew-oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctron%2Fyew-oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctron%2Fyew-oauth2/lists"}