<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://shazwazza.com/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Shazwazza</title>
    <link>https://shazwazza.com/</link>
    <description>My blog which is pretty much just all about coding</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <image>
      <url>/media/0libq25y/frog.png?rmode=max&amp;v=1da0e911f4e6890</url>
      <title>Shazwazza</title>
      <link>https://shazwazza.com/</link>
    </image>
    <item>
      <guid isPermaLink="false">1213</guid>
      <link>https://shazwazza.com/post/configuring-azure-active-directory-login-with-umbraco-members/</link>
      <category>ASP.Net</category>
      <category>Web Development</category>
      <category>Umbraco</category>
      <title>Configuring Azure Active Directory login with Umbraco Members</title>
      <description>&lt;p&gt;This post is about configuring Azure Active Directory with Umbraco &lt;u&gt;Members&lt;/u&gt; (not &lt;em&gt;Users&lt;/em&gt;), meaning this is for your front-end website, not the Umbraco back office. I did write up a post about Azure AD with back office users though, so if that is what you are looking for then &lt;a href="https://shazwazza.com/post/configuring-azure-active-directory-login-with-umbraco/" target="_blank"&gt;this is the link&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;Install the Nuget packages&lt;/h2&gt;&lt;p&gt;First thing to do is get the &lt;a href="https://www.nuget.org/packages/UmbracoIdentity" target="_blank"&gt;UmbracoIdentity&lt;/a&gt; package installed. &lt;/p&gt;

&lt;div style="width: 100%;"&gt;
&lt;div style="padding: 10px; color: rgb(255, 255, 255); line-height: 1.5; font-family: consolas, menlo, monaco,&amp;quot;Courier New&amp;quot;, monospace; background-color: rgb(0, 36, 64);"&gt;PM &amp;gt; Install-Package UmbracoIdentity&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;em&gt;(This will also install the UmbracoIdentity.Core base package)&lt;/em&gt;&lt;/p&gt;&lt;p&gt;This package installs some code snippets and updates your web.config to enable ASP.Net Identity for Umbraco members. Umbraco ships with the old and deprecated ASP.Net Membership Providers for members and not ASP.Net Identity so this package extends the Umbraco CMS and the Umbraco members implementation to use ASP.Net Identity APIs to interact with the built in members data store. Installing this package will remove the (deprecated) FormsAuthentication module from your web.config and it will no longer be used to authenticate members, so the typical members snippets built into Umbraco macros will not work. Instead use the supplied snippets shipped with this package.&lt;/p&gt;&lt;p&gt;To read more about this package see the &lt;a href="https://github.com/Shazwazza/UmbracoIdentity" target="_blank"&gt;GitHub repo here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next, the OpenIdConnect package needs to be installed&lt;/p&gt;

&lt;div style="width: 100%;"&gt;
&lt;div style="padding: 10px; color: rgb(255, 255, 255); line-height: 1.5; font-family: consolas, menlo, monaco,&amp;quot;Courier New&amp;quot;, monospace; background-color: rgb(0, 36, 64);"&gt;PM &amp;gt; Install-Package Microsoft.Owin.Security.OpenIdConnect&lt;/div&gt;
&lt;/div&gt;

&lt;h2&gt;Configure Azure Active Directory&lt;/h2&gt;&lt;p&gt;Head over to the &lt;em&gt;Azure Active Directory &lt;/em&gt;section on the Azure portal, choose &lt;em&gt;App Registrations &lt;/em&gt;(I’m using the Preview functionality for this) and create a &lt;em&gt;New registration&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_4.png"&gt;&lt;img width="802" height="362" title="image" style="display: inline; background-image: none;" alt="image" src="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Next fill out the app details&lt;/h3&gt;&lt;p&gt;&lt;a href="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_22.png"&gt;&lt;img width="802" height="805" title="image" style="display: inline; background-image: none;" alt="image" src="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_thumb_10.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;You may also need to enter other redirect URLs depending on how many different environments you have. All of these URLs can be added in the Authentication section of your app in the Azure portal.&lt;/p&gt;&lt;p&gt;For AAD configuration for front-end members, the redirect Urls are just your website’s root URL and it is advised to keep the trailing slash. &lt;/p&gt;&lt;h3&gt;Next you will need to enable Id Tokens&lt;/h3&gt;&lt;p&gt;&lt;a href="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_12.png"&gt;&lt;img width="802" height="559" title="image" style="display: inline; background-image: none;" alt="image" src="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_thumb_5.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Configure OpenIdConnect&lt;/h2&gt;&lt;p&gt;The UmbracoIdentity package will have installed an OWIN startup class in &lt;em&gt;~/App_Start/UmbracoIdentityStartup.cs &lt;/em&gt;(or it could be in App_Code if you are using a website project)&lt;em&gt;. &lt;/em&gt;This is how ASP.Net Identity is configured for front-end members and where you can specify the configuration for different OAuth providers. There’s a few things you’ll need to do:&lt;/p&gt;&lt;h3&gt;Allow external sign in cookies&lt;/h3&gt;&lt;p&gt;If you scroll down to the &lt;em&gt;ConfigureMiddleware &lt;/em&gt;method, there will be a link of code to uncomment: &lt;em&gt;app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); &lt;/em&gt;this is required for any OAuth providers to work.&lt;/p&gt;&lt;h3&gt;Enable OpenIdConnect OAuth for AAD&lt;/h3&gt;&lt;p&gt;You’ll need to add this extension method class to your code which is some boiler plate code to configure OpenIdConnect with AAD:&lt;/p&gt;

&lt;pre class="lang-csharp"&gt;&lt;code&gt;public static class UmbracoADAuthExtensions
{
    public static void ConfigureAzureActiveDirectoryAuth(this IAppBuilder app,
        string tenant, string clientId, string postLoginRedirectUri, Guid issuerId,
        string caption = "Active Directory")
    {
        var authority = string.Format(
            System.Globalization.CultureInfo.InvariantCulture,
            "https://login.windows.net/{0}",
            tenant);

        var adOptions = new OpenIdConnectAuthenticationOptions
        {
            ClientId = clientId,
            Authority = authority,
            RedirectUri = postLoginRedirectUri
        };

        adOptions.Caption = caption;
        //Need to set the auth type as the issuer path
        adOptions.AuthenticationType = string.Format(
            System.Globalization.CultureInfo.InvariantCulture,
            "https://sts.windows.net/{0}/",
            issuerId);
        app.UseOpenIdConnectAuthentication(adOptions);
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next you’ll need to call this code, add the following line underneath the &lt;em&gt;app.UseExternalSignInCookie&lt;/em&gt; method call: &lt;/p&gt;

&lt;pre class="lang-csharp"&gt;&lt;code&gt;app.ConfigureAzureActiveDirectoryAuth(
    ConfigurationManager.AppSettings["azureAd:tenantId"],
    ConfigurationManager.AppSettings["azureAd:clientId"],
    //The value of this will need to change depending on your current environment
    postLoginRedirectUri: ConfigurationManager.AppSettings["azureAd:redirectUrl"],
    //This is the same as the TenantId
    issuerId: new Guid(ConfigurationManager.AppSettings["azureAd:tenantId"]));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then you’ll need to add a few appSettings to your web.config (based on your AAD info):&lt;/p&gt;

&lt;pre class="lang-csharp"&gt;&lt;code&gt;&amp;lt;add key="azureAd:tenantId" value="YOUR-TENANT-ID-GUID" /&amp;gt;
&amp;lt;add key="azureAd:clientId" value="YOUR-CLIENT-ID-GUID" /&amp;gt;
&amp;lt;add key="azureAd:redirectUrl" value="http://my-test-website/" /&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Configure your Umbraco data&lt;/h2&gt;&lt;p&gt;The UmbracoIdentity repository has the &lt;a href="https://github.com/Shazwazza/UmbracoIdentity#installation" target="_blank"&gt;installation documentation&lt;/a&gt; and you must follow these 2 instructions, and they are very simple:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="https://github.com/Shazwazza/UmbracoIdentity/wiki#2-member-type-updates" target="_blank"&gt;You need to update your member type with the securityStamp property&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="https://github.com/Shazwazza/UmbracoIdentity/wiki#3-creating-the-account-page" target="_blank"&gt;Create the Account document type&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Once that is done you will have an Member account management page which is based off of the installed views and snippets of the UmbracoIdentity package. This account page will look like this:&lt;/p&gt;&lt;p&gt;&lt;a href="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_8.png"&gt;&lt;img width="802" height="305" title="image" style="display: inline; background-image: none;" alt="image" src="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_thumb_3.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;As you can see the button text under the “Use another service to log in” is the login provider name which is a bit ugly. The good news is that this is easy to change since this is just a partial view that was installed with the UmbracoIdentity package. You can edit the file: &lt;em&gt;~/Views/UmbracoIdentityAccount/ExternalLoginsList.cshtml&lt;/em&gt;, the code to render that button text is using &lt;em&gt;@p.Authentication&lt;/em&gt; provider but we can easily change this to &lt;em&gt;@p.Caption&lt;/em&gt; which is actually the same caption text used in the extension method we created. So the whole button code can look like this instead:&lt;/p&gt;
&lt;pre class="lang-html"&gt;&lt;code&gt;
&amp;lt;button type="submit" class="btn btn-default"
        id="@p.AuthenticationType"
        name="provider"
        value="@p.AuthenticationType"
        title="Log in using your @p.Caption account"&amp;gt;
    @p.Caption
&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is a bit nicer, now the button looks like:&lt;/p&gt;&lt;p&gt;&lt;a href="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_10.png"&gt;&lt;img width="802" height="192" title="image" style="display: inline; background-image: none;" alt="image" src="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_thumb_4.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The purpose of all of these snippets and views installed with UmbracoIdentity is for you to customize how the whole flow looks and works so you’ll most likely end up customizing a number of views found in this folder to suit your needs.&lt;/p&gt;&lt;h2&gt;That’s it!&lt;/h2&gt;&lt;p&gt;Once that’s all configured, if you click on the Active Directory button to log in as a member, you’ll be brought to the standard AAD permission screen:&lt;/p&gt;&lt;p&gt;&lt;a href="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_18.png"&gt;&lt;img width="402" height="434" title="image" style="display: inline; background-image: none;" alt="image" src="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_thumb_8.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Once you accept you’ll be redirect back to your Account page:&lt;/p&gt;&lt;p&gt;&lt;a href="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_20.png"&gt;&lt;img width="802" height="930" title="image" style="display: inline; background-image: none;" alt="image" src="https://shazwazza.com/media/articulate/open-live-writer-configuring-azure-active-directory-login_c313-image_thumb_9.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Any customizations is then up to you. You can modify how the flow works, whether or not you accepting auto-linking accounts (like in the above example), or if you require a member to exist locally before being able to link an OAuth account, etc… All of the views and controller code in UmbracoIdentity is there for you to manipulate. The main files are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;~/Views/Account.cshtml&lt;/li&gt;&lt;li&gt;~/Views/UmbracoIdentityAccount/*&lt;/li&gt;&lt;li&gt;~/Controllers/UmbracoIdentityAccountController.cs&lt;/li&gt;&lt;li&gt;~/App_Start/UmbracoIdentityStartup.cs&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Happy coding!&lt;/p&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:09:08 Z</pubDate>
      <a10:updated>2023-03-23T15:09:08Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1260</guid>
      <link>https://shazwazza.com/post/aspnet-identity-for-umbraco-members/</link>
      <category>ASP.Net</category>
      <category>Umbraco</category>
      <title>ASP.Net Identity for Umbraco Members</title>
      <description>&lt;p&gt;I’ve released version 1.0 of &lt;em&gt;UmbracoIdentity&lt;/em&gt; which allows for &lt;a rel="noopener" href="http://www.asp.net/identity" target="_blank"&gt;ASP.Net Identity&lt;/a&gt; to be used with Umbraco for &lt;strong&gt;front-end&lt;/strong&gt; members. I’ve tried to write enough documentation for you to get started, all of the code and docs are here: &lt;a href="https://github.com/Shandem/UmbracoIdentity" title="https://github.com/Shandem/UmbracoIdentity"&gt;https://github.com/Shandem/UmbracoIdentity&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It’s worth noting that this is not something that ‘everyone’ should just jump in with and start using. If you are not familiar with OWIN or ASP.Net Identity than none of this will really make any sense, I’ve added a bit of a disclaimer to the docs about this here: &lt;a href="https://github.com/Shandem/UmbracoIdentity#owin-setup" title="https://github.com/Shandem/UmbracoIdentity#owin-setup"&gt;https://github.com/Shandem/UmbracoIdentity#owin-setup&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are some &lt;a rel="noopener" href="https://github.com/Shandem/UmbracoIdentity/wiki/Known-Issues" target="_blank"&gt;known issues and limitations&lt;/a&gt; that you should be aware of, and this will also not work currently with back office users (that will come eventually too though).&lt;/p&gt;
&lt;p&gt;This package can be highly customized, it comes with many .cshtml views and c# classes that you can customize as you see fit – very similar to the Visual Studio 2013 Web Application templates that support ASP.Net Identity.&lt;/p&gt;
&lt;h2&gt;What about Asp.Net Membership with Umbraco?&lt;/h2&gt;
&lt;p&gt;The way that I’ve created this is to be 100% compatible with the current Membership structure in Umbraco. This means that this is not using EntityFramework to access data, it uses the Umbraco member services and providers using custom ASP.Net Identity user stores. This also means that the password formats are based on the current password formats of the membership provider. When the Nuget package is installed it will actually swap out the membership provider for a custom type: &lt;em&gt;UmbracoIdentity.IdentityEnabledMembersMembershipProvider. &lt;/em&gt;This is required so that the password security can still be handled by the membership provider logic.&lt;/p&gt;
&lt;p&gt;There is a &lt;a rel="noopener" href="https://github.com/Shandem/UmbracoIdentity/wiki/Known-Issues#passwords" target="_blank"&gt;note about passwords here&lt;/a&gt;, ASP.Net Identity normally will format and salt passwords different (slightly better) than how the membership providers current work, but if you need that functionality you’d have to implement your own &lt;em&gt;IPasswordHasher&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;Installation&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;It is absolutely essential you read &lt;/span&gt;&lt;/strong&gt;&lt;a rel="noopener" href="https://github.com/Shandem/UmbracoIdentity" target="_blank"&gt;&lt;strong&gt;the documentation&lt;/strong&gt;&lt;/a&gt; before installing. Once you’ve done that, you can use Nuget:&lt;/p&gt;
&lt;div class="nuget-badge"&gt;
&lt;p&gt;PM&amp;gt; Install-Package UmbracoIdentity&lt;/p&gt;
&lt;/div&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1278</guid>
      <link>https://shazwazza.com/post/configuring-aspnet-identity-oauth-login-providers-for-multi-tenancy/</link>
      <category>ASP.Net</category>
      <title>Configuring ASP.Net Identity OAuth login providers for multi-tenancy</title>
      <description>&lt;p&gt;Say for example you have a CMS :) You want to give full control to the developer to manage how their front-end members with authenticate, which could of course include ASP.Net Identity OAuth login providers. At the same time you want to easily allow your CMS to be configured so that ASP.Net Identity OAuth providers can be used for logging into the back office.&amp;nbsp; In this scenario, the same OAuth provider might be used for both front-end and back-office authentication but authenticated under 2 different OAuth accounts. Another example might be if you have multi-tenancy set up for your front-end site and perhaps you want to use the same OAuth login provider but have members authenticate with different OAuth accounts for different domain names. &lt;/p&gt; &lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;  &lt;h2&gt;The defaults&lt;/h2&gt; &lt;p&gt;As an example, lets assume that front-end members are configured to authenticate with the ASP.Net Identity Google OAuth2 provider. This is easily done by just following one of the many tutorials out there. Your startup code might look like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;app.UseCookieAuthentication(&lt;span class="kwrd"&gt;new&lt;/span&gt; CookieAuthenticationOptions ....

app.UseExternalSignInCookie();

app.UseGoogleAuthentication(
              clientId: &lt;span class="str"&gt;"123456789..."&lt;/span&gt;,
              clientSecret: &lt;span class="str"&gt;"987654321...."&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Great, but I need 2 (or more) Google OAuth2 providers, so what now? I can’t just add 2 declarations of:&lt;/p&gt;&lt;pre class="csharpcode"&gt;app.UseGoogleAuthentication(
              clientId: &lt;span class="str"&gt;"123456789..."&lt;/span&gt;,
              clientSecret: &lt;span class="str"&gt;"987654321...."&lt;/span&gt;);

app.UseGoogleAuthentication(
              clientId: &lt;span class="str"&gt;"abcdef..."&lt;/span&gt;,
              clientSecret: &lt;span class="str"&gt;"zyxwv...."&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;you’ll quickly realize that doesn’t work and only one provider instance will actually be used. This is because of the default underlying settings that get used to instantiate the Google provider. Let’s have a look at what the default options are in this case. The above code is equivalent to this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;app.UseGoogleAuthentication(&lt;span class="kwrd"&gt;new&lt;/span&gt; GoogleOAuth2AuthenticationOptions
{
    AuthenticationType = &lt;span class="str"&gt;"Google"&lt;/span&gt;,
    ClientId = &lt;span class="str"&gt;"123456789..."&lt;/span&gt;,
    ClientSecret = &lt;span class="str"&gt;"987654321...."&lt;/span&gt;,
    Caption = &lt;span class="str"&gt;"Google"&lt;/span&gt;,
    CallbackPath = &lt;span class="kwrd"&gt;new&lt;/span&gt; PathString(&lt;span class="str"&gt;"/signin-google"&lt;/span&gt;),
    AuthenticationMode = AuthenticationMode.Passive,
    SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType(),
    BackchannelTimeout = TimeSpan.FromSeconds(60),
    BackchannelHttpHandler = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Net.Http.WebRequestHandler(),
    BackchannelCertificateValidator = &lt;span class="kwrd"&gt;null&lt;/span&gt;,
    Provider = &lt;span class="kwrd"&gt;new&lt;/span&gt; GoogleOAuth2AuthenticationProvider()
});&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h2&gt;The AuthenticationType&lt;/h2&gt;
&lt;p&gt;One very important aspect of the default settings is the &lt;em&gt;AuthenticationType&lt;/em&gt;. This is a &lt;strong&gt;unique &lt;/strong&gt;identifier for the provider instance and this is one of the reasons why if you have 2 x &lt;em&gt;UseGoogleAuthentication&lt;/em&gt; declarations with the defaults only one will ever be used.&lt;/p&gt;
&lt;p&gt;Knowing this, it’s clear that each declaration of &lt;em&gt;UseGoogleAuthentication&lt;/em&gt; needs to specify custom options and have the &lt;em&gt;AuthenticationType&lt;/em&gt; unique amongst them. So we might end up with something like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//keep defaults for front-end&lt;/span&gt;
app.UseGoogleAuthentication(
    clientId: &lt;span class="str"&gt;"123456789..."&lt;/span&gt;,
    clientSecret: &lt;span class="str"&gt;"987654321...."&lt;/span&gt;);

&lt;span class="rem"&gt;//custom options for back-office&lt;/span&gt;
app.UseGoogleAuthentication(&lt;span class="kwrd"&gt;new&lt;/span&gt; GoogleOAuth2AuthenticationOptions
{
    AuthenticationType = &lt;span class="str"&gt;"GoogleBackOffice"&lt;/span&gt;,
    ClientId = &lt;span class="str"&gt;"abcdef..."&lt;/span&gt;,
    ClientSecret = &lt;span class="str"&gt;"zyxwv...."&lt;/span&gt;    
});&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;If you test this now, you’ll find out that only the first declaration is actually working even when you explicitly tell &lt;em&gt;IOwinContext.Authentication.Challenge&lt;/em&gt; to use the “GoogleBackOffice” provider.&lt;/p&gt;
&lt;h2&gt;The CallbackPath&lt;/h2&gt;
&lt;p&gt;The reason that the default (first) declaration is the one that activates is because the response from Google is sending the request to the path: “/signin-google”, which is the default. The &lt;em&gt;GoogleAuthenticationMiddleware &lt;/em&gt;will delegate to the &lt;em&gt;GoogleAuthenticationHandler &lt;/em&gt;for each request and inspect the request to see if it should execute. For this logic it checks: &lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (Options.CallbackPath.HasValue &amp;amp;&amp;amp; Options.CallbackPath == Request.Path)
{
     &lt;span class="rem"&gt;//If the path matches, auth the request...&lt;/span&gt;
}&lt;/pre&gt;
&lt;p&gt;Since the &lt;em&gt;CallbackPath&lt;/em&gt; will be the same by default on both above declarations, the first one that is registered will match and the other registered authenticators will be ignored. To fix this we’ll need to update the path that Google sends back and then update the second declaration to match that path. &lt;/p&gt;
&lt;p&gt;To tell Google to send the request back on a different path, in your Google Developers Console change the REDIRECT URIS value for the second provider:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-connet-identity-oauth-login-providers-f_a1ef-image_thumb_2.png"&gt;&lt;img title="image_thumb" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image_thumb" src="http://shazwazza.com/media/articulate/windows-live-writer-connet-identity-oauth-login-providers-f_a1ef-image_thumb_thumb.png" width="244" height="216"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then we need to update the 2nd declaration with the custom &lt;em&gt;CallbackPath&lt;/em&gt; so that it matches and activates properly:&lt;/p&gt;&lt;pre class="csharpcode"&gt;app.UseGoogleAuthentication(&lt;span class="kwrd"&gt;new&lt;/span&gt; GoogleOAuth2AuthenticationOptions
{
    AuthenticationType = &lt;span class="str"&gt;"GoogleBackOffice"&lt;/span&gt;,
    ClientId = &lt;span class="str"&gt;"abcdef..."&lt;/span&gt;,
    ClientSecret = &lt;span class="str"&gt;"zyxwv...."&lt;/span&gt;,
    CallbackPath = &lt;span class="kwrd"&gt;new&lt;/span&gt; PathString(&lt;span class="str"&gt;"/custom-signin-google"&lt;/span&gt;)
});&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Hooray, now it should work!&lt;/p&gt;
&lt;p&gt;This concept is the same for most external login providers. For example for the Facebook one the default value is “/signin-facebook”, you’d need to configure Facebook’s “Valid OAuth redirect URIs” property with the correct callback path in Facebook’s developer portal:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/media/articulate/windows-live-writer-connet-identity-oauth-login-providers-f_a1ef-image_thumb1_2.png"&gt;&lt;img title="image_thumb1" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image_thumb1" src="http://shazwazza.com/media/articulate/windows-live-writer-connet-identity-oauth-login-providers-f_a1ef-image_thumb1_thumb.png" width="184" height="244"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;What is SignInAsAuthenticationType?&lt;/h2&gt;
&lt;p&gt;The last thing to point out is that by default the &lt;em&gt;SignInAsAuthenticationType &lt;/em&gt;for each provider will resolve to: &lt;em&gt;app.GetDefaultSignInAsAuthenticationType()&lt;/em&gt;, which by default is: &lt;em&gt;DefaultAuthenticationTypes.ExternalCookie&lt;/em&gt;&amp;nbsp; = “ExternalCookie”. Each OAuth provider is linked to another middleware that is responsible for actually issuing a user’s ClaimsIdentity, so by default this will be “ExternalCookie”. In some cases you won’t want the default external cookie authentication middleware to assign the ClaimsIdentity for your OAuth provider, you might need to issue a different ClaimsIdentity or just have more granular control over what happens with the callback for each OAuth provider. In this case you’ll need to specify another custom cookie authentication declaration, for example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;app.UseCookieAuthentication(&lt;span class="kwrd"&gt;new&lt;/span&gt; CookieAuthenticationOptions
{
    AuthenticationType = &lt;span class="str"&gt;"CustomExternal"&lt;/span&gt;,
    AuthenticationMode = AuthenticationMode.Passive,
    CookieName = &lt;span class="str"&gt;"MyAwesomeCookie"&lt;/span&gt;,
    ExpireTimeSpan = TimeSpan.FromMinutes(5),
    &lt;span class="rem"&gt;//Additional custom cookie options....&lt;/span&gt;
});&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;And then you can link that up to your OAuth declaration like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//custom options for back-office&lt;/span&gt;
app.UseGoogleAuthentication(&lt;span class="kwrd"&gt;new&lt;/span&gt; GoogleOAuth2AuthenticationOptions
{
    AuthenticationType = &lt;span class="str"&gt;"GoogleBackOffice"&lt;/span&gt;,
    ClientId = &lt;span class="str"&gt;"abcdef..."&lt;/span&gt;,
    ClientSecret = &lt;span class="str"&gt;"zyxwv...."&lt;/span&gt;,
    SignInAsAuthenticationType = &lt;span class="str"&gt;"CustomExternal"&lt;/span&gt;
});&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:08:15 Z</pubDate>
      <a10:updated>2023-03-23T15:08:15Z</a10:updated>
    </item>
  </channel>
</rss>