scitacean.auth.OAuthClientNormal#
- class scitacean.auth.OAuthClientNormal(*, provider, client_id, local_port=0, callback_path='/callback', local_timeout=datetime.timedelta(seconds=60), remote_timeout=datetime.timedelta(seconds=5), scopes=('openid',), allow_http=False)[source]#
An OAuth client for ‘normal’ authentication flows.
This client implements the ‘normal’ flow of OAuth. It runs an interactive login flow via the user’s web browser and a callback server on localhost.
This requires that Python is running on the same machine as the user interface so that opening
127.0.0.1in a browser connects with the machine running the Python code. This is notably not the case when using a remote Jupyter instance. Use a different login method in such a case.See also
Constructors
__init__(*, provider, client_id[, ...])Create a new client.
Methods
login(*[, open_browser])Log in with the IdP.
Attributes
The timeout for calls to the identity provider.
- __init__(*, provider, client_id, local_port=0, callback_path='/callback', local_timeout=datetime.timedelta(seconds=60), remote_timeout=datetime.timedelta(seconds=5), scopes=('openid',), allow_http=False)[source]#
Create a new client.
This client uses a callback server that will be launched on
127.0.0.1:{port}{callback_path}
This path needs to be whitelisted in the OAuth provider’s configuration for the client ID.
- Parameters:
provider (
str) – The URL of the OAuth provider.client_id (
str) – The client ID of the OAuth client.local_port (
int|Iterable[int], default:0) – The port(s) to use for the callback server on localhost. If multiple, tries all ports in order until one is available. Defaults to 0, which means that the server will pick any free port.callback_path (
str, default:'/callback') – The path to use for the callback server on localhost.local_timeout (
timedelta, default:datetime.timedelta(seconds=60)) – Timeout for the callback server.remote_timeout (
timedelta, default:datetime.timedelta(seconds=5)) – Timeout for calls to the identity provider.scopes (
Iterable[str], default:('openid',)) – The scopes to request from the identity provider. Only change this if login fails with the default.allow_http (
bool, default:False) – Whether to allow the use of HTTP instead of HTTPS. Only use this for testing! Otherwise, secrets are transmitted unencrypted.
- login(*, open_browser=None)[source]#
Log in with the IdP.
This runs an interactive login flow via the user’s web browser.
- Parameters:
open_browser (
Callable[[str],SupportsClose] |None, default:None) – A function that opens a given URL in the user’s web browser. By default, the client either uses the system’s default browser or, in Jupyter, opens a browser through JavaScript. The return value is intended to close the browser window or at least release any auxiliary resources.- Returns:
ExpiringToken– An IdP access token. (This is not a SciCat token.)