To configure Workforce Identity Federation with OIDC, register your OIDC application with an external identity provider, such as Okta or Microsoft Entra ID. This ensures secure authentication and facilitates user management.要使用OIDC配置劳动力身份联合,请向外部身份提供者(如Okta或Microsoft Entra ID)注册OIDC应用程序。这可确保安全身份验证并方便用户管理。
About this Task关于此任务
Workforce Identity Federation uses OIDC. You can use any external identity provider that supports the OIDC standard.劳动力身份联合会使用OIDC。您可以使用任何支持OIDC标准的外部身份提供程序。
You can configure your OIDC application for the following grant types:您可以为以下授权类型配置OIDC应用程序:
Authorization Code Flow with PKCE使用PKCE的授权码流Device Authorization Flow设备授权流程
MongoDB recommends that you use Authorization Code Flow with PKCE for increased security. Use Device Authorization Flow only if your users need to access the database from machines with no browser.MongoDB建议您将授权代码流与PKCE结合使用,以提高安全性。仅当用户需要从没有浏览器的计算机访问数据库时,才使用设备授权流。
Note
Workforce Identity Federation supports only JWT for authentication. It doesn't support opaque access tokens.Workforce Identity Federation仅支持JWT进行身份验证。它不支持不透明的访问令牌。
The following procedures provide detailed configuration instructions for Microsoft Entra ID and Okta, and generic configuration instructions for other external identity providers.以下过程提供了Microsoft Entra ID和Okta的详细配置说明,以及其他外部身份提供程序的通用配置说明。
Before you Begin开始之前
To use Okta as an identity provider, you must have an Okta account.要使用Okta作为身份提供者,您必须拥有Okta帐户。To use Microsoft Entra ID as an identity provider, you must have a Microsoft Azure account.若要将Microsoft Entra ID用作身份提供者,您必须拥有Microsoft Azure帐户。
Steps步骤
Microsoft Entra ID
Register an application注册应用程序
Navigate to App registrations.导航到应用程序注册。In your Azure portal account, search and click Microsoft Entra ID.在Azure门户帐户中,搜索并单击Microsoft Entra ID。In the Manage section of the left navigation, click App registrations.在左侧导航的管理部分,单击应用程序注册。
Click New registration.单击“新建注册”。Apply the following values.应用以下值。Field字段Value值Name名称MongoDB - WorkforceMongoDB-劳动力Supported Account Types支持的帐户类型Accounts in this organizational directory only (single tenant)仅此组织目录中的帐户(单个租户)Redirect URI重定向 URI- Public client/native (mobile & desktop)公共客户端/本地(移动和桌面)
-To access clusters using MongoDB Compass and MongoDB Shell, set the Redirect URI to要使用MongoDB Compass和MongoDB Shell访问集群,请将重定向URI设置为http://localhost:27097/redirect.http://localhost:27097/redirect。Click Register.单击“注册”。
To learn more about registering an application, see Azure Documentation.要了解有关注册应用程序的更多信息,请参阅Azure文档。
Add a group claim添加组索赔
Navigate to Token Configuration.导航到“令牌配置”。In the Manage section of the left navigation, click Token Configuration.在左侧导航的“管理”部分,单击“令牌配置”。Click Add groups claim.单击“添加组索赔”。In the Edit groups claim modal, select Security.在“编辑组声明”模式中,选择“安全”。What groups you select depend on the type of groups you configured in your Azure environment. You may need to select a different type of group to send the appropriate group information.您选择的组取决于您在Azure环境中配置的组类型。您可能需要选择其他类型的组来发送相应的组信息。In the Customize token properties by type section, only select Group ID.在“按类型自定义令牌属性”部分,仅选择“组ID”。Click Add.单击“添加”。
To learn more about adding a group claim, see Azure Documentation.要了解有关添加组声明的更多信息,请参阅Azure文档。
Add a user identifier claim to the access token将用户标识符声明添加到访问令牌中
Click Add optional claim.单击“添加可选索赔”。In the Add optional claim modal, select Access.在“添加可选声明”模式中,选择“访问”。Select a claim that carries a user identifier that you can refer to in MongoDB access logs such as an email.选择一个包含用户标识符的声明,您可以在MongoDB访问日志(如电子邮件)中引用该标识符。You can use the UPN claim to identify users with their email address.您可以使用UPN声明通过电子邮件地址识别用户。Click Add.单击“添加”。In the Microsoft Graph Permissions note, check the box, and click Add.在“Microsoft图形权限”注释中,选中该框,然后单击“添加”。
To learn more, see Azure Documentation.要了解更多信息,请参阅Azure文档。
Update the manifest更新清单
In the Manage section of the left navigation, click Manifest.在左侧导航的“管理”部分,单击“清单”。Update the requestedAccessTokenVersion from将nullto2.requestedAccessTokenVersion从null更新为2。The number数字2represents Version 2 of Microsoft's access tokens. Other applications can use this as a signed attestation of the Active Directory-managed user's identity.2代表微软访问令牌的版本2。其他应用程序可以将其用作活动目录管理用户身份的签名证明。Version 2 ensures that the token is a JSON Web Token that MongoDB understands.版本2确保令牌是MongoDB理解的JSON Web令牌。Click Save.单击“保存”。
To learn more about adding an optional claim, see Azure Documentation.要了解有关添加可选声明的更多信息,请参阅Azure文档。
Remember metadata记住元数据
In the left navigation, click Overview.在左侧导航中,单击“概述”。Copy the Application (client) ID value.复“制应用程序(客户端)ID”值。In the top navigation, click Endpoints.在顶部导航中,单击“端点”。Copy the OpenID Connect metadata document value without the复制“OpenID Connect元数据文档”值,但不包括部分。/.well-known/openid-configurationpart.You can also get this value by copying the value for您还可以通过复制OpenID Connect元数据文档URL中issuerin the OpenID Connect metadata document URL.issuer的值来获得此值。
The following table shows what these Microsoft Entra ID UI values map to in the MongoDB 下表显示了这些Microsoft Entra ID UI值在MongoDB oidcIdentityProviders parameter:oidcIdentityProviders参数中的映射:
| Microsoft Entra ID UI | MongoDB oidcIdentityProviders Parameter Field |
|---|---|
clientIDaudience | |
issuer |
Okta
Create an application in Okta在Okta中创建应用程序
In your Okta Admin dashboard, use the left navigation pane to go to Applications → Applications.在Okta管理仪表板中,使用左侧导航窗格转到应用程序应用程序。
On the Applications screen, click Create App Integration.在“应用程序”屏幕上,单击“创建应用程序集成”。In the Sign-in method section, select OIDC - OpenID Connect.在登录方法部分,选择“OIDC-OpenID Connect”。In the Application type section, select Native Application.在“应用程序类型”部分,选择“本机应用程序”。Click Next.单击“下一步”。
To learn more, see Create OIDC app Integrations.要了解更多信息,请参阅创建OIDC应用程序集成。
Configure your New Native App Integration配置新的本地应用程序集成
After you create an app integration, you are automatically redirected to the New Native App Integration screen.创建应用程序集成后,您将自动重定向到“新建本地应用程序集成”屏幕。
In the App integration name field, enter a name for your application.在应用程序集成名称字段中,输入应用程序的名称。In the Grant type field, select grant types.在“资助类型”字段中,选择资助类型。Enable the following grant types:启用以下授权类型:Authorization Code or Device Authorization授权码或设备授权(Optional) Refresh Token(可选)刷新令牌Enabling refresh tokens provides a better user experience. When refresh tokens are not enabled, users must re-authenticate with the identity provider once their access token expires.启用刷新令牌可提供更好的用户体验。当未启用刷新令牌时,一旦用户的访问令牌过期,他们必须重新向身份提供程序进行身份验证。
In the Sign-in redirect URIs section, enter a URL.在“登录重定向URI”部分,输入URL。Enter the following URL:输入以下URL:http://localhost:27097/redirect.In the Assignments section, configure the Controlled access and Enable immediate access fields.在“分配”部分,配置“受控访问”和“启用立即访问”字段。For the Controlled access field, select Allow everyone in your organization to access.在“受控访问”字段中,选择“允许组织中的所有人访问”。For Enable immediate access field, ensure Enable immediate access with Federation Broker Mode is checked.对于“启用立即访问”字段,请确保选中了“使用联合身份验证代理模式启用即时访问”。
Click Save.单击“保存”。
To learn more, see Create OIDC app integrations.要了解更多信息,请参阅创建OIDC应用程序集成。
Configure PKCE and obtain client ID配置PKCE并获取客户端ID
On your application dashboard, go to the General tab and configure the following:在应用程序仪表板上,转到“常规”选项卡并配置以下内容:
In the Client ID field, click the icon to copy the client ID for later use.在客户端ID字段中,单击图标复制客户端ID以供以后使用。In the Proof Key for Code Exchange (PKCE) field, ensure Require PKCE as additional verification is enabled (checked by default).在代码交换的证明键(PKCE)字段中,确保启用了“要求PKCE作为额外验证”(默认选中)。
Add an authorization server添加授权服务器
In the left navigation pane, go to Security → API. Click Add Authorization Server.在左侧导航窗格中,转到“Security → API”。单击“添加授权服务器”。
In the Name field, enter a name for your server.在“名称”字段中,输入服务器的名称。In the Audience field, paste the client ID from the previous step.在“Audience”字段中,粘贴上一步中的客户端ID。(Optional) In the Description field, enter a description of your server.(可选)在“描述”字段中,输入服务器的描述。Click Save.单击“保存”。
To learn more, see Create an Authorization Server.要了解更多信息,请参阅创建授权服务器。
Find and save the issuer URI查找并保存颁发者URI
After you create your authorization server, you are automatically redirected to your authorization server's screen.创建授权服务器后,您将自动重定向到授权服务器的屏幕。
Under the Settings tab, save the issuer URI by copying the first part of the Metadata URI up to the 在“设置”选项卡下,通过将“元数据URI”的第一部分复制到.well-known section. .well-known部分来保存颁发者URI。The URI structure should be similar to: URI结构应类似于:https://trial4238026.okta.com/oauth2/ausabgmhveoOQSMsE697.https://trial4238026.okta.com/oauth2/ausabgmhveoOQSMsE697。
Add Groups claim添加“组”声明
On your authorization server screen, go to the Claims tab and click Add Claim.在授权服务器屏幕上,转到“声明”选项卡,然后单击“添加声明”。
Configure Groups claim with the following configuration information:使用以下配置信息配置“组”声明:Field字段Value值Name名称Enter a name for your claim.为索赔输入一个名称。Include in token type包含在令牌类型中Click the drop-down and select Access Token.单击下拉列表并选择访问令牌。Value type值类型Click the drop-down and select Groups.单击下拉列表并选择“组”。Filter筛选器Click the drop-down and select Matches regex. Next to the drop-down, enter单击下拉列表并选择“匹配正则表达式”。在下拉列表旁边,输入.*..*。Disable claim禁用索赔Do not check.不要检查。Include in包含在Select Any scope.选择“任意范围”。Click Create.单击“创建”。
To learn more, see Create Claims.要了解更多信息,请参阅创建索赔。
Create an access policy创建访问策略
On your authorization server screen, go to the Access Policies tab and click Add Policy.在授权服务器屏幕上,转到“访问策略”选项卡,然后单击“添加策略”。
In the Name field, enter a policy name.在“名称”字段中,输入策略名称。In the Description field, enter a description for the policy.在“描述”字段中,输入策略的描述。In the Assign to field, select All clients.在“分配给”字段中,选择“所有客户端”。Click Create Policy.单击“创建策略”。
To learn more, see Create an Access Policy.要了解更多信息,请参阅创建访问策略。
Create a rule for the access policy为访问策略创建规则
Under the Access Policies tab, click Add Rule.在“访问策略”选项卡下,单击“添加规则”。
In the Rule Name field, enter a name for the access policy.在“规则名称”字段中,输入访问策略的名称。For IF Grant Type is, select a grant type.如果“补助类型”为,请选择一种补助类型。When configuring grant types, select the appropriate option based on the client behavior:配置授权类型时,根据客户端行为选择适当的选项:If the client is acting on behalf of itself, select Client Credentials.如果客户端代表自己行事,请选择“客户端凭据”。If the client is acting on behalf of a user, select the following:如果客户端代表用户行事,请选择以下选项:Authorization Code授权码Device Authorization设备授权
Add rule configurations based on your organization's security policy.根据组织的安全策略添加规则配置。Example Okta rule configuration:Okta规则配置示例:Field字段Value值AND user isAND用户是Select Any user assigned to the app.选择“分配给应用程序的任何用户”。AND Scopes requested要求的范围Select Any scopes.选择“任意范围”。THEN Use this inline hook然后使用这个内联钩子None (disabled)无(禁用)AND Access token lifetime isAND访问令牌寿命为1 Hours1小时AND Refresh token lifetime isAND刷新令牌生存期为Click the second drop-down and select Unlimited.单击第二个下拉列表并选择Unlimited。but will expire if not used every但如果不是每次使用都会过期Enter 7 days.输入7天。Click Create Rule.单击“创建规则”。
To learn more, see Create Rules for each Access Policy.要了解更多信息,请参阅为每个访问策略创建规则。
Create a group创建组
In the left navigation pane, go to Directory → Groups and click Add Group.在左侧导航窗格中,转到“目录 → 组”,然后单击“添加组”。
In the Name field, name your directory在“名称”字段中,将目录命名为OIDC.OIDC。(Optional) In the Description field, enter a description for your rule.(可选)在“描述”字段中,输入规则的描述。Click Save.单击“保存”。
To learn more, see Create a Group.要了解更多信息,请参阅创建组。
Add a user to your organization将用户添加到组织
In the left navigation pane, go to Directory → People and click Add Person.在左侧导航窗格中,转到“目录 → 人员”,然后单击“添加人员”。
Provide user details by entering the following values in the corresponding fields:
Field字段Value User type用户类型Select User.选择“用户”。First name名字Provide name as needed.根据需要提供名称。Last name姓氏Provide name as needed.根据需要提供名称。Username用户名Enter an email as a username.输入电子邮件作为用户名。Primary email主要邮箱Enter an email. The email must be same as the one used for the Username field.输入电子邮件。电子邮件必须与用户名字段中使用的电子邮件相同。Secondary email备用邮箱Optional.可选。Groups群组Enter OIDC.输入OIDC。Activation激活Select Activate Now and check I will set password.选择“立即激活”并选中“我将设置密码”。Password密码Enter a password.输入密码。User must change password on first login用户必须在首次登录时更改密码Select Optional Click Save.单击“保存”。
To learn more, see Add Users Manually.要了解更多信息,请参阅手动添加用户。
Generic
Register a new application for MongoDB为MongoDB注册新应用程序
Select public client/native application as the client type.选择公共客户端/本机应用程序作为客户端类型。
(Conditional) Add or enable a groups claim if you authenticate with groups(有条件)如果您对组进行身份验证,则添加或启用“组”声明
For groups, this step ensures that your access tokens contain the group membership information of the user authenticating. MongoDB uses the values sent in a groups claim for authorization.对于组,此步骤可确保访问令牌包含进行身份验证的用户的组成员信息。MongoDB使用组声明中发送的值进行授权。
(Optional) Allow refresh tokens if you want MongoDB clients to refresh the tokens for a better user experience(可选)如果您希望MongoDB客户端刷新令牌以获得更好的用户体验,请允许刷新令牌
(Optional) Configure the access token lifetime ((可选)配置访问令牌生存期(exp声明)以与数据库连接会话时间对齐exp claim) to align with your database connection session time
After you register your application, save the 注册应用程序后,保存issuer, clientId, and audience values to use in the next stage of the configuration.issuer、clientId和audience值,以便在配置的下一阶段使用。