Authentication¶
-
class
elg.authentication.
Authentication
(domain: str)¶ Class to authenticate in the ELG using out-of-band authentication.
- Parameters
base_url (str) – url to authenticate.
token_url (str) – url to request tokens.
client (str) – name of the Keycloak client.
redirect_uri (str) – redirect uri.
-
create
(scope: str = 'openid')¶ Method to create Keycloak authentication tokens.
- Parameters
scope (str, optional) – scope to use when requesting tokens. Can be set to “openid” or “offline_access” to get offline tokens. Defaults to “openid”.
-
classmethod
create_authentication_url
(scope: str = 'openid', domain: str = 'live') → str¶ Class method to create the Keycloak authentication url.
- Parameters
scope (str, optional) – scope to use when requesting tokens. Can be set to “openid” or “offline_access” to get offline tokens. Defaults to “openid”.
domain (str, optional) – ELG domain you want to use. “live” to use the public ELG, “dev” to use the development ELG and another value to use a local ELG. Defaults to “live”.
- Returns
Keycloak authentication url.
- Return type
str
-
classmethod
from_json
(filename: str)¶ Class method to init an Authentication object from a json file.
- Parameters
filename (str) – name of the json file.
- Returns
Authentication object with Keycloak authentication tokens.
- Return type
elg.Authentication
-
classmethod
from_success_code
(code: str, domain: str = 'live')¶ Class method to init an Authentication object from a success code.
- Parameters
code (str) – success code obtained after authentication.
domain (str, optional) – ELG domain you want to use. “live” to use the public ELG, “dev” to use the development ELG and another value to use a local ELG. Defaults to “live”.
- Returns
Authentication object with Keycloak authentication tokens.
- Return type
elg.Authentication
-
classmethod
init
(scope: str = 'openid', domain: str = 'live')¶ Class method to init an Authentication object and authenticate to the ELG.
- Parameters
scope (str, optional) – scope to use when requesting tokens. Can be set to “openid” or “offline_access” to get offline tokens. Defaults to “openid”.
domain (str, optional) – ELG domain you want to use. “live” to use the public ELG, “dev” to use the development ELG and another value to use a local ELG. Defaults to “live”.
- Returns
Authentication object with Keycloak authentication tokens.
- Return type
elg.Authentication
-
refresh
()¶ Method to refresh to access_token using the refresh_token.
- Raises
AuthenticationException – There is no refresh_token to refresh the access_token.
-
refresh_if_needed
()¶ Method that call the refresh method only if needed, i.e. the access_token is expired.
- Raises
RefreshTokenExpirationException – The refresh_token is expired.
-
to_json
(filename: str)¶ Save the Keycloak authentication tokens to a json file.
- Parameters
filename (str) – name of the json file.
-
class
elg.authentication.
NeedAuthentication
¶ Parent class for class which needs authentication. Provide useful methods
-
elg.authentication.
need_authentication
()¶ Decorator for methods to refresh to authentication tokens before calling the method