我使用的是ForgeRock v7.1.0,运行在MacOS 11.5.2 (Big )上的Dockerv3.6.0中。
我正在尝试交换一个JWT2.0访问令牌(subject令牌),我已经检索到它是一个ID令牌(带有一个JWT ),每次我调用它时,它都会给我一个错误,特别是我相信它与OAuth参数有关。
我现在采取的步骤如下:
curl --location --request POST 'http://am.example.com:8080/am/oauth2/realms/root/access_token' \
--header 'Authorization: Basic c3RldmU6cGFzc3dvcmQ=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=user1' \
--data-urlencode 'password=7fYCi0Frhcq5p3gCXGxJ2B' \
--data-urlencode 'scope=cn'返回以下内容:
{
"access_token": "BS8vVbJ4EEygzdEE3jQH-xsKW9w",
"scope": "cn",
"token_type": "Bearer",
"expires_in": 3599
}curl --location --request POST 'http://am.example.com:8080/am/oauth2/realms/root/introspect?token=BS8vVbJ4EEygzdEE3jQH-xsKW9w' \
--header 'Authorization: Basic c3RldmU6cGFzc3dvcmQ='返回以下内容:
{
"active": true,
"scope": "cn",
"realm": "/",
"client_id": "steve",
"user_id": "user1",
"token_type": "Bearer",
"exp": 1629990663,
"sub": "(usr!user1)",
"subname": "user1",
"iss": "http://am.example.com:8080/am/oauth2",
"auth_level": 0,
"authGrantId": "whjnenzHCH96TyaxfuefiOcBfm8",
"auditTrackingId": "4d353b7e-6cd5-4289-884a-39c50396ed0c-116027"
}现在,当我尝试交换令牌:
时,这就是我得到错误的地方
curl --location --request POST 'http://am.example.com:8080/am/oauth2/realms/root/access_token' \
--header 'Authorization: Basic c3RldmU6cGFzc3dvcmQ=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
--data-urlencode 'subject_token_type=urn:ietf:params:oauth:token-type:access_token' \
--data-urlencode 'subject_token=BS8vVbJ4EEygzdEE3jQH-xsKW9w' \
--data-urlencode 'scope=cn' \
--data-urlencode 'requested_token_type=urn:ietf:params:oauth:token-type:id_token'这给了我一个错误:
{
"error_description": "Invalid token exchange.",
"error": "invalid_request"
}如果我没有指定subject_token_type,它反而给出了错误:
{
"error_description": "Subject token type is required.",
"error": "invalid_request"
}这让我相信,要么我使用了错误的类型,要么在我的本地ForgeRock实例中没有正确地设置一些东西。
我看过这里描述的错误响应可能性:https://backstage.forgerock.com/docs/am/7.1/oauth2-guide/token-exchange-flows.html,但是它没有那么大的帮助。
任何感激的帮助!谢谢史蒂夫
发布于 2021-08-26 14:47:44
哈!总是这样,在发布了一个问题后,你设法解决它!
好吧,这就是我需要做的:
import org.forgerock.json.JsonValue
token.setMayAct(
JsonValue.json(JsonValue.object(
JsonValue.field("client_id", "steve"),
JsonValue.field("sub", "(usr!user1)"))))https://stackoverflow.com/questions/68940329
复制相似问题