openedx.core.djangoapps.commerce package#

Subpackages#

Submodules#

openedx.core.djangoapps.commerce.utils module#

Commerce API Service.

class openedx.core.djangoapps.commerce.utils.BearerAuth(token)#

Bases: AuthBase

Attaches Bearer Authentication to the given Request object.

class openedx.core.djangoapps.commerce.utils.DeprecatedRestApiClient(url, signing_key=None, username=None, full_name=None, email=None, timeout=5, issuer=None, expires_in=30, tracking_context=None, oauth_access_token=None, session=None, jwt=None, **kwargs)#

Bases: API

API client for edX REST API.

(deprecated) See docs/decisions/0002-oauth-api-client-replacement.rst.

classmethod get_and_cache_jwt_oauth_access_token(url, client_id, client_secret, timeout=(3.05, 5))#
classmethod get_oauth_access_token(url, client_id, client_secret, token_type='bearer', timeout=(3.05, 5))#

To help transition to OAuthAPIClient, use DeprecatedRestApiClient. get_and_cache_jwt_oauth_access_token instead’

‘of DeprecatedRestApiClient.get_oauth_access_token to share cached jwt token used by OAuthAPIClient.’

classmethod user_agent()#
openedx.core.djangoapps.commerce.utils.create_tracking_context(user)#

Assembles attributes from user and request objects to be sent along in E-Commerce API calls for tracking purposes.

openedx.core.djangoapps.commerce.utils.ecommerce_api_client(user, session=None)#

Returns an E-Commerce API client setup with authentication for the specified user.

DEPRECATED: To be replaced with get_ecommerce_api_client.

openedx.core.djangoapps.commerce.utils.get_and_cache_oauth_access_token(url, client_id, client_secret, token_type='jwt', grant_type='client_credentials', refresh_token=None, timeout=(3.05, 5))#

Retrieves a possibly cached OAuth 2.0 access token using the given grant type.

See get_oauth_access_token for usage details.

First retrieves the access token from the cache and ensures it has not expired. If the access token either wasn’t found in the cache, or was expired, retrieves a new access token and caches it for the lifetime of the token.

Note: Consider tokens to be expired ACCESS_TOKEN_EXPIRED_THRESHOLD_SECONDS early to ensure the token won’t expire while it is in use.

Returns:

Tuple containing (access token string, expiration datetime).

Return type:

tuple

openedx.core.djangoapps.commerce.utils.get_ecommerce_api_base_url()#

Returns an E-Commerce API base URL.

openedx.core.djangoapps.commerce.utils.get_ecommerce_api_client(user)#

Returns an E-Commerce API client setup with authentication for the specified user.

openedx.core.djangoapps.commerce.utils.get_oauth_access_token(url, client_id, client_secret, token_type='jwt', grant_type='client_credentials', refresh_token=None, timeout=(3.05, 5))#

Retrieves OAuth 2.0 access token using the given grant type.

Parameters:
  • url (str) – Oauth2 access token endpoint, optionally including part of the path.

  • client_id (str) – client ID

  • client_secret (str) – client secret

Kwargs:

token_type (str): Type of token to return. Options include bearer and jwt. grant_type (str): One of ‘client_credentials’ or ‘refresh_token’ refresh_token (str): The previous access token (for grant_type=refresh_token)

Raises:

requests.RequestException if there is a problem retrieving the access token.

Returns:

Tuple containing (access token string, expiration datetime).

Return type:

tuple

openedx.core.djangoapps.commerce.utils.is_commerce_service_configured()#

Return a Boolean indicating whether or not configuration is present to use the external commerce service.

openedx.core.djangoapps.commerce.utils.user_agent()#

Return a User-Agent that identifies this client.

Example

python-requests/2.9.1 edx-rest-api-client/1.7.2 ecommerce

The last item in the list will be the application name, taken from the OS environment variable EDX_REST_API_CLIENT_NAME. If that environment variable is not set, it will default to the hostname.

Module contents#

Thin Client for the Ecommerce API Service