Skip to content

Commit

Permalink
Merge pull request #3 from afedyanin/upgrade_to_Blazor_8
Browse files Browse the repository at this point in the history
Upgrade to blazor 8
  • Loading branch information
afedyanin committed May 24, 2024
2 parents 6e02fe7 + 2cfc162 commit 92187ca
Show file tree
Hide file tree
Showing 90 changed files with 1,262 additions and 1,944 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dotnet_diagnostic.IDE0090.severity = none
dotnet_diagnostic.IDE0022.severity = none
dotnet_diagnostic.IDE0061.severity = none
dotnet_diagnostic.IDE0025.severity = none
dotnet_diagnostic.IDE0210.severity = none
csharp_style_prefer_readonly_struct_member = true:suggestion

##########################################
Expand Down
6 changes: 2 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CS1591</NoWarn>
</PropertyGroup>
</Project>
2 changes: 0 additions & 2 deletions Directory.Build.targets

This file was deleted.

42 changes: 14 additions & 28 deletions Keycloak4Blazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,40 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{4B1B7D
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
keycloak-setup.md = keycloak-setup.md
keycloak.json = keycloak.json
LICENSE = LICENSE
README.md = README.md
TECH.md = TECH.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B42857C-FD8E-4EB6-B9D6-200FD3E19168}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{9C59A7AC-5C91-4BC5-97B7-72B20D752B2C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorSampleApp", "src\BlazorSampleApp\BlazorSampleApp.csproj", "{D922FDF4-851B-4779-A507-11EB6087918A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorApp", "src\BlazorApp\BlazorApp.csproj", "{2E141D10-E6F4-45F6-94D1-BFE23D0B1B8F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorBff", "src\BlazorBff\BlazorBff.csproj", "{9A116B39-F9D1-460A-A269-596894B3AA3C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorShared", "src\BlazorShared\BlazorShared.csproj", "{AE623DB2-D790-4901-8BC7-D8F73659B83F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorBff.Tests", "tests\BlazorBff.Tests\BlazorBff.Tests.csproj", "{9DF3DA09-9E4E-4FAD-88E4-CFD2EF251717}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorSampleApp.Client", "src\BlazorSampleApp.Client\BlazorSampleApp.Client.csproj", "{D469E4E5-8DED-46C1-803A-6444E3F9085C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E141D10-E6F4-45F6-94D1-BFE23D0B1B8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E141D10-E6F4-45F6-94D1-BFE23D0B1B8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E141D10-E6F4-45F6-94D1-BFE23D0B1B8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E141D10-E6F4-45F6-94D1-BFE23D0B1B8F}.Release|Any CPU.Build.0 = Release|Any CPU
{9A116B39-F9D1-460A-A269-596894B3AA3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A116B39-F9D1-460A-A269-596894B3AA3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A116B39-F9D1-460A-A269-596894B3AA3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A116B39-F9D1-460A-A269-596894B3AA3C}.Release|Any CPU.Build.0 = Release|Any CPU
{AE623DB2-D790-4901-8BC7-D8F73659B83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE623DB2-D790-4901-8BC7-D8F73659B83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE623DB2-D790-4901-8BC7-D8F73659B83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE623DB2-D790-4901-8BC7-D8F73659B83F}.Release|Any CPU.Build.0 = Release|Any CPU
{9DF3DA09-9E4E-4FAD-88E4-CFD2EF251717}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DF3DA09-9E4E-4FAD-88E4-CFD2EF251717}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DF3DA09-9E4E-4FAD-88E4-CFD2EF251717}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DF3DA09-9E4E-4FAD-88E4-CFD2EF251717}.Release|Any CPU.Build.0 = Release|Any CPU
{D922FDF4-851B-4779-A507-11EB6087918A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D922FDF4-851B-4779-A507-11EB6087918A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D922FDF4-851B-4779-A507-11EB6087918A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D922FDF4-851B-4779-A507-11EB6087918A}.Release|Any CPU.Build.0 = Release|Any CPU
{D469E4E5-8DED-46C1-803A-6444E3F9085C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D469E4E5-8DED-46C1-803A-6444E3F9085C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D469E4E5-8DED-46C1-803A-6444E3F9085C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D469E4E5-8DED-46C1-803A-6444E3F9085C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2E141D10-E6F4-45F6-94D1-BFE23D0B1B8F} = {4B42857C-FD8E-4EB6-B9D6-200FD3E19168}
{9A116B39-F9D1-460A-A269-596894B3AA3C} = {4B42857C-FD8E-4EB6-B9D6-200FD3E19168}
{AE623DB2-D790-4901-8BC7-D8F73659B83F} = {4B42857C-FD8E-4EB6-B9D6-200FD3E19168}
{9DF3DA09-9E4E-4FAD-88E4-CFD2EF251717} = {9C59A7AC-5C91-4BC5-97B7-72B20D752B2C}
{D922FDF4-851B-4779-A507-11EB6087918A} = {4B42857C-FD8E-4EB6-B9D6-200FD3E19168}
{D469E4E5-8DED-46C1-803A-6444E3F9085C} = {4B42857C-FD8E-4EB6-B9D6-200FD3E19168}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AED32BEA-7168-480C-BA57-E1182383356F}
Expand Down
84 changes: 1 addition & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,4 @@
# keycloak4blazor

Keycloak for Blazor demo

## Keycloak resources

- [Single Sign-on user authentication on Blazor WebAssembly SignalR client](https://scientificprogrammer.net/2022/08/12/single-sign-on-user-authentication-on-blazor-webassembly-signalr-client/)
- [ASP.NET Core - Keycloak authorization guide](https://github.com/tuxiem/AspNetCore-keycloak/tree/master)
- [Posts tagged with keycloak](https://nikiforovall.github.io/tags.html#keycloak-ref)
- [Using OpenID Connect to secure applications and services](https://www.keycloak.org/docs/latest/securing_apps/#_oidc)
- [OpenID Connect Client with .NET](https://curity.io/resources/learn/dotnet-openid-connect-website/)
- [C#/NetStandard OpenID Connect Client Library for native Applications](https://github.com/IdentityModel/IdentityModel.OidcClient)
- [Secure ASP.NET Core Blazor WebAssembly](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/?view=aspnetcore-7.0)
- [OpenIDConnect Response Type Confusion](https://stackoverflow.com/questions/29275477/openidconnect-response-type-confusion)
- [Blazor.BFF.OpenIDConnect.Template](https://github.com/damienbod/Blazor.BFF.OpenIDConnect.Template)

## BFF Security

- [Securing SPAs and Blazor Applications using the BFF (Backend for Frontend) Pattern - Dominick Baier](https://www.youtube.com/watch?v=hWJuX-8Ur2k)
- [Backend for Frontend (BFF) Security Framework](https://duendesoftware.com/products/bff)

## Openid connect
- [OpenID Connect Client with .NET](https://curity.io/resources/learn/dotnet-openid-connect-website/)
- [Persist additional claims and tokens from external providers in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/additional-claims?view=aspnetcore-7.0)


## Additional
- [Server-side ASP.NET Core Blazor additional security scenarios](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/additional-scenarios?view=aspnetcore-7.0)
- [OIDC authentication in server-side Blazor](https://stackoverflow.com/questions/64853618/oidc-authentication-in-server-side-blazor)
- [Authentication and Authorization](https://gist.github.com/SteveSandersonMS/175a08dcdccb384a52ba760122cd2eda)
- [BlazorWebAssemblyCookieAuth](https://github.com/berhir/BlazorWebAssemblyCookieAuth)

## Access token
- [AccessTokenManagement](https://github.com/DuendeSoftware/Duende.AccessTokenManagement)


## Keycloak setup

```
docker pull keycloak/keycloak
docker run -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -p 8080:8080 keycloak/keycloak:latest start-dev
https://localhost:8080/
```


- Create realm: myrealm
- Create user: afedyanin, set password
- Create group: mygroup
- Add user to group
- Create global role: myrole
- Assign role to user

```
https://localhost:8080/realms/myrealm/account
```

- Create Client: blazor-client
- AuthFlow: Standard flow, Direct access grants
- Client Auth - On

- Add valid redirect urls: https://localhost:5278/*
- Enable CORS on Keycloak +
- Download adapter config

```
{
"realm": "myrealm",
"auth-server-url": "https://localhost:8080/",
"ssl-required": "external",
"resource": "blazor-client",
"credentials": {
"secret": "aNZUREfcTwZjh1qiD095SGQnzL6SQWo0"
},
"confidential-port": 0
}
```

```
curl --data "grant_type=password&client_id=blazor-client&username=afedyanin&password=afedyanin&client_secret=aNZUREfcTwZjh1qiD095SGQnzL6SQWo0" localhost:8080/realms/myrealm/protocol/openid-connect/token
```


Keycloak for Blazor 8 sample app

36 changes: 36 additions & 0 deletions TECH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Blazor 8 Resources

- [Blazor 8 Security](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-8.0)
- [Blazor 8 Samples on GitHub](https://github.com/dotnet/blazor-samples)

## Keycloak resources

- [Single Sign-on user authentication on Blazor WebAssembly SignalR client](https://scientificprogrammer.net/2022/08/12/single-sign-on-user-authentication-on-blazor-webassembly-signalr-client/)
- [ASP.NET Core - Keycloak authorization guide](https://github.com/tuxiem/AspNetCore-keycloak/tree/master)
- [Posts tagged with keycloak](https://nikiforovall.github.io/tags.html#keycloak-ref)
- [Using OpenID Connect to secure applications and services](https://www.keycloak.org/docs/latest/securing_apps/#_oidc)
- [OpenID Connect Client with .NET](https://curity.io/resources/learn/dotnet-openid-connect-website/)
- [C#/NetStandard OpenID Connect Client Library for native Applications](https://github.com/IdentityModel/IdentityModel.OidcClient)
- [Secure ASP.NET Core Blazor WebAssembly](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/?view=aspnetcore-7.0)
- [OpenIDConnect Response Type Confusion](https://stackoverflow.com/questions/29275477/openidconnect-response-type-confusion)
- [Blazor.BFF.OpenIDConnect.Template](https://github.com/damienbod/Blazor.BFF.OpenIDConnect.Template)

## BFF Security

- [Securing SPAs and Blazor Applications using the BFF (Backend for Frontend) Pattern - Dominick Baier](https://www.youtube.com/watch?v=hWJuX-8Ur2k)
- [Backend for Frontend (BFF) Security Framework](https://duendesoftware.com/products/bff)

## Openid connect
- [OpenID Connect Client with .NET](https://curity.io/resources/learn/dotnet-openid-connect-website/)
- [Persist additional claims and tokens from external providers in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/additional-claims?view=aspnetcore-7.0)

## Additional
- [Server-side ASP.NET Core Blazor additional security scenarios](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/additional-scenarios?view=aspnetcore-7.0)
- [OIDC authentication in server-side Blazor](https://stackoverflow.com/questions/64853618/oidc-authentication-in-server-side-blazor)
- [Authentication and Authorization](https://gist.github.com/SteveSandersonMS/175a08dcdccb384a52ba760122cd2eda)
- [BlazorWebAssemblyCookieAuth](https://github.com/berhir/BlazorWebAssemblyCookieAuth)

## Access token
- [AccessTokenManagement](https://github.com/DuendeSoftware/Duende.AccessTokenManagement)


48 changes: 48 additions & 0 deletions keycloak-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Keycloak setup

```
docker pull keycloak/keycloak
docker run -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -p 8080:8080 keycloak/keycloak:latest start-dev
https://localhost:8080/
```

- Create realm: myrealm
- Create user: afedyanin, set password
- Create group: mygroup
- Add user to group
- Create global role: myrole
- Assign role to user

```
https://localhost:8080/realms/myrealm/account
```

- Create Client: blazor-client
- AuthFlow: Standard flow, Direct access grants
- Client Auth - On

- Add valid redirect urls: https://localhost:5278/*
- Enable CORS on Keycloak +
- Download adapter config

```
{
"realm": "myrealm",
"auth-server-url": "https://localhost:8080/",
"ssl-required": "external",
"resource": "blazor-client",
"credentials": {
"secret": "aNZUREfcTwZjh1qiD095SGQnzL6SQWo0"
},
"confidential-port": 0
}
```

```
curl --data "grant_type=password&client_id=blazor-client&username=afedyanin&password=afedyanin&client_secret=aNZUREfcTwZjh1qiD095SGQnzL6SQWo0" localhost:8080/realms/myrealm/protocol/openid-connect/token
```


25 changes: 0 additions & 25 deletions src/BlazorApp/App.razor

This file was deleted.

21 changes: 0 additions & 21 deletions src/BlazorApp/BlazorApp.csproj

This file was deleted.

19 changes: 0 additions & 19 deletions src/BlazorApp/Pages/CurrentUser.razor

This file was deleted.

45 changes: 0 additions & 45 deletions src/BlazorApp/Pages/FetchData.razor

This file was deleted.

Loading

0 comments on commit 92187ca

Please sign in to comment.