1

我正在将 Azure B2C 实现到 .NET MVC 应用程序,我需要向登录 url 添加一个额外的查询参数。

这是我在 startup.cs 中的设置方式

var openIdConnectAuthenticationOptions = new OpenIdConnectAuthenticationOptions
            {
                // Generate the metadata address using the tenant and policy information
                MetadataAddress = String.Format(Globals.WellKnownMetadata, Globals.Tenant, Globals.DefaultPolicy),

                // These are standard OpenID Connect parameters, with values pulled from web.config
                ClientId = Globals.ClientId,
                RedirectUri = Globals.RedirectUri,
                PostLogoutRedirectUri = Globals.RedirectUri,

                // Specify the callbacks for each type of notifications
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    RedirectToIdentityProvider = OnRedirectToIdentityProvider,
                    AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                    AuthenticationFailed = OnAuthenticationFailed
                },

                // Specify the claim type that specifies the Name property.
                TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name",
                    ValidateIssuer = false
                },

                // Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
                Scope = $"openid",
                ResponseType = "id_token",
            };

            app.UseOpenIdConnectAuthentication(
              openIdConnectAuthenticationOptions
            );

当有人试图访问一个带有 [authorized] 标记的页面时,它会将他们发送到这个 b2c url:

https://mytenant.b2clogin.com/mytenant.onmicrosoft.com/oauth2/v2.0/authorize?p=b2c_custom_signin&client_id=0000-000000-000-00&redirect_uri=https://localhost&response_type=id_token&scope=openid&x-client-SKU= ID_NET461&x-client-ver=5.3.0.0

但是,我需要在末尾添加一个额外的查询参数“&appId=000-000-000”,因此生成的登录 URL 为:

https://mytenant.b2clogin.com/mytenant.onmicrosoft.com/oauth2/v2.0/authorize?p=b2c_custom_signin&client_id=0000-000000-000-00&redirect_uri=https://localhost&response_type=id_token&scope=openid&x-client-SKU= ID_NET461&x-client-ver=5.3.0.0 &appId=000-000-000

我该怎么做呢?

4

1 回答 1

1

恐怕你不能添加appId参数,但我建议使用state参数。您可以使用此参数将 appid 的值作为请求的一部分发送,并在响应中返回它。

在此处输入图像描述

有关更多详细信息,请参见此处

于 2020-10-16T02:18:51.527 回答