This is a demonstration of using a web interface to acquire and refresh tokens for building on top of Schwab's API: developer.schwab.com
This Flask-based web application demonstrates OAuth authentication with Schwab’s API. It allows users to log in using their Schwab credentials, manages secure token storage, and implements a token refresh mechanism.
Clone the repository:
git clone <repository-url>
cd <repository-directory>
Install the required dependencies:
pip install -r requirements.txt
Create a .env file in the root directory with the following content:
FLASK_SECRET_KEY=your_secure_secret_key
SCHWAB_CLIENT_ID=your_schwab_client_id
SCHWAB_CLIENT_SECRET=your_schwab_client_secret
Replace your_secure_secret_key, your_schwab_client_id, and your_schwab_client_secret with your actual values.
Start the Flask application:
python main.py
Open a web browser and navigate to http://localhost:5000
Click on the “Login with Schwab” button to initiate the OAuth flow
After successful authentication, you will be redirected back to the application where you can view your account numbers and test the token refresh mechanism
app.py: Main Flask application setuproutes.py: Contains all the route handlers for the applicationconfig.py: Configuration settings for the applicationmodules/oauth/: Contains OAuth-related functionality (token writing, refreshing, and validation)templates/: HTML templates for the web interfacestatic/: Static files (CSS, JavaScript)This application is for demonstration purposes only. In a production environment, additional security measures should be implemented.
Please ensure you comply with Schwab’s API usage policies and terms of service when using this application.