AuthCodeReceiver Class

Inheritance
builtins.object
AuthCodeReceiver

Constructor

AuthCodeReceiver(port=None, scheduled_actions=None)

Parameters

port
default value: None
scheduled_actions
default value: None

Methods

close

Either call this eventually; or use the entire class as context manager

get_auth_response

Wait and return the auth response. Raise RuntimeError when timeout.

get_port

The port this server actually listening to

close

Either call this eventually; or use the entire class as context manager

close()

get_auth_response

Wait and return the auth response. Raise RuntimeError when timeout.

get_auth_response(timeout=None, **kwargs)

Parameters

auth_uri
str
default value: None

If provided, this function will try to open a local browser.

timeout
int
Required

In seconds. None means wait indefinitely.

state
str
Required

You may provide the state you used in auth_uri, then we will use it to validate incoming response.

welcome_template
str
Required

If provided, your end user will see it instead of the auth_uri. When present, it shall be a plaintext or html template following Python Template string syntax, and include some of these placeholders: $auth_uri and $abort_uri.

success_template
str
Required

The page will be displayed when authentication was largely successful. Placeholders can be any of these: https://tools.ietf.org/html/rfc6749#section-5.1

error_template
str
Required

The page will be displayed when authentication encountered error. Placeholders can be any of these: https://tools.ietf.org/html/rfc6749#section-5.2

auth_uri_callback
callable
Required

A function with the shape of lambda auth_uri: ... When a browser was unable to be launch, this function will be called, so that the app could tell user to manually visit the auth_uri.

browser_name
str
Required

If you did webbrowser.register("xyz", None, BackgroundBrowser("/path/to/browser")) beforehand, you can pass in the name "xyz" to use that browser. The default value None means using default browser, which is customizable by env var $BROWSER.

Returns

The auth response of the first leg of Auth Code flow, typically {"code": "...", "state": "..."} or {"error": "...", ...} See https://tools.ietf.org/html/rfc6749#section-4.1.2 and https://openid.net/specs/openid-connect-core-1_0.html#AuthResponse Returns None when the state was mismatched, or when timeout occurred.

get_port

The port this server actually listening to

get_port()