Authentication
Learn how to authenticate with Mentor3.ai APIs
curl -X GET "https://api.mentor3.ai/v1/courses" \
-H "Authorization: Bearer YOUR_API_KEY"
import requests
headers = {
'Authorization': f'Bearer YOUR_API_KEY'
}
response = requests.get('https://api.mentor3.ai/v1/courses', headers=headers)
print(response.json())
API Authentication Overview
Mentor3.ai uses OAuth 2.0 and API keys for secure access to our learning platform APIs. Authentication ensures that only authorized users and applications can access protected resources. We support multiple authentication methods to accommodate different integration scenarios.
Authentication Methods
Use API keys for server-to-server communication.
Your unique API key obtained from the dashboard.
Implement OAuth 2.0 for user-based authentication.
Register Application
Create an OAuth application in your dashboard.
Request Authorization
Direct users to the authorization endpoint.
const authUrl = 'https://api.mentor3.ai/oauth/authorize?' +
'client_id=YOUR_CLIENT_ID&' +
'redirect_uri=YOUR_REDIRECT_URI&' +
'response_type=code&' +
'scope=read+write';
window.location.href = authUrl;
Exchange Code
Exchange authorization code for access token.
Token Management
Access tokens have a limited lifespan for security. Implement token refresh logic to maintain continuous API access.
Security Best Practices
Never expose API keys or tokens in client-side code. Use environment variables or secure key management systems.
Troubleshooting Authentication Issues
Common authentication problems and their solutions:
| Issue | Symptom | Solution |
|---|---|---|
| Invalid Token | 401 Unauthorized | Refresh or re-authenticate |
| Rate Limited | 429 Too Many Requests | Implement backoff strategy |
| Expired Key | 403 Forbidden | Generate new API key |
Integration Examples
Here's how to authenticate in different programming environments:
const authenticate = async (apiKey) => {
const response = await fetch('/api/user/profile', {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error('Authentication failed');
}
return response.json();
};
<?php
$apiKey = 'YOUR_API_KEY';
$ch = curl_init('https://api.mentor3.ai/v1/user/profile');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
throw new Exception('Authentication failed');
}
curl_close($ch);
?>
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Mentor3ApiClient {
private final HttpClient client = HttpClient.newHttpClient();
private final String apiKey;
public Mentor3ApiClient(String apiKey) {
this.apiKey = apiKey;
}
public String getUserProfile() throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.mentor3.ai/v1/user/profile"))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
throw new RuntimeException("Authentication failed: " + response.statusCode());
}
return response.body();
}
}
For additional support with authentication, refer to our API documentation or contact the developer support team.
Last updated 4 days ago