API Authentication
Secure your API requests with proper authentication.
API Keys
Generating Keys
1. Admin > API > API Keys
2. Click "Generate New Key"
3. Set key name and permissions
4. Copy and store securely
Key Permissions
Scope your keys:
- Read-only
- Write access
- Specific resources
- IP restrictions
Using API Keys
Authorization: Bearer sk_live_xxxxxOAuth 2.0
For User-Context Access
When acting on behalf of a user:
Authorization Code Flow
1. Redirect user to authorize:
GET /oauth/authorize?
client_id=xxx&
redirect_uri=xxx&
scope=read write&
response_type=code2. Exchange code for token:
POST /oauth/token
{
"grant_type": "authorization_code",
"code": "xxx",
"client_id": "xxx",
"client_secret": "xxx"
}Scopes
Available OAuth scopes:
read: Read accesswrite: Write accessusers: User managementcourses: Course managementgrades: Grade access
Token Refresh
Access tokens expire in 1 hour.
Refresh token:
POST /oauth/token
{
"grant_type": "refresh_token",
"refresh_token": "xxx"
}Security Best Practices
1. Never expose keys in client code
2. Use environment variables
3. Rotate keys regularly
4. Monitor key usage
5. Use minimal required scopes
Testing
Sandbox Environment
https://sandbox.dnlearn.org/api/v1Use test API keys that don't affect production.