@@ -72,7 +72,8 @@ def __init__(
7272 self , client_id ,
7373 client_credential = None , authority = None , validate_authority = True ,
7474 token_cache = None ,
75- verify = True , proxies = None , timeout = None ):
75+ verify = True , proxies = None , timeout = None ,
76+ client_claims = None ):
7677 """Create an instance of application.
7778
7879 :param client_id: Your app has a client_id after you register it on AAD.
@@ -91,6 +92,22 @@ def __init__(
9192 public_certificate (optional) is public key certificate which is
9293 sent through 'x5c' JWT header only for
9394 subject name and issuer authentication to support cert auto rolls
95+
96+ :param dict client_claims:
97+ It is a dictionary of extra claims that would be signed by
98+ by this :class:`ConfidentialClientApplication` 's private key.
99+ For example, you can use {"client_ip": "x.x.x.x"}.
100+ You may also override any of the following default claims:
101+
102+ {
103+ "aud": the_token_endpoint,
104+ "iss": self.client_id,
105+ "sub": same_as_issuer,
106+ "exp": now + 10_min,
107+ "iat": now,
108+ "jti": a_random_uuid
109+ }
110+
94111 :param str authority:
95112 A URL that identifies a token authority. It should be of the format
96113 https://login.microsoftonline.com/your_tenant
@@ -115,6 +132,7 @@ def __init__(
115132 """
116133 self .client_id = client_id
117134 self .client_credential = client_credential
135+ self .client_claims = client_claims
118136 self .verify = verify
119137 self .proxies = proxies
120138 self .timeout = timeout
@@ -140,7 +158,8 @@ def _build_client(self, client_credential, authority):
140158 client_credential ["private_key" ], algorithm = "RS256" ,
141159 sha1_thumbprint = client_credential .get ("thumbprint" ), headers = headers )
142160 client_assertion = signer .sign_assertion (
143- audience = authority .token_endpoint , issuer = self .client_id )
161+ audience = authority .token_endpoint , issuer = self .client_id ,
162+ additional_claims = self .client_claims or {})
144163 client_assertion_type = Client .CLIENT_ASSERTION_TYPE_JWT
145164 else :
146165 default_body ['client_secret' ] = client_credential
0 commit comments