Veracity.Authentication.OpenIDConnect.AspNet 1.1.0

Prefix Reserved
Suggested Alternatives

Veracity.Common.Authentication.AspNet

dotnet add package Veracity.Authentication.OpenIDConnect.AspNet --version 1.1.0                
NuGet\Install-Package Veracity.Authentication.OpenIDConnect.AspNet -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Veracity.Authentication.OpenIDConnect.AspNet" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Veracity.Authentication.OpenIDConnect.AspNet --version 1.1.0                
#r "nuget: Veracity.Authentication.OpenIDConnect.AspNet, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Veracity.Authentication.OpenIDConnect.AspNet as a Cake Addin
#addin nuget:?package=Veracity.Authentication.OpenIDConnect.AspNet&version=1.1.0

// Install Veracity.Authentication.OpenIDConnect.AspNet as a Cake Tool
#tool nuget:?package=Veracity.Authentication.OpenIDConnect.AspNet&version=1.1.0                

Converting from Veracity.Authentication.OpenIDConnect.* to Veracity.Common.Authentication.*

As we have changed our strategy to provide a unified set of packages that build upon eachother with authientication as the foundation we have deprecated the Veracity.Authentication.OpenIDConnect.* packages. This guide will help in the process of upgrading to the new packages.

We now support different options with regards of token caching through the Microsoft.Extensions.Caching namespace. This provides an easy and standard way of setting up the caching strategy that is most siutable for your solution. Note that persistent token chacing like redis and sql require you to encrupt the tokens before storing them. We also provide options for doing this. For details on the new packages see Readme.md

asp.net

This package is implemented using extension methods and not a full owin startup so you are able to customize the behaviour as you like and add additional middlewares if needed. In the samples here we only show the basics.

  1. Remove the old package
  2. Remove the owin startup reference in web.config
  3. install the package: Install-Package Veracity.Common.Authentication.AspNet
  4. update web.config keys
    1. veracity:ClientId → veracity:ClientId
    2. veracity:ClientSecret → apiGW:clientSecret (should be secured in key vault or the like)
    3. veracity:RedirectUri → apiGW:redirectUrl
    4. veracity:APISubscriptionKey → subscriptionKey
  5. Add new keys to web.config
    1. apiGW:scope = https://dnvglb2cprod.onmicrosoft.com/83054ebf-1d7b-43f5-82ad-b2bde84d7b75/user_impersonation
    2. apiGW:idp = a68572e3-63ce-4bc1-acdc-b64943502e9d
    3. apiGW:policy = B2C_1A_SignInWithADFSIdp
    4. myApiV3Url = https://api.veracity.com/Veracity/Services/V3 (if calling the Services api using our packages)
  6. Add owin startup, see sample below

Sample Owin startup.cs install Microsoft.Extensions.Caching.Memory -Version 2.0.0 (or higher)

using System.Security.Claims;
using System.Web;
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Owin;
using Veracity.Common.Authentication;

[assembly: OwinStartup(typeof(NetFrameworkIdentity.Startup))]

namespace NetFrameworkIdentity
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            //Example on how to get secrets from key vault
            var azureServiceTokenProvider = new AzureServiceTokenProvider();
            var keyVaultClient = new KeyVaultClient(async (authority, resource, scope) =>
                await azureServiceTokenProvider.GetAccessTokenAsync(resource));
            var secret = keyVaultClient.GetSecretAsync("https://veracitydevdaydemo.vault.azure.net/",
                "Veracity1--ClientSecret").Result;
            var subscriptionKey = keyVaultClient
                .GetSecretAsync("https://veracitydevdaydemo.vault.azure.net/", "Veracity--SubscriptionKey").Result;
            
            app.UseCookieAuthentication(new CookieAuthenticationOptions { CookieName = "a.c" }); //set auth cookie
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); //set default auth type 
            //configure veracity auth
            app.UseVeracityAuthentication(new TokenProviderConfiguration
                {
                    ClientSecret = secret.Value,
                    SubscriptionKey = subscriptionKey.Value
                }) //Add Azure Ad B2C authentication and access token cache
                .UseTokenCache(CacheFactoryFunc); //add access token cache and set cache strategy
        }

        private static DistributedTokenCache CacheFactoryFunc()
        {
            return new DistributedTokenCache(HttpContext.Current.User as ClaimsPrincipal, DistributedCache, null, null);
        }

        private static MemoryDistributedCache DistributedCache { get; } =
            new MemoryDistributedCache(
                new OptionsWrapper<MemoryDistributedCacheOptions>(new MemoryDistributedCacheOptions()));
    }
}

Modify global.asax.cs

protected void Application_Start()
{
    ConfigurationManagerHelper.SetManager(new ConfigManager()); //to hook up a config abstraction allowing the shared library work both for asp.net and aspnetcore
    this.AddDependencyInjection<AppServiceConfig>(); //Add Microsoft.Extensions.DependencyInjection support if you dont use DI already. If you are using autofac see the autofac IocIntegration for details
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Sample web.config file

<appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="apiGW:clientId" value="db4b6456-8873-4358-8c5d-96c39750ec28" />
    <add key="apiGW:policy" value="B2C_1A_SignInWithADFSIdp" />
    <add key="apiGW:scope" value="https://dnvglb2ctest.onmicrosoft.com/a4a8e726-c1cc-407c-83a0-4ce37f1ce130/user_impersonation" />
    <add key="apiGW:redirectUrl" value="https://localhost:44330/" />
    <add key="apiGW:idp" value="ed815121-cdfa-4097-b524-e2b23cd36eb6" />
    <add key="myApiV3Url" value="https://api-test.veracity.com/platform/" />
</appSettings>
Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 1,397 6/20/2019 1.1.0 is deprecated because it is no longer maintained.
1.0.0 954 12/29/2018
1.0.0-preview007 570 12/28/2018
1.0.0-preview006 598 12/28/2018
1.0.0-preview005 543 12/28/2018
1.0.0-preview004 613 12/28/2018
1.0.0-preview003 596 12/28/2018
1.0.0-preview002 636 12/28/2018
1.0.0-preview001 537 12/28/2018
1.0.0-beta1 578 12/28/2018
1.0.0-beta 635 12/28/2018

Updated dependencies