Veracity.Authentication.OpenIDConnect.AspNet
1.1.0
Prefix Reserved
dotnet add package Veracity.Authentication.OpenIDConnect.AspNet --version 1.1.0
NuGet\Install-Package Veracity.Authentication.OpenIDConnect.AspNet -Version 1.1.0
<PackageReference Include="Veracity.Authentication.OpenIDConnect.AspNet" Version="1.1.0" />
paket add Veracity.Authentication.OpenIDConnect.AspNet --version 1.1.0
#r "nuget: Veracity.Authentication.OpenIDConnect.AspNet, 1.1.0"
// 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.
- Remove the old package
- Remove the owin startup reference in web.config
- install the package: Install-Package Veracity.Common.Authentication.AspNet
- update web.config keys
- veracity:ClientId → veracity:ClientId
- veracity:ClientSecret → apiGW:clientSecret (should be secured in key vault or the like)
- veracity:RedirectUri → apiGW:redirectUrl
- veracity:APISubscriptionKey → subscriptionKey
- Add new keys to web.config
- apiGW:scope = https://dnvglb2cprod.onmicrosoft.com/83054ebf-1d7b-43f5-82ad-b2bde84d7b75/user_impersonation
- apiGW:idp = a68572e3-63ce-4bc1-acdc-b64943502e9d
- apiGW:policy = B2C_1A_SignInWithADFSIdp
- myApiV3Url = https://api.veracity.com/Veracity/Services/V3 (if calling the Services api using our packages)
- 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 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. |
-
.NETFramework 4.7.1
- Microsoft.Configuration.ConfigurationBuilders.Base (>= 1.0.2)
- Microsoft.Extensions.Caching.Abstractions (>= 2.2.0)
- Microsoft.Identity.Client (>= 4.0.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 5.4.0)
- Microsoft.Owin.Security (>= 4.0.1)
- Microsoft.Owin.Security.Cookies (>= 4.0.1)
- Microsoft.Owin.Security.OAuth (>= 3.0.1)
- Microsoft.Owin.Security.OpenIdConnect (>= 4.0.1)
- System.Configuration.Abstractions (>= 2.0.2.45)
- System.Configuration.ConfigurationManager (>= 4.5.0)
- System.IdentityModel.Tokens.Jwt (>= 5.4.0)
- System.Runtime.Caching (>= 4.5.0)
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.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