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-Preview2
Browse files Browse the repository at this point in the history
  • Loading branch information
henalbrod committed Nov 4, 2019
1 parent b231f47 commit 9d5026b
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 30 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ jobs:
- name: Publish Blazor-Auth0-Share Nuget package.
if: github.ref == 'master'
if: github.ref == 'refs/heads/master'
continue-on-error: true
run: |
dotnet nuget push packages/Blazor-Auth0-Share*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
- name: Publish Blazor-Auth0-ClientSide Nuget package.
if: github.ref == 'master'
if: github.ref == 'refs/heads/master'
continue-on-error: true
run: |
run: |
dotnet nuget push packages/Blazor-Auth0-ClientSide*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
- name: Publish Blazor-Auth0-ServerSide Nuget package.
if: github.ref == 'master'
if: github.ref == 'refs/heads/master'
continue-on-error: true
run: |
dotnet nuget push packages/Blazor-Auth0-ServerSide*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Install via [Nuget](https://www.nuget.org/).

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

>Client Side
```bash
Install-Package Blazor-Auth0-ClientSide -Version 2.0.0-Preview1
Install-Package Blazor-Auth0-ClientSide -Version 2.0.0-Preview2
````
## Usage
Expand Down Expand Up @@ -151,6 +151,19 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu

## Release History

**v2.0.0-Preview2**

This relase comes with Client Side changes primarly

* New LoginMode parameter in ClientOptions

Redirect = Classic behavior (default)
PopUp = Loads Universal Login inside a popup window

The new PopUp behavior comes in handy to avoid the full client side app reloading

* New AuthorizePopup method in Blazor.Auth0.Authentication for client side

**v2.0.0-Preview1**

BREAKING CHANGES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-ClientSide" Version="1.0.0-Preview3" />
<PackageReference Include="Blazor-Auth0-ClientSide" Version="2.0.0-Preview2" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down
3 changes: 3 additions & 0 deletions examples/Examples.AspNetCoreHosted/Client/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public void ConfigureServices(IServiceCollection services)

//// Uncomment the following line if you don't want your users to be automatically logged-off on token expiration
// options.SlidingExpiration = true;

//// Uncomment the following line if you want your users to log in via a pop-up window instead of being redirected
// options.LoginMode = LoginModes.Popup;
});

// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.1
Expand Down
2 changes: 1 addition & 1 deletion examples/Examples.ClientSide/Examples.ClientSide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-ClientSide" Version="1.0.0-Preview3" />
<PackageReference Include="Blazor-Auth0-ClientSide" Version="2.0.0-Preview2" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down
4 changes: 2 additions & 2 deletions examples/Examples.ClientSide/Shared/LoginDisplay.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<AuthorizeView>
<Authorized>
<NavLink class="nav-link" href="" @onclick="@(async ()=> await authService.LogOut())">
<NavLink class="nav-link" href="javascript:void(0)" @onclick="@(async ()=> await authService.LogOut())">
<span class="oi oi-account-logout" aria-hidden="true"></span> Logout
</NavLink>

</Authorized>
<NotAuthorized>
<NavLink class="nav-link" href="" @onclick="authService.Authorize">
<NavLink class="nav-link" href="javascript:void(0)" @onclick="authService.Authorize">
<span class="oi oi-account-login" aria-hidden="true"></span> Login
</NavLink>
</NotAuthorized>
Expand Down
5 changes: 4 additions & 1 deletion examples/Examples.ClientSide/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Blazor.Auth0;
using Blazor.Auth0.Models.Enumerations;
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -9,7 +10,6 @@ public class Startup

public void ConfigureServices(IServiceCollection services)
{

services.AddBlazorAuth0(options =>
{
// Required
Expand All @@ -29,6 +29,9 @@ public void ConfigureServices(IServiceCollection services)

//// Uncomment the following line if you don't want your users to be automatically logged-off on token expiration
// options.SlidingExpiration = true;

//// Uncomment the following line if you want your users to log in via a pop-up window instead of being redirected
// options.LoginMode = LoginModes.Popup;
});

// Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.1
Expand Down
1 change: 1 addition & 0 deletions examples/Examples.ClientSide/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@using Microsoft.JSInterop
@using Examples.ClientSide
@using Examples.ClientSide.Shared
@using Examples.ClientSide.Pages

@using Blazor.Auth0
@using Blazor.Auth0.Models
Expand Down
2 changes: 1 addition & 1 deletion examples/Examples.ServerSide/Examples.ServerSide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-ServerSide" Version="1.0.0-Preview3" />
<PackageReference Include="Blazor-Auth0-ServerSide" Version="2.0.0-Preview2" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down
36 changes: 35 additions & 1 deletion src/Blazor.Auth0.ClientSide/Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,32 @@ public static string BuildAuthorizeUrl(AuthorizeOptions buildAuthorizedUrlOption
/// <param name="authorizeOptions">A <see cref="AuthorizeOptions"/> param.</param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
public static async Task Authorize(IJSRuntime jsRuntime, NavigationManager navigationManager, AuthorizeOptions authorizeOptions)
{
await Authorize(jsRuntime, null, navigationManager, authorizeOptions).ConfigureAwait(false);
}

/// <summary>
/// Initiates the Authorization flow by calling the IDP's /authorize enpoint inside a popup window.
/// </summary>
/// <param name="jsRuntime">A <see cref="IJSRuntime"/> param.</param>
/// <param name="objectReference">A <see cref="DotNetObjectReference"/> param.</param>
/// <param name="navigationManager">A <see cref="NavigationManager"/> param.</param>
/// <param name="authorizeOptions">A <see cref="AuthorizeOptions"/> param.</param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
public static async Task AuthorizePopup(IJSRuntime jsRuntime, object objectReference, NavigationManager navigationManager, AuthorizeOptions authorizeOptions)
{
await Authorize(jsRuntime, objectReference, navigationManager, authorizeOptions).ConfigureAwait(false);
}

/// <summary>
/// Initiates the Authorization flow by calling the IDP's /authorize endpoint, if an objectReference is passed as param a popup login will be triggered.
/// </summary>
/// <param name="jsRuntime">A <see cref="IJSRuntime"/> param.</param>
/// <param name="objectReference">A <see cref="DotNetObjectReference"/> param.</param>
/// <param name="navigationManager">A <see cref="NavigationManager"/> param.</param>
/// <param name="authorizeOptions">A <see cref="AuthorizeOptions"/> param.</param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
internal static async Task Authorize(IJSRuntime jsRuntime, object objectReference, NavigationManager navigationManager, AuthorizeOptions authorizeOptions)
{
if (jsRuntime is null)
{
Expand All @@ -118,7 +144,15 @@ public static async Task Authorize(IJSRuntime jsRuntime, NavigationManager navig

string authorizeUrl = BuildAuthorizeUrl(authorizeOptions);

navigationManager.NavigateTo(authorizeUrl);
// If an objectReference is passed as param a popup login will be triggered.
if (objectReference == null)
{
navigationManager.NavigateTo(authorizeUrl);
}
else
{
await jsRuntime.InvokeVoidAsync($"{Resources.InteropElementName}.popupLogin", objectReference, authorizeUrl).ConfigureAwait(false);
}
}

/// <summary>
Expand Down
20 changes: 17 additions & 3 deletions src/Blazor.Auth0.ClientSide/AuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ public async Task Authorize()
{
AuthorizeOptions options = this.BuildAuthorizeOptions();

await Authentication.Authorize(this.jsRuntime, this.navigationManager, options).ConfigureAwait(false);
if (this.clientOptions.LoginMode == LoginModes.Popup)
{
await Authentication.AuthorizePopup(this.jsRuntime, this.dotnetObjectRef, this.navigationManager, options).ConfigureAwait(false);
}
else
{
await Authentication.Authorize(this.jsRuntime, this.navigationManager, options).ConfigureAwait(false);
}
}

/// <inheritdoc/>
Expand Down Expand Up @@ -256,8 +263,16 @@ public Task<AuthenticationState> GetAuthenticationStateAsync()
/// <inheritdoc/>
public async Task ValidateSession()
{
await this.ValidateSession(this.navigationManager.Uri).ConfigureAwait(false);
}

[JSInvokable]
public async Task ValidateSession(string path)
{
// TODO: Add validation such as same host and similars

// Let's validate the hash
Uri absoluteUri = this.navigationManager.ToAbsoluteUri(this.navigationManager.Uri);
Uri absoluteUri = this.navigationManager.ToAbsoluteUri(path);

ParsedHash parsedHash = Authentication.ParseHash(new ParseHashOptions
{
Expand Down Expand Up @@ -496,7 +511,6 @@ private void ClearSession()
this.SessionInfo = null;
this.sessionAuthorizationTransaction = null;
this.logOutTimer?.Stop();
this.logOutTimer?.Dispose();
}

private async Task SilentLogin()
Expand Down
15 changes: 10 additions & 5 deletions src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<LangVersion>8.0</LangVersion>
<Version>2.0.0-Preview1</Version>
<Version>2.0.0-Preview2</Version>
<Authors>Henry Alberto Rodriguez Rodriguez</Authors>
<Description>Auth0 library for Balzor</Description>
<PackageProjectUrl>https://github.com/henalbrod/Blazor.Auth0</PackageProjectUrl>
Expand All @@ -16,11 +16,16 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png</PackageIconUrl>
<PackageId>Blazor-Auth0-ClientSide</PackageId>
<PackageReleaseNotes>Upgraded to .Net Core 3.1.0-preview1
<PackageReleaseNotes>This relase comes with Client Side changes primarly

BREAKING CHANGES:
- New LoginMode parameter in ClientOptions

Auth0 permissions are now accesible as an any other array claim: policy.RequireClaim("permissions", "permission_name")</PackageReleaseNotes>
* Redirect = Classic behavior (default)
* PopUp = Loads Universal Login inside a popup window

The new PopUp behavior comes in handy to avoid the full client side app reloading

- New AuthorizePopup method in Blazor.Auth0.Authentication for client side</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>..\..\packages</PackageOutputPath>
</PropertyGroup>
Expand Down Expand Up @@ -63,7 +68,7 @@ Auth0 permissions are now accesible as an any other array claim: policy.RequireC
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-Shared" Version="1.0.0-Preview3" />
<PackageReference Include="Blazor-Auth0-Shared" Version="2.0.0-Preview2" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down
22 changes: 22 additions & 0 deletions src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"use strict";

if (window.opener && window.name === "auth0_signup_popup") {
window.opener.___blazor_auth0.popupCallback(window.location.href);
close();
}

window.___blazor_auth0 = {
logOut: (src) => {
"use strict";
Expand Down Expand Up @@ -42,5 +47,22 @@ window.___blazor_auth0 = {
}
};
window.addEventListener("message", messageListener);
},
popupLogin: (instance, src) => {
"use strict";

let top = 100;
let left = (window.innerWidth / 2) - 225;

window.___blazor_auth0.popupCallback = (path) => {
instance.invokeMethodAsync("ValidateSession", path)
.then((r) => {
window.___blazor_auth0.popupCallback = null;
});
};

let popup = window.open(src, "auth0_signup_popup", "width=450,height=700,top=" + top + ",left=" + left + ",menubar=no,location=no,resizable=no,scrollbars=no,status=no,personalbar=no");
popup.focus();

}
};
15 changes: 10 additions & 5 deletions src/Blazor.Auth0.ServerSide/Blazor.Auth0.ServerSide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<Version>2.0.0-Preview1</Version>
<Version>2.0.0-Preview2</Version>
<Authors>Henry Alberto Rodriguez Rodriguez</Authors>
<Description>Auth0 library for Balzor</Description>
<PackageProjectUrl>https://github.com/henalbrod/Blazor.Auth0</PackageProjectUrl>
Expand All @@ -15,11 +15,16 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png</PackageIconUrl>
<PackageId>Blazor-Auth0-ServerSide</PackageId>
<PackageReleaseNotes>Upgraded to .Net Core 3.1.0-preview1
<PackageReleaseNotes>This relase comes with Client Side changes primarly

BREAKING CHANGES:
- New LoginMode parameter in ClientOptions

Auth0 permissions are now accesible as an any other array claim: policy.RequireClaim("permissions", "permission_name")</PackageReleaseNotes>
* Redirect = Classic behavior (default)
* PopUp = Loads Universal Login inside a popup window

The new PopUp behavior comes in handy to avoid the full client side app reloading

- New AuthorizePopup method in Blazor.Auth0.Authentication for client side</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>..\..\packages</PackageOutputPath>
</PropertyGroup>
Expand All @@ -40,7 +45,7 @@ Auth0 permissions are now accesible as an any other array claim: policy.RequireC
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="Blazor-Auth0-Shared" Version="1.0.0-Preview3" />
<PackageReference Include="Blazor-Auth0-Shared" Version="2.0.0-Preview2" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down
13 changes: 9 additions & 4 deletions src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<Version>2.0.0-Preview1</Version>
<Version>2.0.0-Preview2</Version>
<Authors>Henry Alberto Rodriguez Rodriguez</Authors>
<Description>Auth0 library for Balzor</Description>
<PackageProjectUrl>https://github.com/henalbrod/Blazor.Auth0</PackageProjectUrl>
Expand All @@ -15,11 +15,16 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png</PackageIconUrl>
<PackageId>Blazor-Auth0-Shared</PackageId>
<PackageReleaseNotes>Upgraded to .Net Core 3.1.0-preview1
<PackageReleaseNotes>This relase comes with Client Side changes primarly

BREAKING CHANGES:
- New LoginMode parameter in ClientOptions

Auth0 permissions are now accesible as an any other array claim: policy.RequireClaim("permissions", "permission_name")</PackageReleaseNotes>
* Redirect = Classic behavior (default)
* PopUp = Loads Universal Login inside a popup window

The new PopUp behavior comes in handy to avoid the full client side app reloading

- New AuthorizePopup method in Blazor.Auth0.Authentication for client side</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>..\..\packages</PackageOutputPath>
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Blazor.Auth0.Shared/Models/ClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class ClientOptions : IValidatableObject

public string Realm { get; set; }

public LoginModes LoginMode { get; set; } = LoginModes.Redirect;

#endregion

/// <inheritdoc/>
Expand Down
6 changes: 6 additions & 0 deletions src/Blazor.Auth0.Shared/Models/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ public enum CodeChallengeMethods
None = 0,
S256,
}

public enum LoginModes
{
Redirect = 0,
Popup
}
}

0 comments on commit 9d5026b

Please sign in to comment.