@@ -663,6 +663,120 @@ the following::
663663 }
664664 }
665665
666+ ==============
667+ Token exchange
668+ ==============
669+ There are two possible ways to configure Token Exchange in OIDC-OP, globally and per-client.
670+ For the first case the configuration is passed in the Token Exchange handler throught the
671+ `urn:ietf:params:oauth:grant-type:token-exchange ` dictionary in token's `grant_types_supported `.
672+
673+ If present, the token exchange configuration must contain a `policy ` object that describes a default
674+ policy `callable ` and its `kwargs ` through the `"" ` key. Different callables can be optionally
675+ defined for each token type supported.
676+
677+ ```
678+ "grant_types_supported":{
679+ "urn:ietf: params:oauth: grant-type:token-exchange": {
680+ "class": "oidcop.oidc.token.TokenExchangeHelper",
681+ "kwargs": {
682+ "subject_token_types_supported": [
683+ "urn:ietf: params:oauth: token-type:access_token",
684+ "urn:ietf: params:oauth: token-type:refresh_token",
685+ "urn:ietf: params:oauth: token-type:id_token"
686+ ],
687+ "requested_token_types_supported": [
688+ "urn:ietf: params:oauth: token-type:access_token",
689+ "urn:ietf: params:oauth: token-type:refresh_token",
690+ "urn:ietf: params:oauth: token-type:id_token"
691+ ],
692+ "policy": {
693+ "urn:ietf: params:oauth: token-type:access_token": {
694+ "callable": "/path/to/callable",
695+ "kwargs": {
696+ "audience": ["https://example.com"],
697+ "scopes": ["openid"]
698+ }
699+ },
700+ "urn:ietf: params:oauth: token-type:refresh_token": {
701+ "callable": "/path/to/callable",
702+ "kwargs": {
703+ "resource": ["https://example.com"],
704+ "scopes": ["openid"]
705+ }
706+ },
707+ "": {
708+ "callable": "/path/to/callable",
709+ "kwargs": {
710+ "scopes": ["openid"]
711+ }
712+ }
713+ }
714+ }
715+ }
716+ }
717+ ```
718+
719+ For the per-client configuration a similar configuration scheme should be present in the client's
720+ metadata under the `token_exchange ` key.
721+
722+ For example:
723+
724+ ```
725+ "token_exchange":{
726+ "urn:ietf: params:oauth: grant-type:token-exchange": {
727+ "class": "oidcop.oidc.token.TokenExchangeHelper",
728+ "kwargs": {
729+ "subject_token_types_supported": [
730+ "urn:ietf: params:oauth: token-type:access_token",
731+ "urn:ietf: params:oauth: token-type:refresh_token",
732+ "urn:ietf: params:oauth: token-type:id_token"
733+ ],
734+ "requested_token_types_supported": [
735+ "urn:ietf: params:oauth: token-type:access_token",
736+ "urn:ietf: params:oauth: token-type:refresh_token",
737+ "urn:ietf: params:oauth: token-type:id_token"
738+ ],
739+ "policy": {
740+ "urn:ietf: params:oauth: token-type:access_token": {
741+ "callable": "/path/to/callable",
742+ "kwargs": {
743+ "audience": ["https://example.com"],
744+ "scopes": ["openid"]
745+ }
746+ },
747+ "urn:ietf: params:oauth: token-type:refresh_token": {
748+ "callable": "/path/to/callable",
749+ "kwargs": {
750+ "resource": ["https://example.com"],
751+ "scopes": ["openid"]
752+ }
753+ },
754+ "": {
755+ "callable": "/path/to/callable",
756+ "kwargs": {
757+ "scopes": ["openid"]
758+ }
759+ }
760+ }
761+ }
762+ }
763+ }
764+ ```
765+
766+ The policy callable accepts a specific argument list and must return the altered token exchange
767+ request or raise an exception.
768+
769+ For example:
770+
771+ ```
772+ def custom_token_exchange_policy(request, context, subject_token, **kwargs):
773+ if some_condition in request:
774+ return TokenErrorResponse(
775+ error="invalid_request", error_description="Some error occured"
776+ )
777+
778+ return request
779+ ```
666780
667781=======
668782Clients
0 commit comments