你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

通过 Akamai 企业应用程序访问配置 Azure Active Directory B2C 已实现 SSO 和安全混合访问

本示例教程介绍如何将 Azure Active Directory B2C (Azure AD B2C) 身份验证与 Akamai 企业应用程序访问集成。 Akamai 企业应用程序访问是一种零信任网络访问 (ZTNA) 解决方案,可实现对专用数据中心中的现代化以及旧版应用程序的安全远程访问。 Akamai 企业应用程序访问与标识提供者 (IdP) Azure AD B2C 联合对用户进行身份验证,然后使用其授权策略对标识、设备、应用程序和请求上下文执行持续评估,再允许访问专用应用程序。

此功能仅适用于自定义策略。 对于设置步骤,请在前面的选择器中选择“自定义策略”。

先决条件

若要开始,需要:

  • Akamai 企业访问合同。 如果没有,可获取免费试用版

  • Azure 订阅。 如果没有订阅,可以获取一个免费帐户

  • 已链接到 Azure 订阅的 Azure AD B2C 租户

  • 部署在数据中心或混合云环境中的防火墙后的虚拟设备,用于部署 Akamai 企业应用程序访问连接器

  • 使用标头进行身份验证的应用程序。 在此示例中,我们将使用显示标头 docker header-demo-app 的应用程序。

  • 或 OpenID Connect (OIDC) 应用程序。 本示例将使用 ASP.NET MVC Web 应用,该应用通过使用 .NET (OWIN) 中间件的开放式 Web 接口和 Microsoft 标识平台来让用户登录。

方案描述

在此方案中,你将让最终用户能在尝试访问受 Akamai 企业应用程序访问保护的专用应用程序时完成 Azure AD B2C 身份验证。

此集成所涉及的组件包括:

  • Azure AD B2C:负责对最终用户进行身份验证的 SAML 标识提供者。

  • Akamai 企业应用程序访问:一项 ZTNA 云服务,负责通过持续实施 ZTNA 策略来保护对专用应用程序的访问。

  • Akamai 企业应用程序访问连接器:部署在专用数据中心的虚拟设备。 通过该连接器,可建立与专用应用之间的安全连接,无需打开任何数据中心入站防火墙端口。

  • 应用程序:部署在专用数据中心的服务或应用程序,是最终用户需要访问的对象。

用户向 Azure AD B2C(作为 SAML IdP)进行身份验证,Azure AD B2C 将通过 SAML 断言响应 Akamai 企业应用程序访问(服务提供商)。 Akamai 企业应用程序访问映射 SAML 断言中的信息,并构造 OpenID 声明或注入包含用户相关信息的 HTTP 标头。 然后 Akamai 企业应用程序访问会将此内容传递至可通过 Akamai 企业应用程序访问连接器访问的应用程序。 在我们的示例中,应用程序将显示这些标头的内容。 如果使用的是 OIDC 应用程序,将显示用户的声明。

下图展示的是 Akamai 企业应用程序访问 (EAA) 与 Azure AD B2C 的集成方式。

Screenshot shows the integration architecture.

  1. 最终用户尝试使用 Akamai 企业应用程序访问中注册的应用程序的外部 URL 访问专用数据中心内托管的应用程序。

  2. Akamai 企业应用程序访问将未经身份验证的最终用户重定向到 Azure AD B2C 以进行身份验证。

  3. 身份验证成功后,Azure AD B2C 使用 SAML 断言将用户重定向回 Akamai 企业应用程序访问。

  4. Akamai 企业应用程序访问使用 SAML 断言中的身份信息来标识用户,并确定是否允许用户访问其请求的应用程序。

  5. Akamai 企业应用程序访问构造 OIDC 声明或注入发送到应用程序的 HTTP 标头。

  6. 应用程序使用此信息来标识经过身份验证的用户,并为最终用户创建应用程序会话。

加入 Akamai 企业应用程序访问

若要开始使用 Akamai 企业应用程序访问,请参阅 Akamai 企业应用程序访问入门指南

步骤 1 - 在 Akamai 企业应用程序访问中将 Azure AD B2C 添加为 SAML IdP

Akamai 企业应用程序访问支持与 Azure AD B2C 等云 IdP 的 SAML 联合。 在 Akamai 企业应用程序访问中将 Azure AD B2C 添加为第三方 SAML IdP

  1. 登录到企业中心 https://control.akamai.com/

  2. 在企业中心导航菜单中选择“应用程序访问”>“标识和用户”>“标识提供者”。

  3. 选择“添加标识提供者(+)”。

  4. 输入名称、说明,并在提供者类型处选择“第三方 SAML”。

  5. 选择“继续”。 此时会显示标识提供者配置页面。

  6. 在“设置”>“常规”中,输入标识服务器的 URL。 可以选择使用 Akamai 域或使用自己的域。 如果使用自己的域,请使用自签名证书,或使用上传的自定义证书。

  7. 在“身份验证”中输入上一步骤中在“常规”部分定义的 URL,然后选择“保存”。

    Screenshot shows the akamai settings.

步骤 2 - 在 Azure AD B2C 中注册 SAML 应用程序

  1. 从 GitHub 获取自定义策略新手包,然后使用 Azure AD B2C 租户名称更新 LocalAccounts 新手包中的 XML 文件:

    • 下载 .zip 文件或克隆存储库:

      git clone https://github.com/Azure-Samples/active-directory-b2c-custom-policy-starterpack
      
    • 在 LocalAccounts 目录中的所有文件中,将字符串 yourtenant 替换为 Azure AD B2C 租户的名称。 例如,如果 B2C 租户的名称为 fabrikam,则 yourtenant.onmicrosoft.com 的所有实例都将变为 fabrikam.onmicrosoft.com

  2. 为 Azure AD B2C 创建签名证书,以对发送到 Akamai 企业应用程序访问的 SAML 响应进行签名:

    a. 获得证书。 如果你还没有证书,则可以使用自签名证书。

    b. 在 Azure AD B2C 租户中上传证书。 记下该名称,因为该名称将在后续步骤中用于我们提到过的 TechnicalProfile

  3. 启用策略以连接 SAML 应用程序。

    a. 打开自定义策略新手包中的 LocalAccounts\TrustFrameworkExtensions.xml 。 找到 ClaimsProviders 元素。 如果策略不存在,请在根元素 TrustFrameworkPolicy 下进行添加,并添加以下 XML 代码片段以实现 SAML 响应生成器:

     <ClaimsProvider>
       <DisplayName>Akamai</DisplayName>
       <TechnicalProfiles>
         <!-- SAML Token Issuer technical profile -->
         <TechnicalProfile Id="AkamaiSaml2AssertionIssuer">
           <DisplayName>Token Issuer</DisplayName>
           <Protocol Name="SAML2" />
           <OutputTokenFormat>SAML2</OutputTokenFormat>
           <Metadata>
             <Item Key="IssuerUri">https://<REPLACE>.login.go.akamai-access.com/saml/sp/response</Item>
           </Metadata>
           <CryptographicKeys>
             <Key Id="SamlAssertionSigning" StorageReferenceId="B2C_1A_AkamaiSAMLSigningCert" />
             <Key Id="SamlMessageSigning" StorageReferenceId="B2C_1A_AkamaiSAMLSigningCert" />
           </CryptographicKeys>
           <InputClaims />
           <OutputClaims />
           <UseTechnicalProfileForSessionManagement ReferenceId="SM-Saml-issuerAkamai" />
         </TechnicalProfile>
         <!-- Session management technical profile for SAML-based tokens -->
         <TechnicalProfile Id="SM-Saml-issuerAkamai">
           <DisplayName>Session Management Provider</DisplayName>
           <Protocol Name="Proprietary" Handler="Web.TPEngine.SSO.SamlSSOSessionProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
           <Metadata>
             <Item Key="IncludeSessionIndex">false</Item>
             <Item Key="RegisterServiceProviders">false</Item>
           </Metadata>
         </TechnicalProfile>
       </TechnicalProfiles>
     </ClaimsProvider>
    

    b. 将 issuerUri 替换为步骤 1 中在 Akamai 企业应用程序访问“设置”>“常规”中定义的 Akamai URL

    • 示例:<Item Key="IssuerUri">https://fabrikam.login.go.akamai-access.com/saml/sp/response</Item>

    • 将 B2C_1A_AkamaiSAMLSigningCert 替换为已上传的策略密钥的名称。

步骤 3 - 创建为 SAML 配置的注册或登录策略

  1. 在初学者包的工作目录中创建 SignUpOrSignin.xml 文件的副本,并使用新名称保存该副本。 本文使用 SignUpOrSigninSAML.xml 作为示例。 此文件是你对信赖方的策略文件。 它默认配置为发出 JWT 响应。

  2. 在自己偏好的编辑器中打开 SignUpOrSigninSAML.xml 文件。

  3. 使用 Azure AD B2C 租户的名称进行更新 tenant-name,将策略的 PolicyIdPublicPolicyUri 值更改为 B2C_1A_signup_signin_samlhttp://<tenant-name>.onmicrosoft.com/B2C_1A_signup_signin_saml

    <TrustFrameworkPolicy
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06"
    PolicySchemaVersion="0.3.0.0"
    TenantId="tenant-name.onmicrosoft.com"
    PolicyId="B2C_1A_signup_signin_saml"
    PublicPolicyUri="http://<tenant-name>.onmicrosoft.com/B2C_1A_signup_signin_saml">
    
  4. 用户旅程结束时,Azure AD B2C 将包含 SendClaims 步骤。 此步骤引用令牌颁发者技术配置文件。 若要发出 SAML 响应而不是默认的 JWT 响应,请修改 SendClaims 步骤,以引用新的 SAML 令牌颁发者技术配置文件 Saml2AssertionIssuer

    紧靠在 <RelyingParty> 元素的前面添加以下 XML 代码片段。 此 XML 将覆盖 SignUpOrSignIn 用户旅程中的业务流程步骤 4(假设使用的是 LocalAccount 自定义策略初学者包)。

    如果已从初学者包中的不同文件夹启动,或者通过添加或删除业务流程步骤自定义了用户旅程,请确保 order 元素中的编号对应于用户旅程中为令牌颁发者步骤指定的编号。 例如,在其他初学者包文件夹中,SocialAndLocalAccountsSocialAccountsSocialAndLocalAccountsWithMfa 的对应步骤编号分别为 7、6、9。

    <UserJourneys>
    <UserJourney Id="SignUpOrSignIn">
      <OrchestrationSteps>
        <OrchestrationStep Order="4" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="AkamaiSaml2AssertionIssuer"/>
      </OrchestrationSteps>
    </UserJourney>
    </UserJourneys>
    

    信赖方元素确定应用程序使用的协议。 默认为 OpenId。 必须将 Protocol 元素更改为 SAML。 输出声明将创建到 SAML 断言的声明映射。

    <RelyingParty> 元素中的整个 <TechnicalProfile> 元素替换为以下技术配置文件 XML。

     <TechnicalProfile Id="PolicyProfile">
       <DisplayName>PolicyProfile</DisplayName>
       <Protocol Name="SAML2"/>
       <OutputClaims>
         <OutputClaim ClaimTypeReferenceId="displayName" />
         <OutputClaim ClaimTypeReferenceId="givenName" />
         <OutputClaim ClaimTypeReferenceId="surname" />
         <OutputClaim ClaimTypeReferenceId="email" DefaultValue="" />
         <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="" />
         <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="objectId"/>
       </OutputClaims>
       <SubjectNamingInfo ClaimType="objectId" ExcludeAsClaim="true"/>
     </TechnicalProfile>
    

    信赖方的最终策略文件应如以下 XML 代码所示:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <TrustFrameworkPolicy
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns="http://schemas.microsoft.com/online/cpim/schemas/2013/06"
     PolicySchemaVersion="0.3.0.0"
     TenantId="fabrikam.onmicrosoft.com"
     PolicyId="B2C_1A_signup_signin_saml"
     PublicPolicyUri="http://fabrikam.onmicrosoft.com/B2C_1A_signup_signin_saml">
     <BasePolicy>
       <TenantId>fabrikam.onmicrosoft.com</TenantId>
       <PolicyId>B2C_1A_TrustFrameworkExtensions</PolicyId>
     </BasePolicy>
    
     <UserJourneys>
       <UserJourney Id="SignUpOrSignIn">
         <OrchestrationSteps>
           <OrchestrationStep Order="7" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="AkamaiSaml2AssertionIssuer"/>
         </OrchestrationSteps>
       </UserJourney>
     </UserJourneys>
     <RelyingParty>
       <DefaultUserJourney ReferenceId="SignUpOrSignIn" />
       <TechnicalProfile Id="PolicyProfile">
         <DisplayName>PolicyProfile</DisplayName>
         <Protocol Name="SAML2"/>
         <OutputClaims>
           <OutputClaim ClaimTypeReferenceId="displayName" />
           <OutputClaim ClaimTypeReferenceId="givenName" />
           <OutputClaim ClaimTypeReferenceId="surname" />
           <OutputClaim ClaimTypeReferenceId="email" DefaultValue="" />
           <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="" />
           <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="objectId"/>
         </OutputClaims>
         <SubjectNamingInfo ClaimType="objectId" ExcludeAsClaim="true"/>
       </TechnicalProfile>
     </RelyingParty>
     </TrustFrameworkPolicy>
    

注意

可以按照相同的流程来实现其他类型的流(例如登录、密码重置或配置文件编辑流)。

步骤 4 - 上传策略

保存更改并将 TrustFrameworkBase.xml、新的 TrustFrameworkExtensions.xmlSignUpOrSigninSAML.xml 策略文件上传到 Azure 门户。

  1. 登录 Azure 门户

  2. 如果有权访问多个租户,请选择顶部菜单中的“设置”图标,切换到“目录 + 订阅”菜单中的 Azure AD B2C 租户

  3. Azure 门户中,搜索并选择 Azure AD B2C。

  4. 在策略下,选择 Identity Experience Framework。 选择“上传自定义策略”,然后按以下顺序上传已更改的两个策略文件:

    • 基文件,例如 TrustFrameworkBase.xml
    • 扩展策略,例如 TrustFrameworkExtensions.xml
    • 然后是信赖方策略,例如 SignUpOrSigninSAML.xml

步骤 5 - 下载 Azure AD B2C IdP SAML 元数据

上传策略文件后,Azure AD B2C 将使用配置信息来生成应用程序使用的标识提供者 SAML 元数据文档。 SAML 元数据文档包含服务的位置,例如登录方法、注销方法和证书。

  • 以下 URL 提供了 Azure AD B2C 策略元数据:https://<tenant-name>.b2clogin.com/<tenant-name>.onmicrosoft.com/<policy-name>/samlp/metadata

  • <tenant-name> 替换为 Azure AD B2C 租户的名称。 将 <policy-name> 替换为策略的名称 (ID)。 下面是一个示例:https://fabrikam.b2clogin.com/fabrikam.onmicrosoft.com/B2C_1A_signup_signin_saml/samlp/metadata

下载 SAML 元数据并将其本地保存在设备上。 在 Akamai 企业应用程序访问中完成配置的后续步骤会需要该元数据。

步骤 6 - 在 Azure AD B2C 中注册 Akamai 企业应用程序访问应用程序

要使 Azure AD B2C 信任 Akamai 企业应用程序访问,需要创建 Azure AD B2C 应用程序注册。 注册包含配置信息,如应用程序的元数据终结点。

  1. 登录 Azure 门户

  2. 如果有权访问多个租户,请选择顶部菜单中的“设置”图标,切换到“目录 + 订阅”菜单中的 Azure AD B2C 租户

  3. 在左侧菜单中,选择“Azure AD B2C”。 或者,选择“所有服务”,然后搜索并选择“Azure AD B2C”

  4. 选择“应用注册”,然后选择“新建注册” 。

  5. 输入应用程序的“名称”。 例如输入 Akamai B2C 企业应用程序访问。

  6. 在“支持的帐户类型”下,选择“仅此组织目录中的帐户(仅 B2C - 单一租户)”。

  7. 在“重定向 URI”中选择“Web”,然后输入步骤 1 中在 Akamai 企业应用程序访问“设置”\“常规”中定义的 Akamai URL。 例如,https://fabrikam.login.go.akamai-access.com/saml/sp/response

  8. 选择“注册”。

步骤 7 - 在 Azure AD B2C 中配置 Akamai 企业应用程序访问应用程序

对于 SAML,需要在应用程序注册的清单中配置几个属性。

  1. Azure 门户中,转到在步骤 3 中创建的应用程序注册。

  2. 在“管理”下,选择“清单”以打开清单编辑器。 然后修改以下各节中介绍的属性。

添加标识符

当 Akamai 企业应用程序访问应用程序向 Azure AD B2C 发出请求时,SAML 身份验证请求将包含一个 Issuer 特性。 此特性的值通常与应用程序的元数据 entityID 值相同。 Azure AD B2C 使用此值在目录中查找应用程序注册并读取配置。 要使此查找操作成功,必须使用与 Issuer 特性匹配的值来填充应用程序注册清单中的 identifierUri

Screenshot shows the b2c saml configuration.

在注册清单中找到 identifierURIs 参数并添加在步骤 2 中定义的 IssuerURI 值 (Azure AD B2C ClaimsProvider)。

例如:

"identifierUris": [
		"https://fabrikam.login.go.akamai-access.com/saml/sp/response"
	],

此值将与在应用程序的 SAML AuthN 请求中为 EntityId 配置的值,以及应用程序元数据中的 entityID 值相同。 还将需要找到 accessTokenAcceptedVersion 参数,并将值设置为 2

重要

如果不将 accessTokenAcceptedVersion 更新为 2,你将收到一条错误消息,要求提供一个经过验证的域。

步骤 8 - 在 Akamai 企业应用程序访问中配置 Azure AD B2C IdP 的身份验证设置

使用信赖方 URL 等身份验证信息更新 Akamai 企业应用程序访问 Azure AD B2C IdP。

  1. 登录到企业中心 https://control.akamai.com/

  2. 在企业中心导航菜单中选择“应用程序访问”>“标识和用户”>“标识提供者”。

  3. 选择在步骤 1 中创建的标识提供者名称。

  4. 上传在步骤 5 中下载的 Azure AD B2C SAML 元数据文件。

  5. 要上传 metadata.xml 文件,请选择“选择文件”。

    Screenshot shows the metadata file.

  6. 选择“保存并部署”。

步骤 9 - 在专用数据中心部署 Akamai 企业应用程序访问连接器

若要实现对专用应用程序的访问,请在应用程序所在的专用数据中心部署一个或多个 Akamai 企业应用程序访问连接器。 确保部署的连接器可以访问专用应用程序,并具有对 Akamai Cloud 的出站访问权限。

步骤 10 - 在 Akamai 企业应用程序访问中为专用应用程序定义访问应用程序

  1. 在 Akamai 企业应用程序访问中定义并部署访问应用程序

  2. 定义访问应用程序时

选项 1:HTTP 标头

在此示例中,我们将使用显示标头 docker header-demo-app 的应用程序。 在专用环境中部署应用程序并确保连接器能访问应用程序后,请按照 Akamai 文档为访问应用程序配置自定义 HTTP 标头中所述的内容创建自定义 HTTP 类型应用程序。

  1. 在“身份验证”中,选择在前面的步骤中创建的 Azure AD B2C SAML IdP。

Screenshot shows the akamai authn application.

  1. 在应用程序的“高级”部分中,将 HTTP 标头映射至 Azure AD B2C 在 SAML 响应中发出的 SAML 特性(身份验证成功后)。

例如:

标头名称 Attribute
ps-sso-first http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
ps-sso-last http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname
ps-sso-EmailAddress emailaddress
ps-sso-uid objectId

Screenshot shows the akamai header app mapping.

通过选择创建的自定义 HTTP 类型 Web 应用程序的 Akamai URL 来测试应用程序。

Screenshot shows the akamai header app results.

选项 2:OpenID Connect

本示例将使用 ASP.NET MVC Web 应用,该应用通过使用 .NET (OWIN) 中间件的开放式 Web 接口和 Microsoft 标识平台来让用户登录。

  1. 在前面的步骤所创建的 Aure AD B2C SAML IdP 中配置 OIDC 与 SAML 之间的桥接。

    Screenshot shows the akamai oidc app oidc settings.

  2. 按照为访问应用程序配置 OpenID Connect 中所述的内容创建自定义 HTTP 类型应用程序。

  3. 在“身份验证”中为 HTTP 标头应用程序选择在前面的步骤中创建的 Azure AD B2C SAML IdP。

    Screenshot shows the akamai authn app settings.

  4. 在“高级”中选择“OpenID Connect 1.0”作为身份验证机制,然后选择“保存”。

    Screenshot shows the akamai oidc app authentication settings.

  5. 此时会显示一个新的“OpenID”选项卡,复制发现 URL,后续在为测试应用程序配置 OWIN 组件时需要使用它。

    Screenshot shows the akamai oidc app settings.

  6. 在“声明”部分中,定义 Akamai 将为 OIDC 应用程序发出的声明,并在身份验证成功后将它们的值映射至 Azure AD B2C 在 SAML 响应中提供的 SAML 特征。 这些声明需要映射在前面的步骤(在 Azure AD B2C SAML IdP 中配置 OIDC 与 SAML 之间的桥接)中定义的内容。

    Screenshot shows the akamai oidc app claim settings.

  7. 将启动类替换为 ASP.NET MVC Web 应用中的以下代码。

    这些更改配置了授权代码流授权,系统将在应用程序的令牌终结点兑换授权代码以获取令牌,并引入元数据地址来设置用于从 Akamai 获取元数据的发现终结点。

    public class Startup
    {
         // The Client ID is used by the application to uniquely identify itself to Azure AD.
         string clientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"];
    
         //App Client Secret to redeem the code for an access token
         string ClientSecret = System.Configuration.ConfigurationManager.AppSettings["ClientSecret"];
    
         // RedirectUri is the URL where the user will be redirected to after they sign in.
         string redirectUri = System.Configuration.ConfigurationManager.AppSettings["RedirectUri"];
    
         // PostLogoutRedirectUri is the URL where the user will be redirected to after they sign out
         string PostLogoutRedirectUri = System.Configuration.ConfigurationManager.AppSettings["PostLogoutRedirectUri"];
    
         //Authority is the URL for authority
         string authority = System.Configuration.ConfigurationManager.AppSettings["Authority"];
    
         //discovery endpoint for obtaining metadata
         string MetadataAddress = System.Configuration.ConfigurationManager.AppSettings["MetadataAddress"];
    
    
         /// <summary>
         /// Configure OWIN to use OpenIdConnect
         /// </summary>
         /// <param name="app"></param>
         public void Configuration(IAppBuilder app)
       {
         app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    
         app.UseCookieAuthentication(new CookieAuthenticationOptions());
         app.UseOpenIdConnectAuthentication(
             new OpenIdConnectAuthenticationOptions
             {
                 // Sets the ClientId, authority, RedirectUri as obtained from web.config
                 ClientId = clientId,
                 Authority = authority,
                 RedirectUri = redirectUri,
                 MetadataAddress = MetadataAddress,
                 // PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
                 PostLogoutRedirectUri = redirectUri,
                 RedeemCode = true,
                 Scope = OpenIdConnectScope.OpenIdProfile,
                 // ResponseType is set to request the code id_token - which contains basic information about the signed-in user
                 ResponseType = OpenIdConnectResponseType.Code,
                  // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
                 Notifications = new OpenIdConnectAuthenticationNotifications
                 {
                     AuthenticationFailed = OnAuthenticationFailed
                 }
             }
         );
     }
    
     /// <summary>
     /// Handle failed authentication requests by redirecting the user to the home page with an error in the query string
     /// </summary>
     /// <param name="context"></param>
     /// <returns></returns>
     private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
     {
         context.HandleResponse();
         context.Response.Redirect("/?errormessage=" + context.Exception.Message);
         return Task.FromResult(0);
        }
    }
    
  8. web.config 文件中添加元数据地址,并在 appSettings 中使用 Akamai 应用程序中的值替换 clientId、clientsecret、authority、redirectUri 和 PostLogoutRedirectUri。

    可在前文步骤 5 中 HTTP Akamai 应用程序的“OpenID”选项卡(创建 Discovery URL=MetadataAddress 的位置)中找到这些值。 redirectUri 是 Akamai 连接器解析为本地 OIDC 应用程序的本地地址。 Authority 是可从.well-known/openid-configuration文档中找到的 authorization_endpoint。

    发现 URL:https://fabrikam.login.go.akamai-access.com/.well-known/openid-configuration

     <appSettings>
       <add key="ClientId" value="xxxxxxxxxxxxxxxxxx" />
       <add key="ClientSecret" value="xxxxxxxxxxxxxxxxxx" />
       <add key="Authority" value="https://fabrikam.login.go.akamai-access.com/oidc/oauth" />
       <add key="redirectUri" value="http://oidcapp.identity.mistermik.com/" />
       <add key="PostLogoutRedirectUri" value="https://oidc-test.go.akamai-access.com/" />
       <add key="MetadataAddress" value="https://fabrikam.login.go.akamai-access.com/.well-known/openid-configuration" />
     </appSettings>
    

    通过选择创建的自定义 HTTP 类型 Web 应用程序的 Akamai URL 来测试应用程序。

    Screenshot shows the akamai oidc app results.

测试解决方案

  1. 使用 Akamai 企业应用程序访问中指定的外部 URL 导航到应用程序 URL。

  2. 未经身份验证的用户将重定向到 Azure AD B2C 登录页。

  3. 在该页面上从列表中选择 IdP。

  4. 使用链接到 Azure AD B2C 的凭据以最终用户身份登录。

  5. 身份验证成功后,最终用户将被重定向回应用程序,并作为最终用户登录到应用程序。

其他资源