curl --request POST \
--url https://api.example.com/api/sign-in/ \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'{
"access": "<string>",
"refresh": "<string>",
"user": {
"user.id": 123,
"user.username": "<string>",
"user.email": "<string>",
"user.first_name": "<string>",
"user.last_name": "<string>",
"user.number_phone": "<string>",
"user.avatar": "<string>"
}
}Authenticate a user and receive JWT tokens for API access
curl --request POST \
--url https://api.example.com/api/sign-in/ \
--header 'Content-Type: application/json' \
--data '
{
"email": "<string>",
"password": "<string>"
}
'{
"access": "<string>",
"refresh": "<string>",
"user": {
"user.id": 123,
"user.username": "<string>",
"user.email": "<string>",
"user.first_name": "<string>",
"user.last_name": "<string>",
"user.number_phone": "<string>",
"user.avatar": "<string>"
}
}Documentation Index
Fetch the complete documentation index at: https://mintlify.com/edimez14/password_generator/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/sign-in/
curl -X POST http://localhost:8000/api/sign-in/ \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "SecurePass123!"
}'
import requests
url = "http://localhost:8000/api/sign-in/"
payload = {
"email": "[email protected]",
"password": "SecurePass123!"
}
response = requests.post(url, json=payload)
data = response.json()
# Store tokens for future requests
access_token = data['access']
refresh_token = data['refresh']
fetch('http://localhost:8000/api/sign-in/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: '[email protected]',
password: 'SecurePass123!'
})
})
.then(response => response.json())
.then(data => {
// Store tokens in localStorage or secure storage
localStorage.setItem('access_token', data.access);
localStorage.setItem('refresh_token', data.refresh);
});
{
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"user": {
"id": 1,
"username": "johndoe",
"email": "[email protected]",
"first_name": "John",
"last_name": "Doe",
"number_phone": "5551234567",
"avatar": "/media/avatars/profile.jpg"
}
}
{
"error": "Invalid password"
}
{
"error": "Email and password are required."
}
{
"error": "User does not exist."
}
{
"error": "Error message details"
}
apps/users/views.py:21-44. Here’s the authentication flow:
get_object_or_404()check_password() methodRefreshToken.for_user(user)UsersSerializerapps/users/views.py:21-44:
@api_view(['POST'])
@permission_classes([AllowAny])
def sign_in(request):
try:
user = get_object_or_404(Users, email=request.data.get('email'))
if not user.check_password(request.data.get('password')):
return Response({'error': 'Invalid password'}, status=status.HTTP_400_BAD_REQUEST)
refresh = RefreshToken.for_user(user)
serializer = UsersSerializer(instance=user)
return Response({
'refresh': str(refresh),
'access': str(refresh.access_token),
'user': serializer.data
}, status=status.HTTP_200_OK)
except KeyError:
return Response({'error': 'Email and password are required.'}, status=status.HTTP_400_BAD_REQUEST)
except Users.DoesNotExist:
return Response({'error': 'User does not exist.'}, status=status.HTTP_404_NOT_FOUND)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
curl -X GET http://localhost:8000/api/profile/ \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
import requests
headers = {
"Authorization": f"Bearer {access_token}"
}
response = requests.get("http://localhost:8000/api/profile/", headers=headers)
@permission_classes([AllowAny]))