@@ -39,7 +39,7 @@ def __init__(
3939 actor_token_source : typing .Optional [TokenSource ] = None ,
4040 audience : typing .Union [typing .List [str ], str , None ] = None ,
4141 scope : typing .Union [typing .List [str ], str , None ] = None ,
42- resource : typing .Optional [ str ] = None ,
42+ resource : typing .Union [ typing . List [ str ], str , None ] = None ,
4343 grant_type : str = "urn:ietf:params:oauth:grant-type:token-exchange" ,
4444 requested_token_type : str = "urn:ietf:params:oauth:token-type:access_token" ,
4545 ):
@@ -224,6 +224,42 @@ def _duration_seconds_from_config(cls, cfg_json, key_name, default_value):
224224
225225 @classmethod
226226 def from_file (cls , cfg_file , iam_endpoint = None ):
227+ """
228+ Create OAuth 2.0 token exchange protocol credentials from config file.
229+
230+ https://www.rfc-editor.org/rfc/rfc8693
231+ Config file must be a valid json file
232+
233+ Fields of json file
234+ grant-type: [string] Grant type option (default: "urn:ietf:params:oauth:grant-type:token-exchange")
235+ res: [string | list of strings] Resource option (optional)
236+ aud: [string | list of strings] Audience option for token exchange request (optional)
237+ scope: [string | list of strings] Scope option (optional)
238+ requested-token-type: [string] Requested token type option (default: "urn:ietf:params:oauth:token-type:access_token")
239+ subject-credentials: [creds_json] Subject credentials options (optional)
240+ actor-credentials: [creds_json] Actor credentials options (optional)
241+ token-endpoint: [string] Token endpoint
242+
243+ Fields of creds_json (JWT):
244+ type: [string] Token source type. Set JWT
245+ alg: [string] Algorithm for JWT signature.
246+ Supported algorithms can be listed
247+ with GetSupportedOauth2TokenExchangeJwtAlgorithms()
248+ private-key: [string] (Private) key in PEM format (RSA, EC) or Base64 format (HMAC) for JWT signature
249+ kid: [string] Key id JWT standard claim (optional)
250+ iss: [string] Issuer JWT standard claim (optional)
251+ sub: [string] Subject JWT standard claim (optional)
252+ aud: [string | list of strings] Audience JWT standard claim (optional)
253+ jti: [string] JWT ID JWT standard claim (optional)
254+ ttl: [string] Token TTL (default: 1h)
255+
256+ Fields of creds_json (FIXED):
257+ type: [string] Token source type. Set FIXED
258+ token: [string] Token value
259+ token-type: [string] Token type value. It will become
260+ subject_token_type/actor_token_type parameter
261+ in token exchange request (https://www.rfc-editor.org/rfc/rfc8693)
262+ """
227263 with open (os .path .expanduser (cfg_file ), "r" ) as r :
228264 cfg = r .read ()
229265
@@ -245,7 +281,7 @@ def from_content(cls, cfg, iam_endpoint=None):
245281 actor_token_source = cls ._token_source_from_config (cfg_json , "actor-credentials" )
246282 audience = cls ._list_of_strings_or_single_from_config (cfg_json , "aud" )
247283 scope = cls ._list_of_strings_or_single_from_config (cfg_json , "scope" )
248- resource = cls ._string_with_default_from_config (cfg_json , "res" , None )
284+ resource = cls ._list_of_strings_or_single_from_config (cfg_json , "res" )
249285 grant_type = cls ._string_with_default_from_config (
250286 cfg_json , "grant-type" , "urn:ietf:params:oauth:grant-type:token-exchange"
251287 )
@@ -273,7 +309,7 @@ def __init__(
273309 actor_token_source : typing .Optional [TokenSource ] = None ,
274310 audience : typing .Union [typing .List [str ], str , None ] = None ,
275311 scope : typing .Union [typing .List [str ], str , None ] = None ,
276- resource : typing .Optional [ str ] = None ,
312+ resource : typing .Union [ typing . List [ str ], str , None ] = None ,
277313 grant_type : str = "urn:ietf:params:oauth:grant-type:token-exchange" ,
278314 requested_token_type : str = "urn:ietf:params:oauth:token-type:access_token" ,
279315 tracer = None ,
0 commit comments