Veracity.Authentication.OpenIDConnect.AspNet 1.1.0

.NET Framework 4.6.1
Suggested Alternatives

Veracity.Common.Authentication.AspNet

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.
dotnet add package Veracity.Authentication.OpenIDConnect.AspNet --version 1.1.0
<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, C# scripting and .NET Interactive. 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 Versions
.NET Framework net461 net462 net463 net47 net471 net472 net48
Compatible target framework(s)
Additional computed target framework(s)
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,121 6/20/2019
1.0.0 716 12/29/2018
1.0.0-preview007 459 12/28/2018
1.0.0-preview006 460 12/28/2018
1.0.0-preview005 431 12/28/2018
1.0.0-preview004 497 12/28/2018
1.0.0-preview003 496 12/28/2018
1.0.0-preview002 506 12/28/2018
1.0.0-preview001 429 12/28/2018
1.0.0-beta1 463 12/28/2018
1.0.0-beta 481 12/28/2018

Updated dependencies