You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Liberty OIDC Provider中映射basicRegistry到JWT的preferred_username

在Liberty本地开发环境中为OIDC Provider添加preferred_username声明

我正在将Liberty配置为OIDC Provider,用于本地开发环境,因此希望避免完整的LDAP配置,已搭建如下最小化配置:

<server description="myServer">

    <basicRegistry id="basic" realm="customRealm">
        <user name="myTestUser" password="test"/>
    </basicRegistry>

    ...
    

    <openidConnectClient id="RS" inboundPropagation="required"
                         clientId="my-api"
                         clientSecret="mySecret"
                         scope="openid profile email"
                         jwkEndpointUrl="https://localhost:9443/oidc/endpoint/my-oidc/jwk"
                         issuerIdentifier="https://localhost:9443/oidc/endpoint/my-oidc"
                         validationEndpointUrl="https://localhost:9443/oidc/endpoint/my-oidc/introspect">
    </openidConnectClient>

    <openidConnectProvider id="my-oidc"
                           oauthProviderRef="OAuthConfig"
                           keyStoreRef="defaultKeyStore">
    </openidConnectProvider>
    <oauthProvider id="OAuthConfig" jwtAccessToken="true" tokenFormat="jwt">
        <localStore>
            <client name="my-api" secret="mySecret"
                    displayname="my-api"
                    scope="openid profile email"
                    preAuthorizedScope="openid profile email"
                    jwkEnabled="true"
                    allowRegexpRedirects="true"
                    enabled="true">
                <redirect>....</redirect>
        </client>
        </localStore>
    </oauthProvider>
</server>

请求令牌后返回的JWT内容如下:

{
  "sub": "myTestUser",
  "token_type": "Bearer",
  "scope": [
    "openid",
    "profile",
    "email"
  ],
  "azp": "my-api",
  "iss": "https://localhost:9443/oidc/endpoint/my-oidc",
  "exp": 1697713877,
  "iat": 1697706677,
  "realmName": "customRealm",
  "uniqueSecurityName": "myTestUser"
}

为使开发环境与生产环境的实现一致,需要添加preferred_username声明,其值与uniqueSecurityName或sub(即basicRegistry中的用户名)相同。我尝试使用claimToUserRegistryMap进行映射,但未成功,尝试过以下配置均无效:

<openidConnectProvider id="my-oidc"
                       oauthProviderRef="OAuthConfig"
                       keyStoreRef="defaultKeyStore"
                       customClaims="preferred_username">
    <claimToUserRegistryMap preferred_username="name" />
<!--    Tried alternatives-->
<!--    <claimToUserRegistryMap preferred_username="sub" />-->
<!--    <claimToUserRegistryMap preferred_username="username" />-->
<!--    <claimToUserRegistryMap preferred_username="uniqueSecurityName" />-->
</openidConnectProvider>

查阅文档后仍未找到解决方法,希望有人能指点方向。

内容的提问来源于stack exchange,提问作者Benjamin K.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 02:28:11