如何在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.
相关产品推荐
相关产品推荐

