{"id":13806276,"url":"https://github.com/wildermedeiros/BlazorAppWasmAuth","last_synced_at":"2025-05-13T21:32:50.763Z","repository":{"id":238007861,"uuid":"795197250","full_name":"wildermedeiros/BlazorAppWasmAuth","owner":"wildermedeiros","description":"Blazor WebAssembly Standalone App with OIDC Authentication","archived":false,"fork":false,"pushed_at":"2024-05-03T20:16:16.000Z","size":133,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-19T21:16:37.758Z","etag":null,"topics":["blazor-webassembly","keycloak-provider","oidc-authentication"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wildermedeiros.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2024-05-02T19:18:13.000Z","updated_at":"2024-05-03T20:16:20.000Z","dependencies_parsed_at":"2024-05-03T21:13:11.642Z","dependency_job_id":null,"html_url":"https://github.com/wildermedeiros/BlazorAppWasmAuth","commit_stats":null,"previous_names":["wildermedeiros/blazorappwasmauth"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildermedeiros%2FBlazorAppWasmAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildermedeiros%2FBlazorAppWasmAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildermedeiros%2FBlazorAppWasmAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wildermedeiros%2FBlazorAppWasmAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wildermedeiros","download_url":"https://codeload.github.com/wildermedeiros/BlazorAppWasmAuth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213870459,"owners_count":15650178,"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":["blazor-webassembly","keycloak-provider","oidc-authentication"],"created_at":"2024-08-04T01:01:09.683Z","updated_at":"2024-08-04T01:05:58.121Z","avatar_url":"https://github.com/wildermedeiros.png","language":"HTML","funding_links":[],"categories":["Sample Projects"],"sub_categories":["Authentication"],"readme":"## Blazor WebAssembly Standalone App with OIDC Authentication\n\nThis steps provides instructions for setting up a standalone Blazor WebAssembly application using OpenID Connect (OIDC) authentication with Microsoft Identity.\n\n### Prerequisites\n\n- Visual Studio or VSCode;\n- Docker;\n- Keycloak configuration.\n\n### Setup\n\n**1. Create/Update Project:**\n- To create a new Blazor WebAssembly project, use the appropriate template available in Visual Studio or via the CLI.\n- To add OIDC authentication to an existing project, include the dependency `Microsoft.AspNetCore.Components.WebAssembly.Authentication`.\n\n\u003e **Note: It is more convenient to create a new project based on Microsoft Identity.**\n  \n**2. Setup authentication in the `Program.cs`:**\n\nAdd the following code block to your `Program.cs` file to set up OIDC authentication:\n\n```cs\nbuilder.Services.AddOidcAuthentication(options =\u003e\n{\n    builder.Configuration.Bind(\"Keycloak\", options.ProviderOptions);\n    options.ProviderOptions.ResponseType = OpenIdConnectResponseType.Code;\n}).AddAccountClaimsPrincipalFactory\u003cCustomAccountFactory\u003e();\n```\n\n\u003e **Note: `CustomAccountFactory` is a class that inherits from `AccountClaimsPrincipalFactory` and is responsible for creating the user from the authentication process.**\n\n**3. Configure the identity provider in `appsettings.json`:**\n\nIn the **wwwroot** directory of your application, update the `appsettings.json` file with the settings of your OIDC authentication server as shown below:\n\n```json\n  \"Keycloak\": {\n    \"Authority\": \"http://localhost:8080/realms/wilder\",\n    \"ClientId\": \"wasm\"\n  }\n```\n\n### References\n\n[Secure an ASP.NET Core Blazor WebAssembly standalone app with the Authentication library](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-authentication-library?view=aspnetcore-8.0\u0026tabs=visual-studio)\n\n[ASP.NET Core Blazor WebAssembly additional security scenarios](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/additional-scenarios?view=aspnetcore-8.0)\n\n[Microsoft Entra (ME-ID) groups, Administrator Roles, and App Roles](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/microsoft-entra-id-groups-and-roles?view=aspnetcore-8.0\u0026pivots=graph-sdk-4)\n\n[Use Keycloak as Identity Provider from Blazor WebAssembly (WASM) applications](https://nikiforovall.github.io/blazor/dotnet/2022/12/08/dotnet-keycloak-blazorwasm-auth.html)\n\n[Creating a client application](https://www.keycloak.org/docs/latest/authorization_services/index.html#_resource_server_create_client)\n\n[Using OpenID Connect to secure applications and services](https://www.keycloak.org/docs/latest/securing_apps/index.html#_oidc)\n\n### Examples\n\n![chrome_xCYA9ETJqm](https://github.com/wildermedeiros/BlazorAppWasmAuth/assets/66234299/36503a05-1de3-42aa-855b-22d204323baa)\n![firefox_C5qK6nQgAO](https://github.com/wildermedeiros/BlazorAppWasmAuth/assets/66234299/2e9efb25-84ad-4c49-bcb3-274d2690d3a7)\n![chrome_xEcCJZmU1i](https://github.com/wildermedeiros/BlazorAppWasmAuth/assets/66234299/49ad2866-f313-4151-bd8f-79edfc275f26)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildermedeiros%2FBlazorAppWasmAuth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwildermedeiros%2FBlazorAppWasmAuth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildermedeiros%2FBlazorAppWasmAuth/lists"}