Verify OIDC Token with Authlib

  • Share this:

Code introduction


This function is used to verify the validity of an OIDC token, using the OAuth2Provider and OAuth2Token classes from the Authlib library.


Technology Stack : Authlib

Code Type : Verify OIDC Token

Code Difficulty : Intermediate


                
                    
def verify_token(token):
    from authlib.integrations.oidc.oidc import OAuth2Provider
    from authlib.integrations.oidc.core import OAuth2Token

    provider = OAuth2Provider(client_id='your-client-id', client_secret='your-client-secret')
    token_info = OAuth2Token(token, provider=provider)
    token_info.validate()
    return token_info                
              
Tags: