module documentation

Functionality to work with OAuth2 code grant

Class OAuth2ClientInfo Metadata for Oauth2 client
Function exchange_code_for_access_token Exchange a code for an access token using the endpoints from client info
Function exchange_code_for_response Exchange a code for an access token using the endpoints from client info and return the entire response
Function get_auth_url Build authorization url for browser
Function load_oidc_config Load OIDC configuration from the well known configuration endpoint
Function open_browser Open browser using webbrowser module and show message about URL open
def exchange_code_for_access_token(client_info: OAuth2ClientInfo, redirect_uri: str, code: str, access_token_field: str = 'access_token') -> str:

Exchange a code for an access token using the endpoints from client info

Parameters
client_info:OAuth2ClientInfoInfo about oauth2 client
redirect_uri:strCallback URL
code:strCode to redeem
access_token_field:strName of the field containing the access token to use. This might differ depending on the provider you are using. For example for Auth0 you have to set this to id_token
Returns
strExtracted access token from response
def exchange_code_for_response(client_info: OAuth2ClientInfo, redirect_uri: str, code: str) -> dict:

Exchange a code for an access token using the endpoints from client info and return the entire response

Parameters
client_info:OAuth2ClientInfoInfo about oauth2 client
redirect_uri:strCallback URL
code:strCode to redeem
Returns
dictResponse from OAuth2 endpoint
def get_auth_url(client_info: OAuth2ClientInfo, redirect_uri: str) -> str:

Build authorization url for browser

Parameters
client_info:OAuth2ClientInfoInfo about oauth2 client
redirect_uri:strCallback URL
Returns
strReady to use URL
def load_oidc_config(odic_well_known_endpoint: str) -> dict:

Load OIDC configuration from the well known configuration endpoint

Parameters
odic_well_known_endpoint:strEndpoint to load configuration from
Returns
dictUndocumented
def open_browser(url: str, print_open_browser_instruction: Callable[[str], None]|None = print):

Open browser using webbrowser module and show message about URL open

Parameters
url:strURL to open and display
print_open_browser_instruction:Callable[[str], None]|NoneCallback to print the instructions to open the browser. Set to None in order to supress the output.
Returns
None