AddMicrosoftIdentityWebApp

C:\Users\clu\.nuget\packages\microsoft.identity.web\2.9.0\lib\netcoreapp3.1\Microsoft.Identity.Web.dll

[assembly: AssemblyFileVersion("2.9.0.0")]
[assembly: AssemblyInformationalVersion("2.9.0+87400de3c669d962b2035d36ab6d2415cd4123f4")]
[assembly: AssemblyProduct("Microsoft Identity Web")]
[assembly: AssemblyTitle("Microsoft.Identity.Web")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/AzureAD/microsoft-identity-web")]
[assembly: SecurityPermission(8, SkipVerification = true)]

microsoft-identity-web/src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilderExtensions.cs at 87400de3c669d962b2035d36ab6d2415cd4123f4 · AzureAD/microsoft-identity-web (github.com)

 /// <summary>
        /// Add authentication to a web app with Microsoft identity platform.
        /// This method expects the configuration file will have a section, named "AzureAd" as default,
        /// with the necessary settings to initialize authentication options.
        /// </summary>
        /// <param name="builder">The <see cref="AuthenticationBuilder"/> to which to add this configuration.</param>
        /// <param name="configuration">The configuration instance.</param>
        /// <param name="configSectionName">The configuration section with the necessary settings to initialize authentication options.</param>
        /// <param name="openIdConnectScheme">The OpenID Connect scheme name to be used. By default it uses "OpenIdConnect".</param>
        /// <param name="cookieScheme">The cookie-based scheme name to be used. By default it uses "Cookies".</param>
        /// <param name="subscribeToOpenIdConnectMiddlewareDiagnosticsEvents">Set to true if you want to debug, or just understand the OpenID Connect events.</param>
        /// <param name="displayName">A display name for the authentication handler.</param>
        /// <returns>The <see cref="MicrosoftIdentityWebAppAuthenticationBuilderWithConfiguration"/> builder for chaining.</returns>
        public static MicrosoftIdentityWebAppAuthenticationBuilderWithConfiguration AddMicrosoftIdentityWebApp(
            this AuthenticationBuilder builder,
            IConfiguration configuration,
            string configSectionName = Constants.AzureAd,
            string openIdConnectScheme = OpenIdConnectDefaults.AuthenticationScheme,
            string? cookieScheme = CookieAuthenticationDefaults.AuthenticationScheme,
            bool subscribeToOpenIdConnectMiddlewareDiagnosticsEvents = false,
            string? displayName = null)
        {
            if (configuration == null)
            {
                throw new ArgumentException(nameof(configuration));
            }

            if (string.IsNullOrEmpty(configSectionName))
            {
                throw new ArgumentException(nameof(configSectionName));
            }

            IConfigurationSection configurationSection = configuration.GetSection(configSectionName);

            return builder.AddMicrosoftIdentityWebApp(
                configurationSection,
                openIdConnectScheme,
                cookieScheme,
                subscribeToOpenIdConnectMiddlewareDiagnosticsEvents,
                displayName);
        }

        /// <summary>
        /// Add authentication with Microsoft identity platform.
        /// This method expects the configuration file will have a section, named "AzureAd" as default, with the necessary settings to initialize authentication options.
        /// </summary>
        /// <param name="builder">The <see cref="AuthenticationBuilder"/> to which to add this configuration.</param>
        /// <param name="configurationSection">The configuration section from which to get the options.</param>
        /// <param name="openIdConnectScheme">The OpenID Connect scheme name to be used. By default it uses "OpenIdConnect".</param>
        /// <param name="cookieScheme">The cookie-based scheme name to be used. By default it uses "Cookies".</param>
        /// <param name="subscribeToOpenIdConnectMiddlewareDiagnosticsEvents">Set to true if you want to debug, or just understand the OpenID Connect events.</param>
        /// <param name="displayName">A display name for the authentication handler.</param>
        /// <returns>The authentication builder for chaining.</returns>
        public static MicrosoftIdentityWebAppAuthenticationBuilderWithConfiguration AddMicrosoftIdentityWebApp(
            this AuthenticationBuilder builder,
            IConfigurationSection configurationSection,
            string openIdConnectScheme = OpenIdConnectDefaults.AuthenticationScheme,
            string? cookieScheme = CookieAuthenticationDefaults.AuthenticationScheme,
            bool subscribeToOpenIdConnectMiddlewareDiagnosticsEvents = false,
            string? displayName = null)
        {
            _ = Throws.IfNull(builder);
            _ = Throws.IfNull(configurationSection);

            return builder.AddMicrosoftIdentityWebAppWithConfiguration(
                options => configurationSection.Bind(options),
                null,
                openIdConnectScheme,
                cookieScheme,
                subscribeToOpenIdConnectMiddlewareDiagnosticsEvents,
                displayName,
                configurationSection);
        }

        /// <summary>
        /// Add authentication with Microsoft identity platform.
        /// </summary>
        /// <param name="builder">The <see cref="AuthenticationBuilder"/> to which to add this configuration.</param>
        /// <param name="configureMicrosoftIdentityOptions">The action to configure <see cref="MicrosoftIdentityOptions"/>.</param>
        /// <param name="configureCookieAuthenticationOptions">The action to configure <see cref="CookieAuthenticationOptions"/>.</param>
        /// <param name="openIdConnectScheme">The OpenID Connect scheme name to be used. By default it uses "OpenIdConnect".</param>
        /// <param name="cookieScheme">The cookie-based scheme name to be used. By default it uses "Cookies".</param>
        /// <param name="subscribeToOpenIdConnectMiddlewareDiagnosticsEvents">Set to true if you want to debug, or just understand the OpenID Connect events.</param>
        /// <param name="displayName">A display name for the authentication handler.</param>
        /// <returns>The authentication builder for chaining.</returns>
        public static MicrosoftIdentityWebAppAuthenticationBuilder AddMicrosoftIdentityWebApp(
            this AuthenticationBuilder builder,
            Action<MicrosoftIdentityOptions> configureMicrosoftIdentityOptions,
            Action<CookieAuthenticationOptions>? configureCookieAuthenticationOptions = null,
            string openIdConnectScheme = OpenIdConnectDefaults.AuthenticationScheme,
            string? cookieScheme = CookieAuthenticationDefaults.AuthenticationScheme,
            bool subscribeToOpenIdConnectMiddlewareDiagnosticsEvents = false,
            string? displayName = null)
        {
            _ = Throws.IfNull(builder);

            return builder.AddMicrosoftWebAppWithoutConfiguration(
                configureMicrosoftIdentityOptions,
                configureCookieAuthenticationOptions,
                openIdConnectScheme,
                cookieScheme,
                subscribeToOpenIdConnectMiddlewareDiagnosticsEvents,
                displayName);
        }

四个参数需要注意

 this AuthenticationBuilder builder,
            Action<MicrosoftIdentityOptions> configureMicrosoftIdentityOptions,
            Action<CookieAuthenticationOptions>? configureCookieAuthenticationOptions = null,
            string openIdConnectScheme = OpenIdConnectDefaults.AuthenticationScheme,
            string? cookieScheme = CookieAuthenticationDefaults.AuthenticationScheme,

 

https://www.nuget.org/packages/Microsoft.Identity.Web/2.9.0#dependencies-body-tab

MicrosoftIdentityOptions在Microsoft.Identity.Web.TokenAcquisition类库里面

microsoft-identity-web/src/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityOptions.cs at 87400de3c669d962b2035d36ab6d2415cd4123f4 · AzureAD/microsoft-identity-web (github.com)

 

 

MicrosoftIdentityOptions继承了OpenIdConnectOptions 

aspnetcore/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectOptions.cs at 0a2e366eaf4d29b24b9a98e5782a04bef573189e · dotnet/aspnetcore (github.com)

OpenIdConnectOptions有public OpenIdConnectEvents Events { get; set; }

aspnetcore/src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs at 0a2e366eaf4d29b24b9a98e5782a04bef573189e · dotnet/aspnetcore (github.com)

 

MicrosoftIdentityOptions inherits from OpenIdConnectOptions because Microsoft Identity Platform (MIP) is an implementation of OpenID Connect (OIDC). MIP provides a number of features that are not available in the standard OIDC specification, such as:

  • Microsoft Authentication Library (MSAL): MSAL is a library that makes it easy to integrate MIP into your applications. MSAL abstracts away the details of the OIDC protocol, so you can focus on developing your application.
  • Azure Active Directory (AAD): AAD is a cloud-based identity and access management service that can be used to manage users and their access to resources. MIP can be used to integrate with AAD, so that users can sign in to your application using their AAD credentials.
  • B2C (Business-to-Customer) identity flows: MIP provides a number of B2C identity flows that can be used to customize the authentication experience for your users. For example, you can use a B2C identity flow to allow users to sign in using their social media accounts, such as Facebook or Google.

Because MIP is an implementation of OIDC, it inherits all of the features of OIDC. However, MIP also adds a number of features that are not available in the standard OIDC specification. This is why MicrosoftIdentityOptions inherits from OpenIdConnectOptions.

In addition to the features mentioned above, MicrosoftIdentityOptions also inherits a number of other properties and methods from OpenIdConnectOptions. These properties and methods can be used to configure the authentication flow, such as the authorization endpoint, the token endpoint, and the userinfo endpoint.

Overall, MicrosoftIdentityOptions inherits from OpenIdConnectOptions because it is an implementation of OIDC. This inheritance allows MicrosoftIdentityOptions to inherit all of the features of OIDC, as well as a number of additional features that are not available in the standard OIDC specification.

 

 

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(94)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2022-07-20 Using the OptanonWrapper Callback Function
2022-07-20 Add gtag.js to your site
2022-07-20 Tag Manager and gtag.js
2022-07-20 What is the difference between google tag manager and google analytics?
2022-07-20 what are the values in _ga cookie?
2021-07-20 The framework 'Microsoft.WindowsDesktop.App', version '5.0.0' was not found
2020-07-20 Detailed ASP.NET MVC Pipeline
点击右上角即可分享
微信分享提示