/// <summary> /// Adds Azure Active Directory Authentication to your application. /// </summary> /// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param> /// <param name="scheme">The identifier for the virtual scheme.</param> /// <param name="openIdConnectScheme">The identifier for the underlying Open ID Connect scheme.</param> /// <param name="cookieScheme">The identifier for the underlying cookie scheme.</param> /// <param name="displayName">The display name for the scheme.</param> /// <param name="configureOptions">The <see cref="Action{AzureADOptions}"/> to configure the /// <see cref="AzureADOptions"/> /// </param> /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> public static AuthenticationBuilder AddAzureAD( this AuthenticationBuilder builder, string scheme, string openIdConnectScheme, string cookieScheme, string displayName, Action <AzureADOptions> configureOptions) { AddAdditionalMvcApplicationParts(builder.Services); builder.AddPolicyScheme(scheme, displayName, o => { o.ForwardDefault = cookieScheme; o.ForwardChallenge = openIdConnectScheme; }); builder.Services.Configure(TryAddOpenIDCookieSchemeMappings(scheme, openIdConnectScheme, cookieScheme)); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <IConfigureOptions <AzureADOptions>, AzureADOptionsConfiguration>()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <IValidateOptions <AzureADOptions>, AzureADOptionsValidation>()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <IConfigureOptions <OpenIdConnectOptions>, AzureADOpenIdConnectOptionsConfiguration>()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <IConfigureOptions <CookieAuthenticationOptions>, AzureADCookieOptionsConfiguration>()); builder.Services.Configure(scheme, configureOptions); builder.AddOpenIdConnect(openIdConnectScheme, null, o => { }); builder.AddCookie(cookieScheme, null, o => { }); return(builder); }
public static AuthenticationBuilder AddSessionCookie(this AuthenticationBuilder builder) { builder.AddCookie(options => { options.SessionStore = new MemoryCacheTicketStore(); }); return builder; }