### Install drfpasswordless with pipenv
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Installs the drfpasswordless package using pipenv.
```bash
pipenv install drfpasswordless
```
--------------------------------
### Install twilio with pipenv
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Installs the Python Twilio module, required for mobile passwordless authentication.
```bash
pipenv install twilio
```
--------------------------------
### Email callback token message
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Example email body containing the 6-digit callback token sent to the user's email address after a passwordless login request.
```html
...
Your login token is 815381.
...
```
--------------------------------
### Use console email backend for development
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Sets up a dummy development SMTP server that prints sent emails to the console, useful for testing email sending without a real SMTP server.
```python
# Settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
```
--------------------------------
### Run database migrations
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Runs database migrations after adding drfpasswordless and the required Django Rest Framework apps.
```bash
python manage.py migrate
```
--------------------------------
### Configure DRF TokenAuthentication and INSTALLED_APPS
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Configures Django Rest Framework to use TokenAuthentication and adds the required apps (rest_framework, rest_framework.authtoken, drfpasswordless) to INSTALLED_APPS.
```python
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES':
('rest_framework.authentication.TokenAuthentication',
)}
INSTALLED_APPS = [
...
'rest_framework',
'rest_framework.authtoken',
'drfpasswordless',
...
]
```
--------------------------------
### Exchange callback token for auth token (step 6)
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Exchanges the 6-digit callback token for an authentication token. The client has 15 minutes to use the token; on success, returns an HTTP 200 response with the token.
```bash
curl -X POST -d "email=aaron@email.com&token=815381" localhost:8000/auth/token/
> HTTP/1.0 200 OK
> {"token":"76be2d9ecfaf5fa4226d722bzdd8a4fff207ed0e”}
```
--------------------------------
### POST /auth/token/
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Exchanges a valid 6-digit callback token for an authentication token.
```APIDOC
## POST /auth/token/
### Description
Exchanges a valid 6-digit callback token for an authentication token. The callback token must be used within 15 minutes of being issued.
### Method
POST
### Endpoint
/auth/token/
### Parameters
#### Request Body
- **email** (string) - Required - The email address that received the callback token.
- **mobile** (string) - Required - The mobile number that received the callback token.
- **token** (string) - Required - The 6-digit callback token.
### Request Example
```bash
curl -X POST -d "email=aaron@example.com&token=815381" localhost:8000/auth/token/
```
### Response
#### Success Response (200)
- **token** (string) - The authentication token to be used with Django Rest Framework's TokenAuthentication.
#### Response Example
```json
{"token":"76be2d9ecfaf5fa4226d722bzdd8a4fff207ed0e"}
```
```
--------------------------------
### Request callback token via email or mobile
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Sends a passwordless login request using either an email or mobile number. A 6-digit callback token is sent to the provided contact point.
```bash
curl -X POST -d "email=aaron@email.com" localhost:8000/auth/email/
// OR
curl -X POST -d "mobile=+15552143912" localhost:8000/auth/mobile/
```
--------------------------------
### POST /auth/email/
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Sends a 6-digit callback token to the provided email address.
```APIDOC
## POST /auth/email/
### Description
Sends a 6-digit callback token to the provided email address. If the email does not belong to an existing user, a new user is created.
### Method
POST
### Endpoint
/auth/email/
### Parameters
#### Request Body
- **email** (string) - Required - The email address to send the callback token to.
### Request Example
```bash
curl -X POST -d "email=aaron@email.com" localhost:8000/auth/email/
```
### Response
#### Success Response (200)
No response body is documented. The callback token is sent to the email address.
```
--------------------------------
### Configure PASSWORDLESS_EMAIL_NOREPLY_ADDRESS
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Specifies the email address from which callback tokens are sent using the PASSWORDLESS_EMAIL_NOREPLY_ADDRESS setting.
```python
PASSWORDLESS_AUTH = {
..
'PASSWORDLESS_AUTH_TYPES': ['EMAIL',],
'PASSWORDLESS_EMAIL_NOREPLY_ADDRESS': 'noreply@example.com',
..
}
```
--------------------------------
### Configure custom email template
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Specifies a custom email template for the callback token email. The template renders a single variable {{ callback_token }} which is the 6-digit callback token.
```bash
PASSWORDLESS_AUTH = {
...
'PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME': "mytemplate.html"
}
```
--------------------------------
### Request email callback token with curl
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Sends a passwordless login request using an email alias. The server responds by sending a 6-digit callback token to the provided email address.
```bash
curl -X POST -d “email=aaron@email.com” localhost:8000/auth/email/
```
--------------------------------
### POST /auth/mobile/
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Sends a 6-digit callback token to the provided mobile number.
```APIDOC
## POST /auth/mobile/
### Description
Sends a 6-digit callback token to the provided mobile number. If the mobile number does not belong to an existing user, a new user is created.
### Method
POST
### Endpoint
/auth/mobile/
### Parameters
#### Request Body
- **mobile** (string) - Required - The mobile number to send the callback token to.
### Request Example
```bash
curl -X POST -d "mobile=+15552143912" localhost:8000/auth/mobile/
```
### Response
#### Success Response (200)
No response body is documented. The callback token is sent to the mobile number.
```
--------------------------------
### Exchange callback token for auth token with curl
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Submits the email and callback token to the token endpoint. On success, returns an HTTP 200 response with an authentication token for use with Django Rest Framework's TokenAuthentication.
```bash
curl -X POST -d "email=aaron@example.com&token=815381" localhost:8000/auth/token/
> HTTP/1.0 200 OK
> {"token":"76be2d9ecfaf5fa4226d722bzdd8a4fff207ed0e”}
```
--------------------------------
### Include drfpasswordless URLs
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Adds drfpasswordless URLs to the project's urlpatterns, making the passwordless authentication endpoints available.
```python
from django.urls import path, include
urlpatterns = [
..
path('', include('drfpasswordless.urls')),
..
]
```
--------------------------------
### Django REST Framework Passwordless DEFAULTS dictionary
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Full list of configurable defaults for django-rest-framework-passwordless. Shows all settings with their default values, including auth types, token expiry, verification flags, email/SMS templates, and callback functions. Use as a reference for overriding settings in your Django project.
```python
DEFAULTS = {
# Allowed auth types, can be EMAIL, MOBILE, or both.
'PASSWORDLESS_AUTH_TYPES': ['EMAIL'],
# URL Prefix for Authentication Endpoints
'PASSWORDLESS_AUTH_PREFIX': 'auth/',
# URL Prefix for Verification Endpoints
'PASSWORDLESS_VERIFY_PREFIX': 'auth/verify/',
# Amount of time that tokens last, in seconds
'PASSWORDLESS_TOKEN_EXPIRE_TIME': 15 * 60,
# The user's email field name
'PASSWORDLESS_USER_EMAIL_FIELD_NAME': 'email',
# The user's mobile field name
'PASSWORDLESS_USER_MOBILE_FIELD_NAME': 'mobile',
# Marks itself as verified the first time a user completes auth via token.
# Automatically unmarks itself if email is changed.
'PASSWORDLESS_USER_MARK_EMAIL_VERIFIED': False,
'PASSWORDLESS_USER_EMAIL_VERIFIED_FIELD_NAME': 'email_verified',
# Marks itself as verified the first time a user completes auth via token.
# Automatically unmarks itself if mobile number is changed.
'PASSWORDLESS_USER_MARK_MOBILE_VERIFIED': False,
'PASSWORDLESS_USER_MOBILE_VERIFIED_FIELD_NAME': 'mobile_verified',
# The email the callback token is sent from
'PASSWORDLESS_EMAIL_NOREPLY_ADDRESS': None,
# The email subject
'PASSWORDLESS_EMAIL_SUBJECT': "Your Login Token",
# A plaintext email message overridden by the html message. Takes one string.
'PASSWORDLESS_EMAIL_PLAINTEXT_MESSAGE': "Enter this token to sign in: %s",
# The email template name.
'PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME': "passwordless_default_token_email.html",
# Your twilio number that sends the callback tokens.
'PASSWORDLESS_MOBILE_NOREPLY_NUMBER': None,
# The message sent to mobile users logging in. Takes one string.
'PASSWORDLESS_MOBILE_MESSAGE': "Use this code to log in: %s",
# Registers previously unseen aliases as new users.
'PASSWORDLESS_REGISTER_NEW_USERS': True,
# Suppresses actual SMS for testing
'PASSWORDLESS_TEST_SUPPRESSION': False,
# Context Processors for Email Template
'PASSWORDLESS_CONTEXT_PROCESSORS': [],
# The verification email subject
'PASSWORDLESS_EMAIL_VERIFICATION_SUBJECT': "Your Verification Token",
# A plaintext verification email message overridden by the html message. Takes one string.
'PASSWORDLESS_EMAIL_VERIFICATION_PLAINTEXT_MESSAGE': "Enter this verification code: %s",
# The verification email template name.
'PASSWORDLESS_EMAIL_VERIFICATION_TOKEN_HTML_TEMPLATE_NAME': "passwordless_default_verification_token_email.html",
# The message sent to mobile users logging in. Takes one string.
'PASSWORDLESS_MOBILE_VERIFICATION_MESSAGE': "Enter this verification code: %s",
# Automatically send verification email or sms when a user changes their alias.
'PASSWORDLESS_AUTO_SEND_VERIFICATION_TOKEN': False,
# What function is called to construct an authentication tokens when
# exchanging a passwordless token for a real user auth token. This function
# should take a user and return a tuple of two values. The first value is
# the token itself, the second is a boolean value representating whether
# the token was newly created.
'PASSWORDLESS_AUTH_TOKEN_CREATOR': 'drfpasswordless.utils.create_authentication_token',
# What function is called to construct a serializer for drf tokens when
# exchanging a passwordless token for a real user auth token.
'PASSWORDLESS_AUTH_TOKEN_SERIALIZER': 'drfpasswordless.serializers.TokenResponseSerializer',
# A dictionary of demo user's primary key mapped to their static pin
'PASSWORDLESS_DEMO_USERS': {},
# configurable function for sending email
'PASSWORDLESS_EMAIL_CALLBACK': 'drfpasswordless.utils.send_email_with_callback_token',
# configurable function for sending sms
'PASSWORDLESS_SMS_CALLBACK': 'drfpasswordless.utils.send_sms_with_callback_token',
# Token Generation Retry Count
'PASSWORDLESS_TOKEN_GENERATION_ATTEMPTS': 3
}
```
--------------------------------
### Configure PASSWORDLESS_AUTH_TYPES
Source: https://github.com/aaronn/django-rest-framework-passwordless/blob/master/README.md
Sets which contact point types are allowed for authentication. Available options are EMAIL and MOBILE. By default, drfpasswordless looks for fields named email or mobile on the User model; if an alias doesn't belong to any user, a new user is created.
```python
PASSWORDLESS_AUTH = {
..
'PASSWORDLESS_AUTH_TYPES': ['EMAIL', 'MOBILE'],
..
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.