wxc_sdk.integration package

An OAuth integration

class wxc_sdk.integration.Integration(*, client_id: str, client_secret: str, scopes: Union[str, list[str]], redirect_url: str, auth_service: Optional[str] = None, token_service: Optional[str] = None)[source]

Bases: object

An OAuth integration

Parameters
  • client_id – integration’s client id, obtained from developer.webex.com

  • client_secret – integration’s client secret, obtained from developer.webex.com

  • scopes – integration’s scopes. Can be a list of strings or a string containing a list of space separated scopes

  • redirect_url – integration’s redirect URL

  • auth_service – authorization service to be used in the authorization URL. Default: ‘https://webexapis.com/v1/authorize

  • token_service – URL of token service to use to obtain tokens from. Default: ‘https://webexapis.com/v1/access_token

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

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

Tokens

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() Optional[Tokens][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

wxc_sdk.integration.Integration

Returns

set of new tokens if successful, else None

Return type

wxc_sdk.tokens.Tokens`

get_cached_tokens(read_from_cache: Callable[[], Optional[Tokens]], write_to_cache: Callable[[Tokens], None]) Optional[Tokens][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.

Returns

set of tokens or None

Return type

wxc_sdk.tokens.Tokens