Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Commit

Permalink
v2.0.0-Preview1
Browse files Browse the repository at this point in the history
  • Loading branch information
henalbrod committed Oct 26, 2019
1 parent a378e67 commit a2e3c4c
Show file tree
Hide file tree
Showing 18 changed files with 215 additions and 98 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:

container:
image: mcr.microsoft.com/dotnet/core/sdk:3.0.100-disco
image: mcr.microsoft.com/dotnet/core/sdk:3.1.100-preview1-bionic

runs-on: ubuntu-16.04

Expand All @@ -20,39 +20,31 @@ jobs:
- name: Build Blazor-Auth0-Shared project.
run: |
dotnet build src/Blazor.Auth0.Shared
dotnet pack src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj --no-build --output $HOME
- name: Build Blazor-Auth0-ClientSide project.
run: |
dotnet restore src/Blazor.Auth0.ClientSide -s $HOME -s https://api.nuget.org/v3/index.json
dotnet build src/Blazor.Auth0.ClientSide
dotnet pack src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj --no-build --output $HOME
dotnet build src/Blazor.Auth0.ClientSide --source /__w/Blazor.Auth0/packages --source https://api.nuget.org/v3/index.json --configuration Release
- name: Build Blazor-Auth0-ServerSide project.
run: |
dotnet restore src/Blazor.Auth0.ServerSide -s $HOME -s https://api.nuget.org/v3/index.json
dotnet build src/Blazor.Auth0.ServerSide
dotnet pack src/Blazor.Auth0.ServerSide/Blazor.Auth0.ServerSide.csproj --no-build --output $HOME
dotnet build src/Blazor.Auth0.ServerSide --source /__w/Blazor.Auth0/packages --source https://api.nuget.org/v3/index.json --configuration Release
- name: Build AspNetCoreHosted Example.
run: |
dotnet restore examples/Examples.AspNetCoreHosted/Client -s $HOME -s https://api.nuget.org/v3/index.json
dotnet build examples/Examples.AspNetCoreHosted/Server
dotnet build examples/Examples.AspNetCoreHosted/Server --source /__w/Blazor.Auth0/packages --source https://api.nuget.org/v3/index.json --configuration Release
- name: Build ClientSide Example.
run: |
dotnet restore examples/Examples.ClientSide -s $HOME -s https://api.nuget.org/v3/index.json
dotnet build examples/Examples.ClientSide
dotnet build examples/Examples.ClientSide --source /__w/Blazor.Auth0/packages --source https://api.nuget.org/v3/index.json --configuration Release
- name: Build ServerSide Example.
run: |
dotnet restore examples/Examples.ServerSide -s $HOME -s https://api.nuget.org/v3/index.json
dotnet build examples/Examples.ServerSide
dotnet build examples/Examples.ServerSide --source /__w/Blazor.Auth0/packages --source https://api.nuget.org/v3/index.json --configuration Release
- name: Publish Blazor-Auth0-Shared Nuget package.
Expand Down
9 changes: 9 additions & 0 deletions Nuget.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<configuration>
<packageSources>
<add key="Soluction Packages" value="packages" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="Soluction Packages" value="packages" />
</activePackageSource>
</configuration>
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img src="https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png" height="150" alt="Blazor Auth0 Library" align="right"/>

This is a library for Blazor authentication with OIDC Authorization Code-Grant and Implicit-Grant flows, using Auth0's Universal Login and Silent Login for [Blazor](http://blazor.net) over .NET Core v3.0.0 client & server-side solutions, the idea behind this is to have an easy way of using Auth0's services in Blazor without the need of the auth0.js library.
This is a library for Blazor authentication with OIDC Authorization Code-Grant and Implicit-Grant flows, using Auth0's Universal Login and Silent Login for [Blazor](http://blazor.net) over .Net Core 3.1.0-preview1 client & server-side solutions, the idea behind this is to have an easy way of using Auth0's services in Blazor without the need of the auth0.js library.

[![Nuget](https://img.shields.io/nuget/v/Blazor-Auth0-ServerSide?color=green&label=Nuget%3A%20Blazor-Auth0-ServerSide)](https://www.nuget.org/packages/Blazor-Auth0-ServerSide)
[![Nuget](https://img.shields.io/nuget/v/Blazor-Auth0-ClientSide?color=green&label=Nuget%3A%20Blazor-Auth0-Clientside)](https://www.nuget.org/packages/Blazor-Auth0-ClientSide)
Expand Down Expand Up @@ -36,12 +36,12 @@ Install via [Nuget](https://www.nuget.org/).

>Server Side
```bash
Install-Package Blazor-Auth0-ServerSide -Version 1.0.0-Preview3
Install-Package Blazor-Auth0-ServerSide -Version 2.0.0-Preview1
````

>Client Side
```bash
Install-Package Blazor-Auth0-ClientSide -Version 1.0.0-Preview3
Install-Package Blazor-Auth0-ClientSide -Version 2.0.0-Preview1
````
## Usage
Expand Down Expand Up @@ -134,14 +134,11 @@ Pull requests are welcome. For major changes, please open an issue first to disc
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request

* Especial thanks for its help to all the [contributors](https://github.com/henalbrod/Blazor.Auth0/graphs/contributors)

## Authors
**Henry Alberto Rodriguez** - _Initial work_ - [GitHub](https://github.com/henalbrod) - [Twitter](https://twitter.com/henalbrod) - [Linkedin](https://www.linkedin.com/in/henalbrod/)

* Especial thanks for its contributions to:

**jbomhold3** [GitHub](https://github.com/jbomhold3)
**TopSwagCode** [GitHub](https://github.com/TopSwagCode)

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/henalbrod/Blazor.Auth0/blob/master/LICENSE) file for details.
Expand All @@ -154,6 +151,17 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu

## Release History

**v2.0.0-Preview1**

BREAKING CHANGES:

* Upgraded to .Net Core 3.1.0-preview1
* Server side projects upgraded to netcoreapp3.1
* Auth0 permissions are now accesible as an any other array claim:
```C#
policy.RequireClaim("permissions", "permission_name")
```

**v1.0.0-Preview3**
* Overall upgrade to .Net Core 3.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -8,13 +8,26 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazor-Auth0-ClientSide" Version="1.0.0-Preview3" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.1.0-preview1.19508.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.1.0-preview1.19508.20" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>

<Choose>
<When Condition="'$(Configuration)'=='Debug'">
<ItemGroup>
<ProjectReference Include="..\..\..\src\Blazor.Auth0.ClientSide\Blazor.Auth0.ClientSide.csproj" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-ClientSide" Version="1.0.0-Preview3" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup>
<ProjectReference Include="..\Shared\Examples.AspNetCoreHosted.Shared.csproj" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions examples/Examples.AspNetCoreHosted/Client/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void ConfigureServices(IServiceCollection services)
options.Domain = "[Auth0_Domain]";
// Required
options.ClientId = "[Auth0_client_Id]";
options.ClientId = "[Auth0_Client_Id]";
//// Required if you want to make use of Auth0's RBAC
options.Audience = "[Auth0_Audience]";
Expand All @@ -29,11 +29,11 @@ public void ConfigureServices(IServiceCollection services)
// options.SlidingExpiration = true;
});

// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.0
// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.1
services.AddAuthorizationCore(options =>
{
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("read:weather_forecast"));
options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("execute:increment_counter"));
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions", "read:weather_forecast"));
options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("permissions", "execute:increment_counter"));
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>7.3</LangVersion>
<UserSecretsId>12dacd65-df84-4051-99c4-fbc453d4c470</UserSecretsId>
<UserSecretsId>6c2330d9-84c7-4bf5-80a9-6b48c017bbab</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0-preview1.19508.20" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions examples/Examples.AspNetCoreHosted/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddAuthorizationCore(options =>
{
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("read:weather_forecast"));
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions","read:weather_forecast"));
});

services.AddResponseCompression(opts =>
Expand All @@ -62,12 +62,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}

app.UseAuthentication();
app.UseAuthorization();

app.UseStaticFiles();
app.UseClientSideBlazorFiles<Client.Startup>();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
Expand Down
22 changes: 17 additions & 5 deletions examples/Examples.ClientSide/Examples.ClientSide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazor-Auth0-ClientSide" Version="1.0.0-Preview3" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.1.0-preview1.19508.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.1.0-preview1.19508.20" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.1.0-preview1.19508.20" PrivateAssets="all" />
</ItemGroup>

<Choose>
<When Condition="'$(Configuration)'=='Debug'">
<ItemGroup>
<ProjectReference Include="..\..\src\Blazor.Auth0.ClientSide\Blazor.Auth0.ClientSide.csproj" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-ClientSide" Version="1.0.0-Preview3" />
</ItemGroup>
</Otherwise>
</Choose>

</Project>
8 changes: 4 additions & 4 deletions examples/Examples.ClientSide/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ConfigureServices(IServiceCollection services)
options.Domain = "[Auth0_Domain]";
// Required
options.ClientId = "[Auth0_client_Id]";
options.ClientId = "[Auth0_Client_Id]";
//// Required if you want to make use of Auth0's RBAC
options.Audience = "[Auth0_Audience]";
Expand All @@ -31,11 +31,11 @@ public void ConfigureServices(IServiceCollection services)
// options.SlidingExpiration = true;
});

// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.0
// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.1
services.AddAuthorizationCore(options =>
{
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("read:weather_forecast"));
options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("execute:increment_counter"));
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions", "read:weather_forecast"));
options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("permissions", "execute:increment_counter"));
});

}
Expand Down
19 changes: 13 additions & 6 deletions examples/Examples.ServerSide/Examples.ServerSide.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>


<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>6c2330d9-84c7-4bf5-80a9-6b48c017bbab</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazor-Auth0-ServerSide" Version="1.0.0-Preview3" />
</ItemGroup>
<Choose>
<When Condition="'$(Configuration)'=='Debug'">
<ItemGroup>
<ProjectReference Include="..\..\src\Blazor.Auth0.ServerSide\Blazor.Auth0.ServerSide.csproj" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-ServerSide" Version="1.0.0-Preview3" />
</ItemGroup>
</Otherwise>
</Choose>

<ItemGroup>
<Content Update="wwwroot\css\site.css">
Expand Down
8 changes: 4 additions & 4 deletions examples/Examples.ServerSide/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public void ConfigureServices(IServiceCollection services)
// New Blazor.Auth0 one liner intantiation
services.AddDefaultBlazorAuth0Authentication(Configuration.GetSection("Auth0").Get<ClientOptions>());

// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.0
services.AddAuthorization(options =>
// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.1
services.AddAuthorizationCore(options =>
{
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("read:weather_forecast"));
options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("execute:increment_counter"));
options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions", "read:weather_forecast"));
options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("permissions", "execute:increment_counter"));
});

services.AddSingleton<WeatherForecastService>();
Expand Down
2 changes: 1 addition & 1 deletion examples/Examples.ServerSide/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Auth0": {
"Domain": "[Auth0_Audience]",
"Domain": "[Auth0_Domain]",
"ClientId": "[Auth0_Client_Id]",
"Audience": "[Auth0_Audience]",
"ClientSecret": "[Auth0_Client_Secret]"
Expand Down
2 changes: 1 addition & 1 deletion src/Blazor.Auth0.ClientSide/AuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public Task<AuthenticationState> GetAuthenticationStateAsync()

identity.AddClaims(this.User.CustomClaims.Select(customClaim => new Claim(customClaim.Key, customClaim.Value.GetRawText(), customClaim.Value.ValueKind.ToString())));

identity.AddClaims(this.User.Permissions.Select(permission => new Claim($"{permission}", "true", "permissions")));
identity.AddClaims(this.User.Permissions.Select(permission => new Claim("permissions", permission, "permissions")));
}
else
{
Expand Down
Loading

0 comments on commit a2e3c4c

Please sign in to comment.