macrosynergy.download.jpm_oauth#
- class JPMorganOAuth(client_id, client_secret, resource, application_name, root_url, auth_url, proxies=None, verify=True)[source]#
Bases:
objectA lightweight helper for OAuth 2.0 (Client Credentials) authentication used by the JPMorgan DataQuery API, DataQuery File API, and JPMorgan Fusion API.
This class retrieves and manages access tokens for API requests and supports loading credentials from a JSON file or a dictionary.
- Parameters:
client_id (str) – The OAuth client ID issued by JPMorgan.
client_secret (str) – The OAuth client secret issued by JPMorgan.
resource (str) – The token audience (often sent as the aud parameter) identifying the target JPMorgan API.
application_name (str) – The name of the application using the API (used for identification/logging only).
root_url (str) – The base URL for the target JPMorgan API (not required for token retrieval but kept for completeness and potential future use).
auth_url (str) – The full URL of the OAuth token endpoint for JPMorgan.
proxies (Optional[Dict[str, str]]) – Optional proxies to use for the HTTP requests. Default is None.
- classmethod from_credentials_json(credentials_json)[source]#
Load OAuth credentials from a JSON file and return an instance of JPMorganOAuth.
- Parameters:
credentials_json (str) – Path to the JSON file containing the OAuth credentials. This file must contain the keys ‘client_id’ and ‘client_secret’ and should include ‘resource’, ‘application_name’, ‘root_url’, and ‘auth_url’.
- Returns:
An instance of the JPMorganOAuth class initialized with the credentials from the JSON file.
- Return type:
- classmethod from_credentials(credentials)[source]#
Create an instance of JPMorganOAuth from a dictionary of credentials.
- Parameters:
credentials (dict) – A dictionary containing the OAuth credentials. It must include the keys ‘client_id’ and ‘client_secret’, and should include ‘resource’, ‘application_name’, ‘root_url’, and ‘auth_url’.
- Returns:
An instance of the JPMorganOAuth class initialized with the provided credentials.
- Return type:
- retrieve_token()[source]#
Retrieve an access token from the OAuth server and store it in the instance.
Equivalent cURL request:
curl -X POST "$AUTH_URL" \ -d "grant_type=client_credentials" \ -d "aud=$RESOURCE" \ -d "client_id=$CLIENT_ID" \ -d "client_secret=$CLIENT_SECRET"