June 2018
Beginner
508 pages
13h 8m
English
Let's see another quick example involving the issuer (iss) and audience (aud) claims. The code is conceptually very similar to the previous example, and we're going to exercise it in the same way:
# claims_auth.pyimport jwtdata = {'payload': 'data', 'iss': 'fab', 'aud': 'learn-python'}secret = 'secret-key'token = jwt.encode(data, secret)def decode(token, secret, issuer=None, audience=None): try: print(jwt.decode( token, secret, issuer=issuer, audience=audience)) except ( jwt.InvalidIssuerError, jwt.InvalidAudienceError ) as err: print(err) print(type(err))decode(token, secret)# not providing the issuer won't breakdecode(token, secret, audience='learn-python')# not providing the audience will breakdecode(token, secret, ...Read now
Unlock full access