sailor.utils.oauth_wrapper.OAuthServiceImpl

Improvements to OAuth and OData clients.

exception sailor.utils.oauth_wrapper.OAuthServiceImpl.RequestError(msg, status_code, reason, error_text)[source]

Bases: Exception

Exception object with additional information about the status returned by a REST request.

class sailor.utils.oauth_wrapper.OAuthServiceImpl.OAuth2Client(name, scope_config=None)[source]

Bases: object

Provide session management for OAuth2 enhanced requests Session’s.

Manages a single session that can be used for making requests against endpoints which accept tokens issued by the auth server used by this client.

Single entrypoint should be the convenience request() method which acts as a convenience method for making OAuth2 enhanced HTTP requests with an instance of this class.

request(method, url, **req_kwargs)[source]

Make a request using this convenience wrapper.

The interface is the same as the requests.sessions.Session.request() method provides but changes the following behavior:

  • Does not return a response object. Instead, returns content or raises an error (see below).

  • Automatically converts supplied ‘params’ for GET requests to OData URL parameters.

  • If headers are not set, requests for JSON content by default.

Client session management: will use the currently attached session with this client or create a new one. If scopes are configured with this client and are not resolved yet, will try to resolve the scopes with the auth server first before making the request.

Return type

A dict if the response contains JSON. Otherwise returns the response content as bytes.

Raises

RequestError – When the reponse is retrieved but response code is 400 or higher.