wxc_sdk.integration package
An OAuth integration
- class wxc_sdk.integration.Integration(*, client_id: str, client_secret: str, scopes: str | list[str], redirect_url: str, auth_service: str | None = None, token_service: str | None = None, initiate_flow_callback: Callable[[str], None] | None = None)[source]
Bases:
object
An OAuth integration
- client_id: str
integration’s client id, obtained from developer.webex.com
- client_secret: str
integration’s client secret, obtained from developer.webex.com
- scopes: list[str]
OAuth scopes of the integration.
- redirect_url: str
redirect URL of the integration
- auth_service: str
URL of the authorization service; used as part of the URL to start an OAuth flow
- token_service: str
base URL of the access token service
- initiate_flow_callback: Callable[[str], None]
callback to initiate auth flow
- auth_url(state: str) str [source]
Get the URL to start an OAuth flow for the integration
- Parameters:
state (str) – state in redirect URL
- Returns:
URL to start the OAuth flow
- Return type:
str
- tokens_from_code(code: str) Tokens [source]
Get a new set of tokens from code at end of OAuth flow
- Parameters:
code (str) – code obtained at end of SAML 2.0 OAuth flow
- Returns:
new tokens
- Return type:
- refresh(tokens: Tokens)[source]
Try to get a new access token using the refresh token.
- Parameters:
tokens – Tokens. Access token and expirations get updated in place.
- Raise:
requests.HTTPError
: if request to obtain new access token fails
- validate_tokens(tokens: Tokens, min_lifetime_seconds: int = 300) bool [source]
Validate tokens
If remaining life time is to small then try to get a new access token using the existing refresh token. If no new access token can be obtained using the refresh token then the access token is set to None and True is returned
- Parameters:
tokens (Tokens) – current OAuth tokens. Get updated if new tokens are created
min_lifetime_seconds (int) – minimal remaining lifetime in seconds. Default: 300 seconds
- Returns:
True -> min lifetime reached and tried to get new access token.
- Return type:
bool
- get_tokens_from_oauth_flow() Tokens | None [source]
Initiate an OAuth flow to obtain new tokens.
start a local webserver on port 6001 o serve the last step in the OAuth flow
- Parameters:
self – Integration to use for the flow
- Type:
- Returns:
set of new tokens if successful, else None
- Return type:
wxc_sdk.tokens.Tokens`
- get_cached_tokens(read_from_cache: Callable[[], Tokens | None], write_to_cache: Callable[[Tokens], None], force_new: bool = False) Tokens | None [source]
Get tokens.
Tokens are read from cache and then verified. If needed an OAuth flow is initiated to get a new set of tokens. For this the redirect URL http://localhost:6001/redirect is expected.
- Parameters:
read_from_cache – callback to read tokens from cache. Called without parameters and is expected to return a
wxc_sdk.tokens.Tokens
instance with the cached tokens. If cached tokens cannot be provided then None should be returned.write_to_cache – callback to write updated tokens back to cache. The callback is called with a
wxc_sdk.tokens.Tokens
instance as only argument.force_new (bool) – flag, don’t read cached tokens and always get tokens from OAuth flow
- Returns:
set of tokens or None
- Return type:
- get_cached_tokens_from_yml(yml_path: str, force_new: bool = False) Tokens | None [source]
Get tokens.
Tokens are read from given YML file and then verified. If needed an OAuth flow is initiated to get a new set of tokens. For this the redirect URL http://localhost:6001/redirect is expected.
- Parameters:
yml_path – path to YML file to be used to cache tokens
force_new (bool) – flag, don’t read cached tokens and always get tokens from OAuth flow
- Returns:
set of tokens or None
- Return type: