<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Henry Alberto Rodriguez</title>
    <description>The latest articles on DEV Community by Henry Alberto Rodriguez (@henalbrod).</description>
    <link>https://dev.to/henalbrod</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F213052%2F8d1e4b67-156d-452b-8aba-9fe09204bad1.jpeg</url>
      <title>DEV Community: Henry Alberto Rodriguez</title>
      <link>https://dev.to/henalbrod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/henalbrod"/>
    <language>en</language>
    <item>
      <title>Blazor-Auth0 v2.0.0-Preview4 is alive!</title>
      <dc:creator>Henry Alberto Rodriguez</dc:creator>
      <pubDate>Sun, 17 Nov 2019 22:28:39 +0000</pubDate>
      <link>https://dev.to/henalbrod/blazor-auth0-v2-0-0-preview4-is-alive-efb</link>
      <guid>https://dev.to/henalbrod/blazor-auth0-v2-0-0-preview4-is-alive-efb</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f0h9mrKy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f0h9mrKy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/henalbrod/Blazor.Auth0/master/src/Blazor.Auth0.ClientSide/icon.png" height="150" alt="Blazor Auth0 Library"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/henalbrod/Blazor.Auth0"&gt;Blazor.Auth0&lt;/a&gt; Is a library for using the &lt;a href="https://auth0.com/blog/oauth2-implicit-grant-and-spa/"&gt;Authorization Code Grant with Proof Key for Code Exchange (PKCE)&lt;/a&gt; with &lt;a href="https://auth0.com/docs/libraries/when-to-use-lock"&gt;Auth0's Universal Login&lt;/a&gt; in Blazor SPAs.&lt;/p&gt;

&lt;p&gt;The idea behind this is to have an easy way of using Auth0's services with Blazor (especially the client-side) without relying on javascript libraries.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/henalbrod/Blazor.Auth0"&gt;https://github.com/henalbrod/Blazor.Auth0&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blazor</category>
      <category>auth0</category>
      <category>dotnet</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Securing your Blazor App with Auth0 (client side)</title>
      <dc:creator>Henry Alberto Rodriguez</dc:creator>
      <pubDate>Wed, 06 Nov 2019 02:58:33 +0000</pubDate>
      <link>https://dev.to/henalbrod/securing-your-blazor-app-with-auth0-client-side-2c6</link>
      <guid>https://dev.to/henalbrod/securing-your-blazor-app-with-auth0-client-side-2c6</guid>
      <description>&lt;p&gt;Deal with it, security is difficult and it can be the most complex piece in our applications. Because of this, many of us tend to leave it for last, if we ever implement it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JWT&lt;/li&gt;
&lt;li&gt;Cookies&lt;/li&gt;
&lt;li&gt;IdP&lt;/li&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;Authorization&lt;/li&gt;
&lt;li&gt;Password reset&lt;/li&gt;
&lt;li&gt;Email confirmation&lt;/li&gt;
&lt;li&gt;Etc... &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can be too much to do it by ourselves.&lt;/p&gt;

&lt;p&gt;So, why don't leave it to someone who knows about that complex world and can bring us a complete authentication and authorization platform?&lt;/p&gt;

&lt;p&gt;That would make our lives less difficult.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enters Auth0
&lt;/h2&gt;

&lt;p&gt;As per &lt;a href="https://auth0.com/"&gt;Auth0 site&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Auth0 provides a universal authentication &amp;amp; authorization platform for web, mobile, and legacy applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Auth0 will take care of all the complex duties and you only need to take care of the integration.&lt;/p&gt;

&lt;p&gt;Better of, a library already exists that facilitates its integration with Blazor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Blazor.Auth0
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: Author here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/henalbrod/Blazor.Auth0"&gt;Blazor.Auth0&lt;/a&gt; Is a library for using the &lt;a href="https://auth0.com/blog/oauth2-implicit-grant-and-spa/"&gt;Authorization Code Grant with Proof Key for Code Exchange (PKCE)&lt;/a&gt; with &lt;a href="https://auth0.com/docs/libraries/when-to-use-lock"&gt;Auth0's Universal Login&lt;/a&gt; in Blazor SPAs.&lt;/p&gt;

&lt;p&gt;The idea behind this is to have an easy way of using Auth0's services with Blazor (especially the client-side) without relying on javascript libraries.&lt;/p&gt;




&lt;h1&gt;
  
  
  Blazor Requirements
&lt;/h1&gt;

&lt;p&gt;Blazor is evolving rapidly, especially on the client-side, so you will need to fulfill some requirements before starting to work, the best place to find the latest steps for preparation will always be the &lt;a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started?view=aspnetcore-3.1&amp;amp;tabs=visual-studio"&gt;official Blazor website&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Visual Studio 2019 16.4 Preview 2 or later is a must for working with Client-Side applications (at the time of writing this).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wm4vS2zw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a5ho005i95lo3l53f412.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wm4vS2zw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/a5ho005i95lo3l53f412.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Creating the Blazor Client-Side App
&lt;/h1&gt;

&lt;p&gt;If you are in the command line, you should use the &lt;strong&gt;.Net Core CLI&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;dotnet new blazorwasm &lt;span class="nt"&gt;-o&lt;/span&gt; your_awesome_app_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you are using VS 2019, please select &lt;strong&gt;Create a new project&lt;/strong&gt;, look for &lt;strong&gt;Blazor App&lt;/strong&gt;, give a cool name to your project and click on create.&lt;/p&gt;

&lt;p&gt;Be sure to select the correct project template, in this case, we'll be working on a Client-Side application, so you need to select &lt;strong&gt;Blazor Webassembly App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HaZoeWQo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/azqo2ajmqh35w8c90rpz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HaZoeWQo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/azqo2ajmqh35w8c90rpz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Configuring the Blazor Client-Side App
&lt;/h1&gt;

&lt;p&gt;First, you'll want to enable the SSL support, it can be activated by checking the &lt;strong&gt;Enable SSL&lt;/strong&gt; checkbox in the application's properties page.&lt;/p&gt;

&lt;p&gt;Please take note of the generated SSL URL as you'll need it when configuring Auth0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n9cnXL0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/j197ycyfyp8pdg5rvqpa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n9cnXL0d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/j197ycyfyp8pdg5rvqpa.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now install the &lt;strong&gt;Blazor.Auth0&lt;/strong&gt; library via the NuGet Package console by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;Install-Package Blazor-Auth0-ClientSide &lt;span class="nt"&gt;-Version&lt;/span&gt; 2.0.0-Preview2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Another option is opening the &lt;strong&gt;Nuget Package Manager&lt;/strong&gt;, look for Blazor-Auth0-ClientSide and click in install.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ImkTZWJo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9xnqhxzffyglqb4gu2f7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ImkTZWJo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9xnqhxzffyglqb4gu2f7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once &lt;strong&gt;Blazor.Auth0&lt;/strong&gt; is installed, you need to register the AuthenticationService via Dependency Injection, to do it, edit the &lt;code&gt;Startup.cs&lt;/code&gt; file as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Blazor.Auth0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.AspNetCore.Components.Builder&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Microsoft.Extensions.DependencyInjection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Examples.ClientSide&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Startup&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;ConfigureServices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddBlazorAuth0&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;                   
                    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Domain&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"[Auth0_Domain]"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ClientId&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"[Auth0_Client_Id]"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RequireAuthenticatedUser&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;});&lt;/span&gt;
                &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddAuthorizationCore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

            &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IComponentsApplicationBuilder&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddComponent&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;App&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;services.AddBlazorAuth0&lt;/code&gt; is a helper method that will register the required &lt;code&gt;ClientOptions&lt;/code&gt; settings, &lt;code&gt;AuthenticationService&lt;/code&gt;, and &lt;code&gt;AuthenticationStateProvider&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;An optional but recommended step is to add the following import statements in &lt;code&gt;_Imports.razor&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="n"&gt;@using&lt;/span&gt; &lt;span class="n"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AspNetCore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Authorization&lt;/span&gt;
    &lt;span class="n"&gt;@using&lt;/span&gt; &lt;span class="n"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AspNetCore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Components&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Authorization&lt;/span&gt;

    &lt;span class="n"&gt;@using&lt;/span&gt; &lt;span class="n"&gt;Blazor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Auth0&lt;/span&gt;
    &lt;span class="n"&gt;@using&lt;/span&gt; &lt;span class="n"&gt;Blazor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Auth0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Models&lt;/span&gt;
    &lt;span class="n"&gt;@using&lt;/span&gt; &lt;span class="n"&gt;Blazor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Auth0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Enumerations&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will expose these namespaces globally in our Blazor App&lt;/p&gt;

&lt;p&gt;Replace the content of &lt;code&gt;App.razor&lt;/code&gt; with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;    &lt;span class="nt"&gt;&amp;lt;Router&lt;/span&gt; &lt;span class="na"&gt;AppAssembly=&lt;/span&gt;&lt;span class="s"&gt;"@typeof(Program).Assembly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;Found&lt;/span&gt; &lt;span class="na"&gt;Context=&lt;/span&gt;&lt;span class="s"&gt;"routeData"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;AuthorizeRouteView&lt;/span&gt; &lt;span class="na"&gt;RouteData=&lt;/span&gt;&lt;span class="s"&gt;"@routeData"&lt;/span&gt; &lt;span class="na"&gt;DefaultLayout=&lt;/span&gt;&lt;span class="s"&gt;"@typeof(MainLayout)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;Authorizing&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&amp;gt;Determining session state, please wait...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/Authorizing&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;NotAuthorized&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Sorry&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;You're not authorized to reach this page. You may need to log in as a different user.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/NotAuthorized&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/AuthorizeRouteView&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/Found&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;NotFound&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Sorry, there's nothing at this address.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/NotFound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/Router&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That way you'll display the appropriate content depending on the current authentication state.&lt;/p&gt;

&lt;p&gt;More important is, the &lt;code&gt;AuthorizeRouteView&lt;/code&gt; component will Set up the &lt;br&gt;
&lt;code&gt;Task &amp;lt;AuthenticationState&amp;gt;&lt;/code&gt; cascading parameter.&lt;/p&gt;

&lt;p&gt;Replace the content of &lt;code&gt;MainLayout.razor&lt;/code&gt; with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;    @inherits LayoutComponentBase
    @inject Blazor.Auth0.IAuthenticationService authService

    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sidebar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;NavMenu&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"top-row px-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;AuthorizeView&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;Authorized&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;NavLink&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-link"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"authService.LogOut"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"oi oi-account-logout"&lt;/span&gt; &lt;span class="na"&gt;aria-hidden=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt; Logout
                    &lt;span class="nt"&gt;&amp;lt;/NavLink&amp;gt;&lt;/span&gt;

                &lt;span class="nt"&gt;&amp;lt;/Authorized&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;NotAuthorized&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;NavLink&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav-link"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"authService.Authorize"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"oi oi-account-login"&lt;/span&gt; &lt;span class="na"&gt;aria-hidden=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;  Login
                    &lt;span class="nt"&gt;&amp;lt;/NavLink&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/NotAuthorized&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/AuthorizeView&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"http://blazor.net"&lt;/span&gt; &lt;span class="na"&gt;target=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ml-md-auto"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content px-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            @Body
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will display a Login/Logout button in the top-bar for the users to start or finish their sessions.&lt;/p&gt;

&lt;p&gt;The last view you'll need to edit is the &lt;code&gt;Index.razor&lt;/code&gt;, replace its content with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;    @page "/"

    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;
        Hello,
        &lt;span class="nt"&gt;&amp;lt;AuthorizeView&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;Authorized&amp;gt;&lt;/span&gt;@context.User.Identity.Name&lt;span class="nt"&gt;&amp;lt;/Authorized&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;NotAuthorized&amp;gt;&lt;/span&gt;World&lt;span class="nt"&gt;&amp;lt;/NotAuthorized&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/AuthorizeView&amp;gt;&lt;/span&gt;
        !
    &lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

    Welcome to your new app.

    &lt;span class="nt"&gt;&amp;lt;SurveyPrompt&lt;/span&gt; &lt;span class="na"&gt;Title=&lt;/span&gt;&lt;span class="s"&gt;"How is Blazor working for you?"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;AuthorizeView&amp;gt;&lt;/code&gt; component will detect the authentication state of the user and will display &lt;em&gt;Hello, World&lt;/em&gt; in case there's no active user or &lt;em&gt;Hello, [Name of the user&lt;/em&gt;] when a user is authenticated.&lt;/p&gt;




&lt;h1&gt;
  
  
  Configuring Auth0
&lt;/h1&gt;

&lt;p&gt;If you don't have an Auth0 account already, please create one by navigating to &lt;a href="https://auth0.com/"&gt;Auth0's home page&lt;/a&gt;, hitting the Sign-Up button and following thru the account creation wizard, at the end of the process you'll end up in the dashboard.&lt;/p&gt;

&lt;p&gt;Once there, select &lt;strong&gt;Applications&lt;/strong&gt; then &lt;strong&gt;Default App&lt;/strong&gt; to load the application settings page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ks4Mn6S---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5516nf574o2lmqehvbzb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ks4Mn6S---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5516nf574o2lmqehvbzb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, look for the &lt;strong&gt;Domain&lt;/strong&gt; and &lt;strong&gt;Client ID&lt;/strong&gt; fields, and take note of them as you'll need them in the final step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XLPJzVfN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8uu8arlz5lcaqh9o7isw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XLPJzVfN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8uu8arlz5lcaqh9o7isw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next look for the &lt;strong&gt;Application Type&lt;/strong&gt; field, expand it to see the different client application types supported by Auth0. Select &lt;strong&gt;Single Page Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HTe6NjLH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mav4jsel8vpsm53x49pz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HTe6NjLH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mav4jsel8vpsm53x49pz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To finish with the Auth0 configuration you need to indicate the Blazor App SSL URL as one of the valid paths for Auth0 to allow the users to authenticate.&lt;/p&gt;

&lt;p&gt;To do it, look for the following fields and add the application SSL URL to them. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allowed Callback URLs&lt;/strong&gt;: &lt;br&gt;
To which URLs the user can be redirected to after login in&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allowed Web Origins&lt;/strong&gt;:&lt;br&gt;
Which URLs are allowed to perform Silent Login&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allowed Logout URLs&lt;/strong&gt;:&lt;br&gt;
To which URLs the user can be redirected to after logging off&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Allowed Origins (CORS)&lt;/strong&gt;:&lt;br&gt;
Which URLs are allowed to perform POST request to the Auth0 API&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The SSL URL is the one obtained after activating the SSL checkbox in the Blazor application options page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The final result should look similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bt5pQIGH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/p66a6twrblder9pn0he5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bt5pQIGH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/p66a6twrblder9pn0he5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With that we finished configuring our Auth0 account, now we need to go back to our code to give the last touch.&lt;/p&gt;




&lt;h1&gt;
  
  
  Back to Blazor
&lt;/h1&gt;

&lt;p&gt;Go back to the Blazor application one last time and replace the &lt;code&gt;[Auth0_Domain]&lt;/code&gt; and &lt;code&gt;[Auth0_Client_Id]&lt;/code&gt; values in &lt;code&gt;Startup.cs&lt;/code&gt; with the values that you've just got from Auth0's Application Settings page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Domain&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"[Auth0_Domain]"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ClientId&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"[Auth0_Client_Id]"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Press F5 and enjoy!
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you've completed the integration of a fully-fledged IDaaS platform into your Brand-new Blazor App, but this is just the beginning, you can take you Application Security to the next level, by implementing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RBAC (Role-Based Access Control)&lt;/li&gt;
&lt;li&gt;Claims Base Authorization&lt;/li&gt;
&lt;li&gt;SSO&lt;/li&gt;
&lt;li&gt;Social Connections&lt;/li&gt;
&lt;li&gt;Lots more!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you've found this publication interesting, useful or learned something new from it.&lt;/p&gt;

&lt;p&gt;Two more publications are in the works for covering Server Side and ASP.Net Core Hosted Scenarios, also, a more in-depth sight to the Blazor.Auth0 library internals and capabilities.&lt;/p&gt;

&lt;p&gt;All comments are welcome, thanks for reading!&lt;/p&gt;

</description>
      <category>blazor</category>
      <category>auth0</category>
      <category>csharp</category>
      <category>auth</category>
    </item>
  </channel>
</rss>
