diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml
index 9c7da7a..ceabaec 100644
--- a/.github/workflows/blank.yml
+++ b/.github/workflows/blank.yml
@@ -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
diff --git a/README.md b/README.md
index e2bbbaa..c015b8b 100644
--- a/README.md
+++ b/README.md
@@ -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
@@ -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:
diff --git a/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj b/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj
index f8768b8..3ae1ff8 100644
--- a/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj
+++ b/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj
@@ -22,7 +22,7 @@
-
+
diff --git a/examples/Examples.AspNetCoreHosted/Client/Startup.cs b/examples/Examples.AspNetCoreHosted/Client/Startup.cs
index ef6c8b0..b5cc893 100644
--- a/examples/Examples.AspNetCoreHosted/Client/Startup.cs
+++ b/examples/Examples.AspNetCoreHosted/Client/Startup.cs
@@ -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
diff --git a/examples/Examples.ClientSide/Examples.ClientSide.csproj b/examples/Examples.ClientSide/Examples.ClientSide.csproj
index 5d931a7..3955c40 100644
--- a/examples/Examples.ClientSide/Examples.ClientSide.csproj
+++ b/examples/Examples.ClientSide/Examples.ClientSide.csproj
@@ -22,7 +22,7 @@
-
+
diff --git a/examples/Examples.ClientSide/Shared/LoginDisplay.razor b/examples/Examples.ClientSide/Shared/LoginDisplay.razor
index 747ce0b..9a77c23 100644
--- a/examples/Examples.ClientSide/Shared/LoginDisplay.razor
+++ b/examples/Examples.ClientSide/Shared/LoginDisplay.razor
@@ -2,13 +2,13 @@
- await authService.LogOut())">
+ await authService.LogOut())">
Logout
-
+
Login
diff --git a/examples/Examples.ClientSide/Startup.cs b/examples/Examples.ClientSide/Startup.cs
index 014fafa..37bd414 100644
--- a/examples/Examples.ClientSide/Startup.cs
+++ b/examples/Examples.ClientSide/Startup.cs
@@ -1,4 +1,5 @@
using Blazor.Auth0;
+using Blazor.Auth0.Models.Enumerations;
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;
@@ -9,7 +10,6 @@ public class Startup
public void ConfigureServices(IServiceCollection services)
{
-
services.AddBlazorAuth0(options =>
{
// Required
@@ -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
diff --git a/examples/Examples.ClientSide/_Imports.razor b/examples/Examples.ClientSide/_Imports.razor
index 8abee15..ee159b1 100644
--- a/examples/Examples.ClientSide/_Imports.razor
+++ b/examples/Examples.ClientSide/_Imports.razor
@@ -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
diff --git a/examples/Examples.ServerSide/Examples.ServerSide.csproj b/examples/Examples.ServerSide/Examples.ServerSide.csproj
index 0dd14ce..96572c1 100644
--- a/examples/Examples.ServerSide/Examples.ServerSide.csproj
+++ b/examples/Examples.ServerSide/Examples.ServerSide.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/src/Blazor.Auth0.ClientSide/Authentication.cs b/src/Blazor.Auth0.ClientSide/Authentication.cs
index bdcb760..c86ddb9 100644
--- a/src/Blazor.Auth0.ClientSide/Authentication.cs
+++ b/src/Blazor.Auth0.ClientSide/Authentication.cs
@@ -96,6 +96,32 @@ public static string BuildAuthorizeUrl(AuthorizeOptions buildAuthorizedUrlOption
/// A param.
/// A representing the result of the asynchronous operation.
public static async Task Authorize(IJSRuntime jsRuntime, NavigationManager navigationManager, AuthorizeOptions authorizeOptions)
+ {
+ await Authorize(jsRuntime, null, navigationManager, authorizeOptions).ConfigureAwait(false);
+ }
+
+ ///
+ /// Initiates the Authorization flow by calling the IDP's /authorize enpoint inside a popup window.
+ ///
+ /// A param.
+ /// A param.
+ /// A param.
+ /// A param.
+ /// A representing the result of the asynchronous operation.
+ public static async Task AuthorizePopup(IJSRuntime jsRuntime, object objectReference, NavigationManager navigationManager, AuthorizeOptions authorizeOptions)
+ {
+ await Authorize(jsRuntime, objectReference, navigationManager, authorizeOptions).ConfigureAwait(false);
+ }
+
+ ///
+ /// Initiates the Authorization flow by calling the IDP's /authorize endpoint, if an objectReference is passed as param a popup login will be triggered.
+ ///
+ /// A param.
+ /// A param.
+ /// A param.
+ /// A param.
+ /// A representing the result of the asynchronous operation.
+ internal static async Task Authorize(IJSRuntime jsRuntime, object objectReference, NavigationManager navigationManager, AuthorizeOptions authorizeOptions)
{
if (jsRuntime is null)
{
@@ -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);
+ }
}
///
diff --git a/src/Blazor.Auth0.ClientSide/AuthenticationService.cs b/src/Blazor.Auth0.ClientSide/AuthenticationService.cs
index bcad47e..9e53674 100644
--- a/src/Blazor.Auth0.ClientSide/AuthenticationService.cs
+++ b/src/Blazor.Auth0.ClientSide/AuthenticationService.cs
@@ -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);
+ }
}
///
@@ -256,8 +263,16 @@ public Task GetAuthenticationStateAsync()
///
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
{
@@ -496,7 +511,6 @@ private void ClearSession()
this.SessionInfo = null;
this.sessionAuthorizationTransaction = null;
this.logOutTimer?.Stop();
- this.logOutTimer?.Dispose();
}
private async Task SilentLogin()
diff --git a/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj b/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj
index 60c373b..53dd659 100644
--- a/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj
+++ b/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj
@@ -4,7 +4,7 @@
netstandard2.0
3.0
8.0
- 2.0.0-Preview1
+ 2.0.0-Preview2
Henry Alberto Rodriguez Rodriguez
Auth0 library for Balzor
https://github.com/henalbrod/Blazor.Auth0
@@ -16,11 +16,16 @@
true
https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png
Blazor-Auth0-ClientSide
- Upgraded to .Net Core 3.1.0-preview1
+ 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")
+ * 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
true
..\..\packages
@@ -63,7 +68,7 @@ Auth0 permissions are now accesible as an any other array claim: policy.RequireC
-
+
diff --git a/src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js b/src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js
index 83cd842..b039aed 100644
--- a/src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js
+++ b/src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js
@@ -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";
@@ -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();
+
}
};
\ No newline at end of file
diff --git a/src/Blazor.Auth0.ServerSide/Blazor.Auth0.ServerSide.csproj b/src/Blazor.Auth0.ServerSide/Blazor.Auth0.ServerSide.csproj
index fa4f355..e679d07 100644
--- a/src/Blazor.Auth0.ServerSide/Blazor.Auth0.ServerSide.csproj
+++ b/src/Blazor.Auth0.ServerSide/Blazor.Auth0.ServerSide.csproj
@@ -3,7 +3,7 @@
netcoreapp3.1
8.0
- 2.0.0-Preview1
+ 2.0.0-Preview2
Henry Alberto Rodriguez Rodriguez
Auth0 library for Balzor
https://github.com/henalbrod/Blazor.Auth0
@@ -15,11 +15,16 @@
true
https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png
Blazor-Auth0-ServerSide
- Upgraded to .Net Core 3.1.0-preview1
+ 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")
+ * 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
true
..\..\packages
@@ -40,7 +45,7 @@ Auth0 permissions are now accesible as an any other array claim: policy.RequireC
-
+
diff --git a/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj b/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj
index 0eade8b..39aed5f 100644
--- a/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj
+++ b/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj
@@ -3,7 +3,7 @@
netstandard2.0
8.0
- 2.0.0-Preview1
+ 2.0.0-Preview2
Henry Alberto Rodriguez Rodriguez
Auth0 library for Balzor
https://github.com/henalbrod/Blazor.Auth0
@@ -15,11 +15,16 @@
true
https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png
Blazor-Auth0-Shared
- Upgraded to .Net Core 3.1.0-preview1
+ 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")
+ * 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
true
..\..\packages
diff --git a/src/Blazor.Auth0.Shared/Models/ClientOptions.cs b/src/Blazor.Auth0.Shared/Models/ClientOptions.cs
index 38f35fa..6bc75f2 100644
--- a/src/Blazor.Auth0.Shared/Models/ClientOptions.cs
+++ b/src/Blazor.Auth0.Shared/Models/ClientOptions.cs
@@ -88,6 +88,8 @@ public class ClientOptions : IValidatableObject
public string Realm { get; set; }
+ public LoginModes LoginMode { get; set; } = LoginModes.Redirect;
+
#endregion
///
diff --git a/src/Blazor.Auth0.Shared/Models/Enumerations.cs b/src/Blazor.Auth0.Shared/Models/Enumerations.cs
index e2a362d..f82d9c2 100644
--- a/src/Blazor.Auth0.Shared/Models/Enumerations.cs
+++ b/src/Blazor.Auth0.Shared/Models/Enumerations.cs
@@ -56,4 +56,10 @@ public enum CodeChallengeMethods
None = 0,
S256,
}
+
+ public enum LoginModes
+ {
+ Redirect = 0,
+ Popup
+ }
}