@@ -39,7 +39,7 @@ def __init__(
39
39
actor_token_source : typing .Optional [TokenSource ] = None ,
40
40
audience : typing .Union [typing .List [str ], str , None ] = None ,
41
41
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 ,
43
43
grant_type : str = "urn:ietf:params:oauth:grant-type:token-exchange" ,
44
44
requested_token_type : str = "urn:ietf:params:oauth:token-type:access_token" ,
45
45
):
@@ -224,6 +224,42 @@ def _duration_seconds_from_config(cls, cfg_json, key_name, default_value):
224
224
225
225
@classmethod
226
226
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
+ """
227
263
with open (os .path .expanduser (cfg_file ), "r" ) as r :
228
264
cfg = r .read ()
229
265
@@ -245,7 +281,7 @@ def from_content(cls, cfg, iam_endpoint=None):
245
281
actor_token_source = cls ._token_source_from_config (cfg_json , "actor-credentials" )
246
282
audience = cls ._list_of_strings_or_single_from_config (cfg_json , "aud" )
247
283
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" )
249
285
grant_type = cls ._string_with_default_from_config (
250
286
cfg_json , "grant-type" , "urn:ietf:params:oauth:grant-type:token-exchange"
251
287
)
@@ -273,7 +309,7 @@ def __init__(
273
309
actor_token_source : typing .Optional [TokenSource ] = None ,
274
310
audience : typing .Union [typing .List [str ], str , None ] = None ,
275
311
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 ,
277
313
grant_type : str = "urn:ietf:params:oauth:grant-type:token-exchange" ,
278
314
requested_token_type : str = "urn:ietf:params:oauth:token-type:access_token" ,
279
315
tracer = None ,
0 commit comments