API Reference
This section provides a detailed reference for the project's API, including data models and views.
Data Models
This section describes the database models used in the auth_api application.
auth_api.models
ApiKey
Bases: Model
Represents a unique API key for a specific App.
API keys are used to authenticate requests made to the service on behalf of an application.
App
Bases: Model
Represents an application created by a developer.
Each app has a unique ID and serves as a container for its own set of users, API keys, and authentication configurations.
OAuthConfig
Bases: Model
Stores OAuth 2.0 configuration for an App and a specific provider.
This model holds the client ID, client secret, and redirect URI required to perform OAuth flows with providers like GitHub or Google.
API Views
This section describes the API views that handle authentication and user management.
auth_api.views
CheckUserLoginView
Bases: APIView
Checks the login status of a user.
This view provides a simple way to check if a user is considered to be logged in, based on their last login time.
CredentialsSignInView
Bases: APIView
Handles user sign-in with email and password.
This view authenticates a user against their stored credentials for a given application. It returns a JWT upon successful authentication.
CredentialsSignUpView
Bases: APIView
Handles user sign-up with email and password.
This view creates a new user account for a given application, provided the email is not already in use for that app. It returns a JWT upon successful registration.
MagicLinkVerifyView
Bases: APIView
Verifies a magic link token.
This view validates the token sent to a user's email. If the token is valid, it updates the user's last login time and returns the token to complete the sign-in process.
MagicLinkView
Bases: APIView
Initiates the magic link authentication flow.
This view generates a single-use sign-in link for a user and sends it to their email address. It creates the user if they do not already exist.
OAuthCallbackView
Bases: APIView
Handles the callback from the OAuth 2.0 provider.
This view receives the authorization code from the provider, exchanges it for an access token, fetches the user's profile information, creates or updates the user in the database, and finally issues a JWT.
OAuthRedirectView
Bases: APIView
Initiates the OAuth 2.0 authentication flow.
This view constructs the appropriate authorization URL for a given provider (e.g., GitHub) and redirects the user to it.
generate_jwt_token(user, app)
Generate JWT token for user with app context