Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sravimohan/blazor-webassembly-cognito-hosted-ui-sample
Sample Blazor Web assembly project Using Cognito Hosted UI Authentication
https://github.com/sravimohan/blazor-webassembly-cognito-hosted-ui-sample
asp-net asp-net-core aws aws-cognito blazor-webassembly dotnet
Last synced: 26 days ago
JSON representation
Sample Blazor Web assembly project Using Cognito Hosted UI Authentication
- Host: GitHub
- URL: https://github.com/sravimohan/blazor-webassembly-cognito-hosted-ui-sample
- Owner: sravimohan
- License: mit
- Created: 2022-05-15T21:12:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-15T22:11:45.000Z (over 2 years ago)
- Last Synced: 2023-10-05T13:27:43.316Z (over 1 year ago)
- Topics: asp-net, asp-net-core, aws, aws-cognito, blazor-webassembly, dotnet
- Language: HTML
- Homepage:
- Size: 190 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sample Blazor Webassembly project Using Cognito Hosted UI Authentication
- Create dotnet WASM project
```dotnet new blazorwasm -au Individual -o BlazorWasmCognitoSample```
This should create a Blazor WASM project with Indivdual type authentication
- [Optional] Create AWS Cognito User Pool.
[Sample Cloudformation - cognito-stack.yml](./.cloudformation/cognito-stack.yml)
[Deploy Script - deploy-cognito-stack.sh](./.cloudformation/deploy-cognito-stack.sh)
If you are using an existing user pool, make sure the CallbackURLs and LogoutURLs match exactly. A common cause of grief is the missing or additional trailing slashes.
Also you will need to configure the Hosted UI.
- Update appsettings.json or appsettings.development.json under wwwroot. Make sure to replace , , with your values.
```
{
"Cognito": {
"Authority": "https://cognito-idp..amazonaws.com/",
"ClientId": "",
"RedirectUri": "https://localhost:5001/authentication/login-callback",
"PostLogoutRedirectUri": "https://localhost:5001/authentication/logout-callback",
"ResponseType": "code"
}
}
```
- Update Program.cs, to refer to the correct config
```
builder.Services.AddOidcAuthentication(options =>
{
builder.Configuration.Bind("Cognito", options.ProviderOptions);
});
```
- Add Authorize Attribute to pages which needs to be protected
```
@using Microsoft.AspNetCore.Authorization@page "/fetchdata"
@attribute [Authorize]
@inject HttpClient HttpWeather forecast
...
```- Run
```dotnet run```Please refer to https://docs.microsoft.com/en-au/aspnet/core/blazor/security/webassembly/?view=aspnetcore-6.0 for official documentation.