public CreateExternalUserInvitationUrl(IOptions <B2CSettings> b2cSettings) { _b2CSettings = b2cSettings.Value; #region .: Load Certificate :. _signingCredentials = new Lazy <X509SigningCredentials>(() => { X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); certStore.Open(OpenFlags.ReadOnly); X509Certificate2Collection certCollection = certStore.Certificates.Find( X509FindType.FindByThumbprint, _b2CSettings.SigningCertThumbprint, false); if (certCollection.Count > 0) { return(new X509SigningCredentials(certCollection[0])); } throw new Exception("Certificate not found"); }); #endregion }
// Inject an instance of an AppSettingsModel class into the constructor of the consuming class, // and let dependency injection handle the rest public OidcController(IOptions <B2CSettings> b2cSettings) { _b2CSettings = b2cSettings.Value; // Sample: Load the certificate with a private key (must be pfx file) _signingCredentials = new Lazy <X509SigningCredentials>(() => { X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); certStore.Open(OpenFlags.ReadOnly); X509Certificate2Collection certCollection = certStore.Certificates.Find( X509FindType.FindByThumbprint, _b2CSettings.SigningCertThumbprint, false); // Get the first cert with the thumb-print if (certCollection.Count > 0) { return(new X509SigningCredentials(certCollection[0])); } throw new Exception("Certificate not found"); }); }
public static void AddAzureB2CAuthentication(this IServiceCollection services, B2CSettings b2cSettings) { services.AddAuthentication(options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(jwtOptions => { jwtOptions.Authority = string.Format(b2cSettings.Authority, b2cSettings.B2CTenant, b2cSettings.B2CPolicy); jwtOptions.Audience = b2cSettings.B2CClientId; }); }