Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moureauf/oauth-mock
Mock OAuth server
https://github.com/moureauf/oauth-mock
flask-application mock oauth2 python3
Last synced: 30 days ago
JSON representation
Mock OAuth server
- Host: GitHub
- URL: https://github.com/moureauf/oauth-mock
- Owner: moureauf
- License: mit
- Created: 2023-12-10T21:51:05.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-10T22:30:21.000Z (about 1 year ago)
- Last Synced: 2024-12-06T22:17:20.625Z (about 1 month ago)
- Topics: flask-application, mock, oauth2, python3
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OAuth Mock Server
This simple Flask app serves as a mock OAuth server implementing the Client Credentials flow. It generates a fake JWT access token for valid client credentials.
## Prerequisites
- [Python 3.x](https://www.python.org/)
- Pip (Python package installer)## Installation
1. **Clone the repository:**
```bash
git clone https://github.com/moureauf/oauth-mock.git
cd oauth-mock
```2. **Install dependencies:**
```bash
pip install -r requirements.txt
```## Configuration
Update the `config.ini` file with your OAuth configuration:
```ini
[OAuth]
client_id = yourClientId
client_secret = yourClientSecret
secret_key = yourSecretKey
user_id = yourUserId[server]
port = 5000
```## Running the Server
Run the Flask app:
```bash
python oauth.py
```The OAuth server will be accessible at `http://127.0.0.1:5000`.
## Obtaining an Access Token
Make a `POST` request to `http://127.0.0.1:5000/token` with the following parameters:
- `client_id`: Your client ID
- `client_secret`: Your client secret
- `grant_type`: 'client_credentials'Example using curl:
```bash
curl -X POST -d "client_id=yourClientId&client_secret=yourClientSecret&grant_type=client_credentials" http://127.0.0.1:5000/token
```The server will respond with a JSON containing the access token.
## Error Handling
The server handles missing or invalid parameters gracefully and responds with appropriate error messages.
### Note:
- This is a simple mock server for educational purposes.
- In a production environment, consider securing sensitive information better.
- Do not use fake or weak secrets in real-world scenarios.Feel free to customize the code and structure according to your needs.