Skip to content

Instantly share code, notes, and snippets.

@noinarisak
Last active June 23, 2020 19:57
Show Gist options
  • Save noinarisak/dcee57a47740a1f0c5b70ac86d13b140 to your computer and use it in GitHub Desktop.
Save noinarisak/dcee57a47740a1f0c5b70ac86d13b140 to your computer and use it in GitHub Desktop.
def getSignedJWT(self, privateKey, clientid, aud, algorithm = 'RS256'):
# Algo : RS256, RS384, RS512, ES256, ES384, ES512
now = int(time.time())
token = {'iss': clientid,
'sub': clientid,
'aud': aud,
'iat': now ,
'exp': now + 3600 }
encoded = jwt.encode(token, privateKey, algorithm)
return encoded
from jwcrypto.jwk import JWK
def generateClientAssertion(jwk, client_id, aud):
key=JWK(**jwk)
private_key = key.export_to_pem(private_key=True, password=None)
client_assertion = getSignedJWT(privateKey = private_key, clientid = client_id, aud = aud)
return client_assertion
def introspect(self, config, token, tokenType):
headers = {'Content-Type': 'application/x-www-form-urlencoded','Accept':'application/json'}
data = {"token":token, "token_type_hint":tokenType}
client_assertion = utils.generateClientAssertion(jwk=config["jwk"],
client_id=config["client_id"],
aud=self.getIntrospectUrl())
data.update({
"client_assertion_type":"urn:ietf:params:oauth:client-assertion-type:jwt-bearer", \
"client_assertion": client_assertion})
result = self.api_post(self.getIntrospectUrl(), headers=headers, data=data)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment