From 8474591aa248f1a067abb0a38bd54412c9322a7d Mon Sep 17 00:00:00 2001 From: Henry Alberto Rodriguez Date: Tue, 3 Mar 2020 23:43:26 -0500 Subject: [PATCH] v2.0.0-Preview5 Fixed issue #41, Upgraded to .Net Core v3.2.0-preview1 --- .github/workflows/blank.yml | 2 +- README.md | 71 ++++++++++--------- .../Examples.AspNetCoreHosted.Client.csproj | 12 ++-- .../Client/Program.cs | 53 +++++++++++--- .../Client/Startup.cs | 48 ------------- .../Examples.AspNetCoreHosted.Server.csproj | 8 +-- .../Server/Startup.cs | 4 +- .../Examples.AspNetCoreHosted.Shared.csproj | 1 - .../Examples.ClientSide.csproj | 12 ++-- examples/Examples.ClientSide/Program.cs | 56 ++++++++++++--- examples/Examples.ClientSide/Startup.cs | 51 ------------- .../Examples.ClientSide/wwwroot/index.html | 2 +- .../Examples.ServerSide.csproj | 2 +- .../AuthenticationService.cs | 7 +- .../Blazor.Auth0.ClientSide.csproj | 30 ++++---- .../Properties/Resources.Designer.cs | 24 +++++++ .../Properties/Resources.resx | 70 ++++++++++++++++++ .../wwwroot/blazor-auth0-clientside.js | 68 ------------------ .../Blazor.Auth0.ServerSide.csproj | 14 ++-- .../Blazor.Auth0.Shared.csproj | 16 ++--- src/Blazor.Auth0.sln | 15 ++++ 21 files changed, 293 insertions(+), 273 deletions(-) delete mode 100644 examples/Examples.AspNetCoreHosted/Client/Startup.cs delete mode 100644 examples/Examples.ClientSide/Startup.cs delete mode 100644 src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml index 85dd99e..d2e2a24 100644 --- a/.github/workflows/blank.yml +++ b/.github/workflows/blank.yml @@ -6,7 +6,7 @@ jobs: build: container: - image: mcr.microsoft.com/dotnet/core/sdk:3.1.100-preview3-bionic + image: mcr.microsoft.com/dotnet/core/sdk:3.1.102-bionic runs-on: ubuntu-16.04 diff --git a/README.md b/README.md index a63b9eb..00fa288 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Learn more at: ### Blazor ->You'll want to follow the [Getting Started](https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started?view=aspnetcore-3.0&tabs=visual-studio) instructions in [Blazor website](https://blazor.net) +>You'll want to follow the [Getting Started](https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started?view=aspnetcore-3.1&tabs=visual-studio) instructions in [Blazor website](https://blazor.net) ### Auth0 @@ -38,60 +38,58 @@ Install via [Nuget](https://www.nuget.org/). >Server Side ```bash -Install-Package Blazor-Auth0-ServerSide -Version 2.0.0-Preview4 +Install-Package Blazor-Auth0-ServerSide -Version 2.0.0-Preview5 ```` >Client Side ```bash -Install-Package Blazor-Auth0-ClientSide -Version 2.0.0-Preview4 +Install-Package Blazor-Auth0-ClientSide -Version 2.0.0-Preview5 ```` ## Usage - **Note**: Following example is for a server-side with require authenticated user implementation, for client-side and core-hosted example implementations please refer to the [examples](https://github.com/henalbrod/Blazor.Auth0/tree/master/examples) + **Note**: Following example is for a client-side with require-authenticated-user implementation, for server-side and core-hosted example implementations please refer to the [examples](https://github.com/henalbrod/Blazor.Auth0/tree/master/examples) -> #### appsettings.json or [Secrets file](https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.0&tabs=windows#secret-manager) (recommended) -```Json -{ - "Auth0":{ - "Domain": "[Your_Auth0_Tenant_Domain]", - "ClientId": "[Your_Auth0_Client/Application_Id]", - "ClientSecret": "[Your_Auth0_Client/Application_Secret]", - "Audience": "[Your_Auth0_Audience/API_Identifier]" - } -} -``` -> #### Startup.cs +> #### Program.cs ```C# -// Import Blazor.Auth0 + using Blazor.Auth0; -using Blazor.Auth0.Models; + // ... -public void ConfigureServices(IServiceCollection services) + +public static async Task Main(string[] args) { - // Other code... + var builder = WebAssemblyHostBuilder.CreateDefault(args); - /// This one-liner will initialize Blazor.Auth0 with all the defaults - services.AddDefaultBlazorAuth0Authentication(Configuration.GetSection("Auth0").Get()); + builder.Services.AddBlazorAuth0(options => + { + // Required + options.Domain = "[Auth0_Domain]"; - // Other code... -} + // Required + options.ClientId = "[Auth0_Client_Id]"; - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - // Otrher code... + //// Required if you want to make use of Auth0's RBAC + options.Audience = "[Auth0_Audience]"; - app.UseHttpsRedirection(); - app.UseStaticFiles(); - - // Add Blazor.Auth0 middleware - app.UseBlazorAuth0(); + //// 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 two lines if you want your users to log in via a pop-up window instead of being redirected + // options.LoginMode = LoginModes.Popup; + + //// Uncomment the following line if you don't want your unauthenticated users to be automatically redirected to Auth0's Universal Login page + // options.RequireAuthenticatedUser = false; + }); + + builder.RootComponents.Add("app"); + + await builder.Build().RunAsync(); +} - // Other code... - } ``` ### @@ -153,6 +151,11 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu ## Release History +**v2.0.0-Preview5** + +* Upgraded to .Net Core v3.2.0-preview1 +* Fixed issue #41 + **v2.0.0-Preview4** * Upgraded to .Net Core v3.1.0-preview3 diff --git a/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj b/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj index a291ef6..4047307 100644 --- a/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj +++ b/examples/Examples.AspNetCoreHosted/Client/Examples.AspNetCoreHosted.Client.csproj @@ -1,17 +1,17 @@  - netstandard2.0 + netstandard2.1 Exe 7.3 3.0 - - - - + + + + @@ -22,7 +22,7 @@ - + diff --git a/examples/Examples.AspNetCoreHosted/Client/Program.cs b/examples/Examples.AspNetCoreHosted/Client/Program.cs index d8cd028..95fe217 100644 --- a/examples/Examples.AspNetCoreHosted/Client/Program.cs +++ b/examples/Examples.AspNetCoreHosted/Client/Program.cs @@ -1,16 +1,53 @@ -using Microsoft.AspNetCore.Blazor.Hosting; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Text; +using Microsoft.AspNetCore.Blazor.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Blazor.Auth0; namespace Examples.AspNetCoreHosted.Client { - public static class Program + public class Program { - public static void Main(string[] args) + public static async Task Main(string[] args) { - CreateHostBuilder(args).Build().Run(); - } + var builder = WebAssemblyHostBuilder.CreateDefault(args); + + builder.Services.AddBlazorAuth0(options => + { + // Required + options.Domain = "[Auth0_Domain]"; + + // Required + options.ClientId = "[Auth0_Client_Id]"; + + //// Required if you want to make use of Auth0's RBAC + options.Audience = "[Auth0_Audience]"; + + // PLEASE! PLEASE! PLEASE! DO NOT USE SECRETS IN CLIENT-SIDE APPS... https://medium.com/chingu/protect-application-assets-how-to-secure-your-secrets-a4165550c5fb + // options.ClientSecret = "NEVER!!"; + + //// Uncomment the following line if you don't want your users to be automatically logged-off on token expiration + // options.SlidingExpiration = true; - public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) => - BlazorWebAssemblyHost.CreateDefaultBuilder() - .UseBlazorStartup(); + //// Uncomment the following two lines if you want your users to log in via a pop-up window instead of being redirected + // options.LoginMode = LoginModes.Popup; + + //// Uncomment the following line if you don't want your unauthenticated users to be automatically redirected to Auth0's Universal Login page + // options.RequireAuthenticatedUser = false; + }); + + // Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.1 + builder.Services.AddAuthorizationCore(options => + { + options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions", "read:weather_forecast")); + options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("permissions", "execute:increment_counter")); + }); + + builder.RootComponents.Add("app"); + + await builder.Build().RunAsync(); + } } } diff --git a/examples/Examples.AspNetCoreHosted/Client/Startup.cs b/examples/Examples.AspNetCoreHosted/Client/Startup.cs deleted file mode 100644 index b5cc893..0000000 --- a/examples/Examples.AspNetCoreHosted/Client/Startup.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Blazor.Auth0; -using Microsoft.AspNetCore.Components.Builder; -using Microsoft.Extensions.DependencyInjection; - -namespace Examples.AspNetCoreHosted.Client -{ - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - services.AddBlazorAuth0(options => - { - // Required - options.Domain = "[Auth0_Domain]"; - - // Required - options.ClientId = "[Auth0_Client_Id]"; - - //// Required if you want to make use of Auth0's RBAC - options.Audience = "[Auth0_Audience]"; - - // PLEASE! PLEASE! PLEASE! DO NOT USE SECRETS IN CLIENT-SIDE APPS... https://medium.com/chingu/protect-application-assets-how-to-secure-your-secrets-a4165550c5fb - // options.ClientSecret = "NEVER!!"; - - //// Uncomment the following line if you don't want your unauthenticated users to be automatically redirected to Auth0's Universal Login page - // options.RequireAuthenticatedUser = false; - - //// 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 - services.AddAuthorizationCore(options => - { - options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions", "read:weather_forecast")); - options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("permissions", "execute:increment_counter")); - }); - } - - public void Configure(IComponentsApplicationBuilder app) - { - app.AddComponent("app"); - } - } -} diff --git a/examples/Examples.AspNetCoreHosted/Server/Examples.AspNetCoreHosted.Server.csproj b/examples/Examples.AspNetCoreHosted/Server/Examples.AspNetCoreHosted.Server.csproj index 51bf0de..e8197fe 100644 --- a/examples/Examples.AspNetCoreHosted/Server/Examples.AspNetCoreHosted.Server.csproj +++ b/examples/Examples.AspNetCoreHosted/Server/Examples.AspNetCoreHosted.Server.csproj @@ -3,13 +3,13 @@ netcoreapp3.1 7.3 - 29ffcc70-613f-459f-a62d-8cdd218eb11b + 6c2330d9-84c7-4bf5-80a9-6b48c017bbab - - - + + + diff --git a/examples/Examples.AspNetCoreHosted/Server/Startup.cs b/examples/Examples.AspNetCoreHosted/Server/Startup.cs index ae0743e..2f8a4f2 100644 --- a/examples/Examples.AspNetCoreHosted/Server/Startup.cs +++ b/examples/Examples.AspNetCoreHosted/Server/Startup.cs @@ -64,7 +64,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseAuthentication(); app.UseStaticFiles(); - app.UseClientSideBlazorFiles(); + app.UseClientSideBlazorFiles(); app.UseRouting(); @@ -73,7 +73,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); - endpoints.MapFallbackToClientSideBlazor("index.html"); + endpoints.MapFallbackToClientSideBlazor("index.html"); }); } } diff --git a/examples/Examples.AspNetCoreHosted/Shared/Examples.AspNetCoreHosted.Shared.csproj b/examples/Examples.AspNetCoreHosted/Shared/Examples.AspNetCoreHosted.Shared.csproj index 2a77f0c..9f5c4f4 100644 --- a/examples/Examples.AspNetCoreHosted/Shared/Examples.AspNetCoreHosted.Shared.csproj +++ b/examples/Examples.AspNetCoreHosted/Shared/Examples.AspNetCoreHosted.Shared.csproj @@ -2,7 +2,6 @@ netstandard2.0 - 7.3 diff --git a/examples/Examples.ClientSide/Examples.ClientSide.csproj b/examples/Examples.ClientSide/Examples.ClientSide.csproj index 7f20686..ef3f620 100644 --- a/examples/Examples.ClientSide/Examples.ClientSide.csproj +++ b/examples/Examples.ClientSide/Examples.ClientSide.csproj @@ -1,17 +1,17 @@  - netstandard2.0 + netstandard2.1 Exe 7.3 3.0 - - - - + + + + @@ -22,7 +22,7 @@ - + diff --git a/examples/Examples.ClientSide/Program.cs b/examples/Examples.ClientSide/Program.cs index 660fa67..b9ac771 100644 --- a/examples/Examples.ClientSide/Program.cs +++ b/examples/Examples.ClientSide/Program.cs @@ -1,18 +1,56 @@ -using Microsoft.AspNetCore.Blazor.Hosting; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Text; +using Microsoft.AspNetCore.Blazor.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Blazor.Auth0; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Builder; namespace Examples.ClientSide { - public static class Program + public class Program { - public static void Main(string[] args) + public static async Task Main(string[] args) { - CreateHostBuilder(args).Build().Run(); - } - public static IWebAssemblyHostBuilder CreateHostBuilder(string[] _args) - { - return BlazorWebAssemblyHost.CreateDefaultBuilder() - .UseBlazorStartup(); + var builder = WebAssemblyHostBuilder.CreateDefault(args); + + builder.Services.AddBlazorAuth0(options => + { + // Required + options.Domain = "[Auth0_Domain]"; + + // Required + options.ClientId = "[Auth0_Client_Id]"; + + //// Required if you want to make use of Auth0's RBAC + options.Audience = "[Auth0_Audience]"; + + // PLEASE! PLEASE! PLEASE! DO NOT USE SECRETS IN CLIENT-SIDE APPS... https://medium.com/chingu/protect-application-assets-how-to-secure-your-secrets-a4165550c5fb + // options.ClientSecret = "NEVER!!"; + + //// 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 two lines if you want your users to log in via a pop-up window instead of being redirected + // options.LoginMode = LoginModes.Popup; + + //// Uncomment the following line if you don't want your unauthenticated users to be automatically redirected to Auth0's Universal Login page + // options.RequireAuthenticatedUser = false; + }); + + // Policy based authorization, learn more here: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.1 + builder.Services.AddAuthorizationCore(options => + { + options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions", "read:weather_forecast")); + options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("permissions", "execute:increment_counter")); + }); + + builder.RootComponents.Add("app"); + + await builder.Build().RunAsync(); } } } diff --git a/examples/Examples.ClientSide/Startup.cs b/examples/Examples.ClientSide/Startup.cs deleted file mode 100644 index 37bd414..0000000 --- a/examples/Examples.ClientSide/Startup.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Blazor.Auth0; -using Blazor.Auth0.Models.Enumerations; -using Microsoft.AspNetCore.Components.Builder; -using Microsoft.Extensions.DependencyInjection; - -namespace Examples.ClientSide -{ - public class Startup - { - - public void ConfigureServices(IServiceCollection services) - { - services.AddBlazorAuth0(options => - { - // Required - options.Domain = "[Auth0_Domain]"; - - // Required - options.ClientId = "[Auth0_Client_Id]"; - - //// Required if you want to make use of Auth0's RBAC - options.Audience = "[Auth0_Audience]"; - - // PLEASE! PLEASE! PLEASE! DO NOT USE SECRETS IN CLIENT-SIDE APPS... https://medium.com/chingu/protect-application-assets-how-to-secure-your-secrets-a4165550c5fb - // options.ClientSecret = "NEVER!!"; - - //// Uncomment the following line if you don't want your unauthenticated users to be automatically redirected to Auth0's Universal Login page - // options.RequireAuthenticatedUser = false; - - //// 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 - services.AddAuthorizationCore(options => - { - options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("permissions", "read:weather_forecast")); - options.AddPolicy("execute:increment_counter", policy => policy.RequireClaim("permissions", "execute:increment_counter")); - }); - - } - - public void Configure(IComponentsApplicationBuilder app) - { - app.AddComponent("app"); - } - } -} diff --git a/examples/Examples.ClientSide/wwwroot/index.html b/examples/Examples.ClientSide/wwwroot/index.html index 828ff1e..6c410d6 100644 --- a/examples/Examples.ClientSide/wwwroot/index.html +++ b/examples/Examples.ClientSide/wwwroot/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/Examples.ServerSide/Examples.ServerSide.csproj b/examples/Examples.ServerSide/Examples.ServerSide.csproj index 5c17318..ca67a5e 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/AuthenticationService.cs b/src/Blazor.Auth0.ClientSide/AuthenticationService.cs index 9e53674..3273673 100644 --- a/src/Blazor.Auth0.ClientSide/AuthenticationService.cs +++ b/src/Blazor.Auth0.ClientSide/AuthenticationService.cs @@ -88,7 +88,12 @@ public AuthenticationService(ILogger logger, HttpClient h this.dotnetObjectRef = DotNetObjectReference.Create(this); - Task.Run(async () => await this.ValidateSession().ConfigureAwait(false)); + Task.Run(async () => + { + // Ugly but necesary :\ + await this.jsRuntime.InvokeVoidAsync("window.eval", Resources.ClientSideJs); + await this.ValidateSession().ConfigureAwait(false); + }); } /// diff --git a/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj b/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj index a5fbcfd..645ab86 100644 --- a/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj +++ b/src/Blazor.Auth0.ClientSide/Blazor.Auth0.ClientSide.csproj @@ -1,10 +1,10 @@  - netstandard2.0 + netstandard2.1 3.0 8.0 - 2.0.0-Preview4 + 2.0.0-Preview5 Henry Alberto Rodriguez Rodriguez Auth0 library for Balzor https://github.com/henalbrod/Blazor.Auth0 @@ -16,32 +16,29 @@ true https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png Blazor-Auth0-ClientSide - Upgraded to .Net Core v3.1.0-preview3 + + Upgraded to .Net Core v3.2.0-preview1 + Fixed issue #41 + true ..\..\packages - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - @@ -59,11 +56,11 @@ - + - + True @@ -79,5 +76,4 @@ - diff --git a/src/Blazor.Auth0.ClientSide/Properties/Resources.Designer.cs b/src/Blazor.Auth0.ClientSide/Properties/Resources.Designer.cs index 6e9be2e..5d26305 100644 --- a/src/Blazor.Auth0.ClientSide/Properties/Resources.Designer.cs +++ b/src/Blazor.Auth0.ClientSide/Properties/Resources.Designer.cs @@ -69,6 +69,30 @@ internal static string ApplicationJsonMediaType { } } + /// + /// Looks up a localized string similar to "use strict"; + /// + ///if (window.opener && window.name === "auth0_signup_popup") { + /// window.opener.___blazor_auth0.popupCallback(window.location.href); + /// close(); + ///}else{ + /// window.___blazor_auth0 = { + /// logOut: (src) => { + /// "use strict"; + /// return new Promise((resolve) => { + /// let iframe = document.createElement("iframe"); + /// iframe.setAttribute("src", src); + /// iframe.style.display = "none"; + /// document.body.appendChild(iframe); + /// iframe.onload = () => { + /// document.body.re [rest of string was truncated]";. + /// + internal static string ClientSideJs { + get { + return ResourceManager.GetString("ClientSideJs", resourceCulture); + } + } + /// /// Looks up a localized string similar to You must indicate either the SECRET when using Authorization Code or the CODE_VERIFIER when using Authorization Code with PKCE, you're providing both.. /// diff --git a/src/Blazor.Auth0.ClientSide/Properties/Resources.resx b/src/Blazor.Auth0.ClientSide/Properties/Resources.resx index f7ab264..434c9b5 100644 --- a/src/Blazor.Auth0.ClientSide/Properties/Resources.resx +++ b/src/Blazor.Auth0.ClientSide/Properties/Resources.resx @@ -120,6 +120,76 @@ application/json + + "use strict"; + +if (window.opener && window.name === "auth0_signup_popup") { + window.opener.___blazor_auth0.popupCallback(window.location.href); + close(); +}else{ + window.___blazor_auth0 = { + logOut: (src) => { + "use strict"; + return new Promise((resolve) => { + let iframe = document.createElement("iframe"); + iframe.setAttribute("src", src); + iframe.style.display = "none"; + document.body.appendChild(iframe); + iframe.onload = () => { + document.body.removeChild(iframe); + resolve(); + }; + }); + }, + drawIframe: (instance, src) => { + "use strict"; + let iframe = document.createElement("iframe"); + iframe.setAttribute("src", src); + iframe.style.display = "none"; + document.body.appendChild(iframe); + var messageListener = (msg) => { + if (msg.data.type === "authorization_response") { + window.removeEventListener("message", messageListener); + instance.invokeMethodAsync("HandleAuthorizationResponseAsync", { + isTrusted: msg.isTrusted, + origin: msg.origin, + type: msg.data.type, + state: msg.data.response.state, + error: msg.data.response.error, + errorDescription: msg.data.response.error_description, + // Code Grant (Recommended) + code: msg.data.response.code, + // Implicit Grant (Legacy) + accessToken: msg.data.response.access_token, + idToken: msg.data.response.id_token, + scope: msg.data.response.scope, + tokenType: msg.data.response.token_type, + expiresIn: msg.data.response.expires_in + }).then((r) => { document.body.removeChild(iframe); }); + } + }; + 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(); + + } + }; +} + You must indicate either the SECRET when using Authorization Code or the CODE_VERIFIER when using Authorization Code with PKCE, you're providing both. diff --git a/src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js b/src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js deleted file mode 100644 index b039aed..0000000 --- a/src/Blazor.Auth0.ClientSide/wwwroot/blazor-auth0-clientside.js +++ /dev/null @@ -1,68 +0,0 @@ -"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"; - return new Promise((resolve) => { - let iframe = document.createElement("iframe"); - iframe.setAttribute("src", src); - iframe.style.display = "none"; - document.body.appendChild(iframe); - iframe.onload = () => { - document.body.removeChild(iframe); - resolve(); - }; - }); - }, - drawIframe: (instance, src) => { - "use strict"; - let iframe = document.createElement("iframe"); - iframe.setAttribute("src", src); - iframe.style.display = "none"; - document.body.appendChild(iframe); - var messageListener = (msg) => { - if (msg.data.type === "authorization_response") { - window.removeEventListener("message", messageListener); - instance.invokeMethodAsync("HandleAuthorizationResponseAsync", { - isTrusted: msg.isTrusted, - origin: msg.origin, - type: msg.data.type, - state: msg.data.response.state, - error: msg.data.response.error, - errorDescription: msg.data.response.error_description, - // Code Grant (Recommended) - code: msg.data.response.code, - // Implicit Grant (Legacy) - accessToken: msg.data.response.access_token, - idToken: msg.data.response.id_token, - scope: msg.data.response.scope, - tokenType: msg.data.response.token_type, - expiresIn: msg.data.response.expires_in - }).then((r) => { document.body.removeChild(iframe); }); - } - }; - 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 6d9d4a6..58fd0a1 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-Preview4 + 2.0.0-Preview5 Henry Alberto Rodriguez Rodriguez Auth0 library for Balzor https://github.com/henalbrod/Blazor.Auth0 @@ -15,7 +15,7 @@ true https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png Blazor-Auth0-ServerSide - Upgraded to .Net Core v3.1.0-preview3 + Upgraded to .Net Core v3.2.0-preview1 true ..\..\packages @@ -36,19 +36,19 @@ - + - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj b/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj index 78a0ca8..c08835e 100644 --- a/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj +++ b/src/Blazor.Auth0.Shared/Blazor.Auth0.Shared.csproj @@ -1,9 +1,9 @@  - netstandard2.0 + netstandard2.1 8.0 - 2.0.0-Preview4 + 2.0.0-Preview5 Henry Alberto Rodriguez Rodriguez Auth0 library for Balzor https://github.com/henalbrod/Blazor.Auth0 @@ -15,7 +15,7 @@ true https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png Blazor-Auth0-Shared - Upgraded to .Net Core v3.1.0-preview3 + Upgraded to .Net Core v3.2.0-preview1 true ..\..\packages @@ -29,15 +29,15 @@ - - - + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Blazor.Auth0.sln b/src/Blazor.Auth0.sln index f325313..c820a6d 100644 --- a/src/Blazor.Auth0.sln +++ b/src/Blazor.Auth0.sln @@ -6,20 +6,35 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Auth0.Shared", "Blazor.Auth0.Shared\Blazor.Auth0.Shared.csproj", "{20F66828-6565-489D-B197-E8251B200737}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Auth0.ClientSide", "Blazor.Auth0.ClientSide\Blazor.Auth0.ClientSide.csproj", "{A8C1B957-C46E-4936-B470-0E6D03CD0EFB}" + ProjectSection(ProjectDependencies) = postProject + {20F66828-6565-489D-B197-E8251B200737} = {20F66828-6565-489D-B197-E8251B200737} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Auth0.ServerSide", "Blazor.Auth0.ServerSide\Blazor.Auth0.ServerSide.csproj", "{CE138C35-6B00-4BE4-A172-F4E641070348}" + ProjectSection(ProjectDependencies) = postProject + {20F66828-6565-489D-B197-E8251B200737} = {20F66828-6565-489D-B197-E8251B200737} + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{30AEBE64-A293-424D-A26A-ADCDAAAF7391}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.ClientSide", "..\examples\Examples.ClientSide\Examples.ClientSide.csproj", "{7C0D133F-DCB3-4C3B-B13F-D20BF9D97DA2}" + ProjectSection(ProjectDependencies) = postProject + {A8C1B957-C46E-4936-B470-0E6D03CD0EFB} = {A8C1B957-C46E-4936-B470-0E6D03CD0EFB} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.ServerSide", "..\examples\Examples.ServerSide\Examples.ServerSide.csproj", "{041EF1E4-B4E2-4A44-884E-144F2FE6F566}" + ProjectSection(ProjectDependencies) = postProject + {CE138C35-6B00-4BE4-A172-F4E641070348} = {CE138C35-6B00-4BE4-A172-F4E641070348} + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ASP.Net Core Hosted", "ASP.Net Core Hosted", "{7AC81899-F4AF-4B85-8B8F-BE6E3BD2E4AE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.AspNetCoreHosted.Shared", "..\examples\Examples.AspNetCoreHosted\Shared\Examples.AspNetCoreHosted.Shared.csproj", "{C0690880-66EB-49CE-99BA-6A5099B85306}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.AspNetCoreHosted.Client", "..\examples\Examples.AspNetCoreHosted\Client\Examples.AspNetCoreHosted.Client.csproj", "{3242EA63-B755-485B-9ECB-C873B5F7DDE7}" + ProjectSection(ProjectDependencies) = postProject + {A8C1B957-C46E-4936-B470-0E6D03CD0EFB} = {A8C1B957-C46E-4936-B470-0E6D03CD0EFB} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.AspNetCoreHosted.Server", "..\examples\Examples.AspNetCoreHosted\Server\Examples.AspNetCoreHosted.Server.csproj", "{50045E62-8938-4C58-AC2A-7C7946A67E0B}" EndProject