{"id":17114327,"url":"https://github.com/anthonychu/blazor-auth-static-web-apps","last_synced_at":"2025-04-13T03:43:45.621Z","repository":{"id":68672459,"uuid":"282543373","full_name":"anthonychu/blazor-auth-static-web-apps","owner":"anthonychu","description":"A Blazor WebAssembly AuthenticationStateProvider for Azure Static Web Apps","archived":false,"fork":false,"pushed_at":"2021-06-23T06:25:32.000Z","size":252,"stargazers_count":36,"open_issues_count":5,"forks_count":14,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-26T20:55:41.093Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","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/anthonychu.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":"2020-07-25T23:45:25.000Z","updated_at":"2023-10-19T15:54:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"b46af269-987c-4d41-9a92-fe125668e00c","html_url":"https://github.com/anthonychu/blazor-auth-static-web-apps","commit_stats":{"total_commits":24,"total_committers":3,"mean_commits":8.0,"dds":0.08333333333333337,"last_synced_commit":"59d0932c3856eaa417c7d0135bc7d68f91181c77"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonychu%2Fblazor-auth-static-web-apps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonychu%2Fblazor-auth-static-web-apps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonychu%2Fblazor-auth-static-web-apps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonychu%2Fblazor-auth-static-web-apps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthonychu","download_url":"https://codeload.github.com/anthonychu/blazor-auth-static-web-apps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661397,"owners_count":21141445,"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":[],"created_at":"2024-10-14T17:16:35.903Z","updated_at":"2025-04-13T03:43:45.596Z","avatar_url":"https://github.com/anthonychu.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blazor Authentication Extension for Azure Static Web Apps\n\nUse Azure Static Web Apps authentication in Blazor WebAssembly apps.\n\n## Usage\n\n### Install NuGet package\n\n```bash\ndotnet add package AnthonyChu.AzureStaticWebApps.Blazor.Authentication --version 0.0.2-preview\n```\n\n### Update Program.cs\n\nAdd `using AzureStaticWebApps.Blazor.Authentication` and register services with `AddStaticWebAppsAuthentication()`.\n\n```csharp\nusing System;\nusing System.Net.Http;\nusing System.Threading.Tasks;\nusing Microsoft.AspNetCore.Components.WebAssembly.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing AzureStaticWebApps.Blazor.Authentication;\n\nnamespace BlazorLogin\n{\n    public class Program\n    {\n        public static async Task Main(string[] args)\n        {\n            var builder = WebAssemblyHostBuilder.CreateDefault(args);\n            builder.RootComponents.Add\u003cApp\u003e(\"app\");\n\n            builder.Services\n                .AddTransient(sp =\u003e new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) })\n                .AddStaticWebAppsAuthentication();\n            await builder.Build().RunAsync();\n        }\n    }\n}\n```\n\n### Update App.razor\n\nAdd `\u003cCascadingAuthenticationState\u003e` and `\u003cAuthorizeRouteView\u003e` to App.razor. For more information, check out the [Blazor security docs](https://docs.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-3.1#customize-unauthorized-content-with-the-router-component).\n\n```html\n\u003cCascadingAuthenticationState\u003e\n    \u003cRouter AppAssembly=\"@typeof(Program).Assembly\"\u003e\n        \u003cFound Context=\"routeData\"\u003e\n            \u003cAuthorizeRouteView RouteData=\"@routeData\" DefaultLayout=\"@typeof(MainLayout)\" /\u003e\n        \u003c/Found\u003e\n        \u003cNotFound\u003e\n                \u003cLayoutView Layout=\"@typeof(MainLayout)\"\u003e\n                    \u003cp\u003eSorry, there's nothing at this address.\u003c/p\u003e\n                \u003c/LayoutView\u003e\n        \u003c/NotFound\u003e\n    \u003c/Router\u003e\n\u003c/CascadingAuthenticationState\u003e\n```\n\n### Log user into Azure Static Web Apps using social\n\nRedirect the user to `/.auth/login/\u003csocial-provider\u003e` to log them in. More info at the [Static Web Apps authentication docs](https://docs.microsoft.com/en-us/azure/static-web-apps/authentication-authorization).\n\n### Access user identity\n\nUse `context.User` to get information about the user.\n\n```html\n\u003cAuthorizeView\u003e\n    \u003cAuthorized\u003e\n        Hello, @context.User.Identity.Name!\n        \u003ca href=\"/.auth/logout?post_logout_redirect_uri=/\"\u003eLog out\u003c/a\u003e\n    \u003c/Authorized\u003e\n    \u003cNotAuthorized\u003e\n        \u003ca href=\"/login-providers\"\u003eLog in\u003c/a\u003e\n    \u003c/NotAuthorized\u003e\n\u003c/AuthorizeView\u003e\n```\n\n## Configuration\n\nBy default, the auth provider will call `/.auth/me` to determine if a user is logged in and get information about the logged in user. Configure `StaticWebAppsAuthentication:AuthenticationDataUrl` in appsettings.json (or an envionrment specific version) to use a different endpoint.\n\nFor instance, in local development you can use a static file:\n\n```json\n{\n  \"StaticWebAppsAuthentication\": {\n    \"AuthenticationDataUrl\": \"/sample-data/me.json\"\n  }\n}\n```\n\nSee [sample-data/me.json](sample/app/wwwroot/sample-data/me.json) for an example of the structure. For more information, check out the [Static Web Apps docs](https://docs.microsoft.com/en-us/azure/static-web-apps/user-information).\n\n## Sample app\n\nCheck out the sample app at [sample/app](sample/app).\n\n---\n\nThis is not an officially supported Microsoft project.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonychu%2Fblazor-auth-static-web-apps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthonychu%2Fblazor-auth-static-web-apps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonychu%2Fblazor-auth-static-web-apps/lists"}