This repository provides a simple utility for retrieving API tokens using the official StockX API. It is designed for developers who need to quickly authenticate and interact with the StockX API.
- Automated OAuth flow for the StockX API.
- Secure storage of tokens for future use.
- Easy integration with your projects to make authenticated API requests.
Ensure you have the following installed on your system:
- Python 3.7+
- pip (Python package manager)
-
Clone this repository:
git clone https://github.com/jnthntena/stockx-api-auth.git cd stockx-api-auth
-
Install dependencies:
pip install -r requirements.txt
-
SSL certificate and key files:
- The process of generating the required SSL certificate (
cert.pem
) and key (key.pem
) is automated by this utility. You don't need to manually generate these files unless you prefer to do so. If you do want to manually create the SSL files, you can use the following command:openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem
- You will be prompted to enter information for the certificate (e.g., country, organization). You can leave most fields blank if not needed.
- This will generate
key.pem
andcert.pem
, which are required for the Flask server to handle secure communication.
Create a .env
file in the root directory based on the provided template:
TOKEN_URL = "https://accounts.stockx.com/oauth/token"
API_KEY = "your_api_key"
CLIENT_ID = "your_client_id"
CLIENT_SECRET = "your_client_secret"
REDIRECT_URI = "https://127.0.0.1:5000/callback"
STATE = "random_state_string"
- Visit the StockX Developer Portal.
- Follow the guide for authentication.
- Create your keys on the API Keys page.
- Set up your application in the Applications section.
- Populate the
.env
file with your credentials.
To retrieve your API tokens:
-
Run the
main.py
script:python main.py
-
The script will:
- Start a local Flask server to handle the OAuth callback.
- Generate an authorization URL and open it in your default browser.
- Wait for you to authenticate and authorize the application.
- Retrieve and save the tokens locally.
-
After successfully retrieving tokens, the script will print:
Successfully retrieved tokens
-
Use the
tokens
object to make authenticated API calls. See the StockX API Reference for available endpoints.
# Example placeholder for API functionality
# args to pass to the API function: tokens, config
perform_some_stockx_api_functionality(tokens, config)
main.py
: The entry point for the script.auth_flow/
: Contains theget_tokens
function for handling the authentication process.utils/
:config_loader.py
: Loads the environment variables from the.env
file.- Other utilities for handling token management.
.env
: Template for your StockX API credentials.requirements.txt
: List of dependencies required to run the project.
- Ensure your
REDIRECT_URI
matches the callback URL configured in your StockX application settings. - The Flask server uses SSL for secure communication. Make sure
cert.pem
andkey.pem
are properly generated and available in the project root. - Tokens are saved locally for reuse but ensure proper security measures when handling them.
- Refer to the StockX API Reference for details on making API calls.
This project is licensed under the MIT License. See the LICENSE
file for details.
For more details on the StockX API, refer to the official documentation.