@@ -41,6 +41,9 @@ def client(client, db):
4141
4242def register_jwt_client_auth (server , validate_jti = True ):
4343 class JWTClientAuth (JWTBearerClientAssertion ):
44+ def get_audiences (self ):
45+ return ["https://provider.test/oauth/token" ]
46+
4447 def validate_jti (self , claims , jti ):
4548 return jti != "used"
4649
@@ -51,7 +54,7 @@ def resolve_client_public_key(self, client, headers):
5154
5255 server .register_client_auth_method (
5356 JWTClientAuth .CLIENT_AUTH_METHOD ,
54- JWTClientAuth ("https://provider.test/oauth/token" , validate_jti ),
57+ JWTClientAuth (validate_jti = validate_jti ),
5558 )
5659
5760
@@ -299,3 +302,43 @@ def test_missing_jti(test_client, server):
299302 resp = json .loads (rv .data )
300303 assert "error" in resp
301304 assert resp ["error_description" ] == "Missing JWT ID."
305+
306+
307+ def test_issuer_as_audience (test_client , server ):
308+ """Per RFC 7523 Section 3 and draft-ietf-oauth-rfc7523bis, the AS issuer
309+ identifier should be a valid audience value for client assertion JWTs."""
310+
311+ class JWTClientAuth (JWTBearerClientAssertion ):
312+ def get_audiences (self ):
313+ return ["https://provider.test/oauth/token" , "https://provider.test" ]
314+
315+ def validate_jti (self , claims , jti ):
316+ return True
317+
318+ def resolve_client_public_key (self , client , headers ):
319+ return client .client_secret
320+
321+ server .register_client_auth_method (
322+ JWTClientAuth .CLIENT_AUTH_METHOD ,
323+ JWTClientAuth (),
324+ )
325+
326+ key = OctKey .import_key ("client-secret" )
327+ claims = {
328+ "iss" : "client-id" ,
329+ "sub" : "client-id" ,
330+ "aud" : "https://provider.test" ,
331+ "exp" : int (time .time () + 3600 ),
332+ "jti" : "nonce" ,
333+ }
334+ client_assertion = jwt .encode ({"alg" : "HS256" }, claims , key )
335+ rv = test_client .post (
336+ "/oauth/token" ,
337+ data = {
338+ "grant_type" : "client_credentials" ,
339+ "client_assertion_type" : JWTBearerClientAssertion .CLIENT_ASSERTION_TYPE ,
340+ "client_assertion" : client_assertion ,
341+ },
342+ )
343+ resp = json .loads (rv .data )
344+ assert "access_token" in resp
0 commit comments