@@ -23,7 +23,7 @@ def __init__(
2323 server_configuration , # type: dict
2424 client_id , # type: str
2525 client_secret = None , # type: Optional[str]
26- client_assertion = None , # type: Optional[str ]
26+ client_assertion = None , # type: Optional[bytes ]
2727 client_assertion_type = None , # type: Optional[str]
2828 default_headers = None , # type: Optional[dict]
2929 default_body = None , # type: Optional[dict]
@@ -45,8 +45,10 @@ def __init__(
4545 https://example.com/.../.well-known/openid-configuration
4646 client_id (str): The client's id, issued by the authorization server
4747 client_secret (str): Triggers HTTP AUTH for Confidential Client
48- client_assertion (str ):
48+ client_assertion (bytes ):
4949 The client assertion to authenticate this client, per RFC 7521.
50+ If it is a SAML assertion, you need to encode it beforehand, by:
51+ base64.urlsafe_b64encode(assertion).strip(b'=')
5052 client_assertion_type (str):
5153 The format of the client_assertion.
5254 If you leave it as the default None, this method will try to make
@@ -70,7 +72,7 @@ def __init__(
7072 if client_assertion_type is None : # RFC7521 defines only 2 profiles
7173 TYPE_JWT = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
7274 TYPE_SAML2 = "urn:ietf:params:oauth:client-assertion-type:saml2-bearer"
73- client_assertion_type = TYPE_JWT if "." in client_assertion else TYPE_SAML2
75+ client_assertion_type = TYPE_JWT if b "." in client_assertion else TYPE_SAML2
7476 self .default_body ["client_assertion" ] = client_assertion
7577 self .default_body ["client_assertion_type" ] = client_assertion_type
7678 self .logger = logging .getLogger (__name__ )
@@ -410,11 +412,13 @@ def obtain_token_by_refresh_token(self, token_item, scope=None,
410412
411413 def obtain_token_by_assertion (
412414 self , assertion , grant_type = None , scope = None , ** kwargs ):
413- # type: (str , Union[str, None], Union[str, list, set, tuple]) -> dict
415+ # type: (bytes , Union[str, None], Union[str, list, set, tuple]) -> dict
414416 """This method implements Assertion Framework for OAuth2 (RFC 7521).
415417 See details at https://tools.ietf.org/html/rfc7521#section-4.1
416418
417- :param assertion: The assertion string which will be sent on wire as-is
419+ :param assertion: The assertion bytes which will be sent on wire as-is.
420+ If it is a SAML assertion, you need to encode it beforehand, by:
421+ base64.urlsafe_b64encode(assertion).strip(b'=')
418422 :param grant_type:
419423 If you leave it as the default None, this method will try to make
420424 a guess between SAML2 (RFC 7522) and JWT (RFC 7523),
@@ -423,7 +427,7 @@ def obtain_token_by_assertion(
423427 :param scope: Optional. It must be a subset of previously granted scopes.
424428 """
425429 if grant_type is None :
426- grant_type = self .GRANT_TYPE_JWT if "." in assertion else self .GRANT_TYPE_SAML2
430+ grant_type = self .GRANT_TYPE_JWT if b "." in assertion else self .GRANT_TYPE_SAML2
427431 data = kwargs .pop ("data" , {})
428432 data .update (scope = scope , assertion = assertion )
429433 return self ._obtain_token (grant_type , data = data , ** kwargs )
0 commit comments