UserSession#

class fourinsight.api.UserSession(auth_force=False, session_key=None)[source]#

Authorized session where credentials are given in the 4insight.io web application. When a valid code is presented, the session is authenticated and persisted. A previous session will be reused as long as it is not expired. When required, a new authentication code is prompted for.

Extends BaseAuthSession.

Parameters:
  • auth_force (bool, optional) – Force re-authenticating the session (default is False)

  • session_key (str, optional) – Unique identifier for an auth session. Can be used so that multiple instances can have independent auth/refresh cycles with the identity authority. Prevents local cache from being accidently overwritten.

fetch_token()[source]#

Fetch new access and refresh token.

get(*args, **kwargs)[source]#

Extend the requests_oauthlib.OAuth2Session.get method to ensure that internal API are not accessed.

get_pages(url, **kwargs)[source]#

Sends GET requests, and returns a generator that lets the user iterate over paginated responses. Note that the endpoint must support OData; the json response should include the a parameter @odata.nextLink’, providing the URL for the next page.

Parameters:
  • url (str) – API endpoint. To return pages, the endpoint must support OData and contain the parameter @odata.nextLink’.

  • **kwargs – Optional keyword arguments. Will be passed on to the get method.

Yields:

response (obj) – The response as a Response object.

refresh_token(*args, **kwargs)[source]#

Refresh (expired) access token with a valid refresh token.

request(*args, **kwargs)[source]#

Extend the requests_oauthlib.OAuth2Session.request method to supply default arguments.