Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get id_token in Python Flask OpenID?

I have successfully implemented Keycloak OpenID + Python (v3.6) Flask integration using Flask-oidc.

I use below code to get user info,access_token and refresh_token

oidc = OpenIDConnect(app)
info = oidc.user_getinfo(['preferred_username', 'email', 'sub', 'given_name', 'iss'])
access_token = oidc.get_access_token()
refresh_token = oidc.get_refresh_token()

And got the results as well. But for a reason i need id_token as well. I tried,

oidc.get_cookie_id_token()

(which is already deprecated), but it gave decoded result not encoded token.

Anybody know how to get id_token from flask-oidc ?

like image 861
James Arems Avatar asked Dec 22 '25 18:12

James Arems


1 Answers

I found a solution,

from oauth2client.client import OAuth2Credentials
id_token_jwt = OAuth2Credentials.from_json(oidc.credentials_store[info.get('sub')]).id_token_jwt
like image 68
James Arems Avatar answered Dec 24 '25 06:12

James Arems



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!