Authentication
Read in 5 minutes
The Edge Sports API supports OAuth2 with JWT tokens.
1. User Authentication
First, use the login endpoint to obtain a JWT token using your credentials from your registered account:
POST /api/v1/auth/login
{
"username": "your.email@example.com",
"password": "your_password"
}
2. Application Authentication (OAuth2)
For application access, first register your application using your JWT token in the header as a bearer token from step 1:
POST /api/v1/auth/register/app
{
"app_name": "Your App Name"
}
This will provide you with an app_id
and app_secret
. Use these to obtain an access token:
POST /api/v1/auth/oauth/token
{
"app_id": "your_app_id",
"client_secret": "your_app_secret",
"grant_type": "client_credentials"
}
Using the OAuth2 Token
For all authenticated requests, include the token in the Authorization header:
Authorization: Bearer your_access_token
Important Note
The token must be included in the Authorization
header with the Bearer
prefix.
Code Examples
1import requests
2
3# 1. User Authentication
4def get_user_token(email, password):
5 response = requests.post(
6 'https://api.example.com/api/v1/auth/login',
7 json={
8 'username': email,
9 'password': password
10 }
11 )
12 return response.json()['access_token']
13
14# 2. Register Application
15def register_app(app_name, user_token):
16 headers = {'Authorization': f'Bearer {user_token}'}
17 response = requests.post(
18 'https://api.example.com/api/v1/auth/register/app',
19 headers=headers,
20 json={'app_name': app_name}
21 )
22 return response.json()
23
24# 3. Get OAuth2 Token
25def get_oauth_token(app_id, app_secret):
26 response = requests.post(
27 'https://api.example.com/api/v1/auth/oauth/token',
28 json={
29 'app_id': app_id,
30 'client_secret': app_secret,
31 'grant_type': 'client_credentials'
32 }
33 )
34 return response.json()['access_token']
35
36# Example usage
37user_token = get_user_token('your.email@example.com', 'your_password')
38
39app_credentials = register_app('My Application', user_token)
40app_id = app_credentials['app_id']
41app_secret = app_credentials['app_secret']
42
43oauth_token = get_oauth_token(app_id, app_secret)
44
45# Making authenticated requests
46headers = {'Authorization': f'Bearer {oauth_token}'}
47response = requests.get('https://api.example.com/protected/endpoint', headers=headers)