OpenID Connect Token Exchange
Presentation
Token exchange is the process of using a set of credentials or token to obtain
an entirely different token, for example to get access to an application not
included in current access_token.
Available Token Exchange systems
Tip
The Lemonldap::NG::Portal::Lib::OIDCTokenExchange base class allow
developers to easily write some other token exchange systems. See
its manpage.
Internal Token Exchange
LemonLDAP::NG provide an internal OIDC token exchange system that allows an OIDC relying party to ask for an access_token available for another.
Configuration
The only thing to configure is to add a list of Relying Party authorized to ask for an access_token into the destination Relying Party. This list contains a space separated of Relying Party names (use the internal LemonLDAP::NG name, not the client ID): “OpenID Connect Relying Party » dest » Options » Advanced » Other RP allowed to exchange access_token”.
How to use it
Request parameters:
Authentication (RP source):
client_id: the client identifierclient_secretif client isn’t publicsubject_token: the currentaccess_token
Oauth2 parameters:
grant_typemust beurn:ietf:params:oauth:grant-type:token-exchangesubject_token_type(optional), onlyurn:ietf:params:oauth:token-type:access_tokenis supported hererequested_token_type(optional), onlyurn:ietf:params:oauth:token-type:access_tokenis supported here
Target:
audience(optional): the client identifier of the target (not the internal LemonLDAP::NG name). If missing, the target is the requesting Relying Partyresource(optional, RFC 8707): an audience of the target, i.e. its client identifier or one of its additional audiences (“Options » Advanced » Additional audiences”)
RFC 8693 allows several audience parameters and RFC 8707 allows several
resource parameters. Repeating the same value has no effect, but:
an exchanged token is issued for a single target: when several different
audiencevalues are given, the request is rejected withinvalid_targeteach
resourcevalue must be an audience of the target, else the request is rejected withinvalid_target. Resources do not restrict the issued token: its audience is always the one of the target
These errors are answered with a 400 HTTP status and a JSON body (RFC 6749
section 5.2), for example:
{"error":"invalid_target","error_description":"several audiences requested"}
The requested values are not copied into the response, they are only logged.
Exemple:
curl -X POST \
-d "client_id=clientIdSrc" \
--data-urlencode "client_secret=ClientSecretSrc" \
--data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
--data-urlencode "subject_token=accessTokenString" \
--data-urlencode "requested_token_type=urn:ietf:params:oauth:token-type:access_token" \
-d "audience=target-client" \
http://auth.example.com/oauth2/token
Scope and access rule
The exchanged token never gets more than the subject_token (RFC 8693):
the
scopeparameter is optional. By default, the scope of thesubject_tokenis requested. Requested scopes not granted to thesubject_tokenare removed, then the scope rules of the target apply as in the authorization code flow. Scopes added by these rules are kept only if thesubject_tokenhas them. If no scope remains, the request is rejected withinvalid_scope. When the granted scope differs from the requested one, it is returned in thescopefield of the responsethe access rule of the target is evaluated, with
$_oidc_grant_typeset totokenexchange. If it denies the user, the request is rejected withinvalid_targetwhenaudienceorresourcewas given, else withinvalid_requestwhen the
subject_tokenis tied to a SSO session, the exchanged tokens are tied to the same session: they are no longer valid after logout. Otherwise (subject_tokenobtained from an offline refresh token), the exchanged refresh token is not tied to any SSO session and is handled as an offline one: “Allow offline access” must be enabled on the target, else the request is rejected withinvalid_grant. Its lifetime is however the SSO session timeout, not the offline session expiration of the target
Actor claim
When a token is exchanged for another client, the tokens issued by the token
exchange contain an act claim identifying the client that requested the
exchange, as described in RFC 8693 section 4.1:
{
"sub": "alice",
"aud": "target-client",
"act": { "sub": "clientIdSrc" }
}
If the subject_token already contains an act claim, it is nested to
keep the delegation chain:
{
"act": {
"sub": "clientIdSrc",
"act": { "sub": "previousActor" }
}
}
The claim is present in JWT access tokens and in the introspection response of the issued access tokens (JWT or opaque), and it is kept when the refresh token is used. It is never taken from a user attribute.
No new actor is added when the client exchanges a token for itself, since this is not a delegation: an existing delegation chain is preserved. The target is another client when the audience is the Client-ID of another relying party.
The delegation chain contains at most 10 actors: a request that would exceed
this limit, or whose subject token carries a malformed chain, is rejected with
an invalid_request error.