Skip to content

Authentication Implementation Plan

asyabetulkeskin edited this page Apr 7, 2026 · 3 revisions

Implementation Plan — Authentication Subgroup

1. Scope Definition

This implementation plan outlines the responsibilities and deliverables of the Authentication Subgroup.

The scope includes:

  • User registration (sign up)
  • User authentication (sign in / login)
  • JWT-based session management
  • Authenticated user retrieval
  • Logout functionality
  • Role-aware account creation
  • Cross-platform authentication support for web and mobile
  • Basic route/session protection for authenticated areas

The scope excludes:

  • Email verification
  • Forgot password / password reset
  • Social login providers
  • Multi-factor authentication
  • Advanced account recovery flows
  • Administrative user management features

2. System Overview

The authentication subsystem is designed to provide secure and consistent user access across the Neighborhood Emergency Preparedness Hub platform.

The system follows a stateless authentication model based on JSON Web Tokens (JWT). Users interact with the system through:

  • React-based web frontend
  • Android mobile application

Both clients communicate with a shared Django REST backend, which is responsible for:

  • User creation
  • Credential validation
  • Token generation
  • Protected endpoint authorization
  • Authenticated user retrieval

The authentication layer acts as the entry point for all role-based and personalized platform functionality.


3. User Registration (Sign Up) Flow

Objective

To allow new users to create an account in the system with the correct role and required profile information.

Description

Users provide registration data through web or mobile forms. The backend validates the input and creates a new account if all constraints are satisfied.

Functional Behavior

  • The system accepts registration input including:
    • Full name
    • Email address
    • Password
    • Password confirmation
    • Role selection
  • The system supports role-based registration for:
    • Standard users
    • Expert users
  • The system validates:
    • Required fields
    • Unique email address
    • Password confirmation consistency
    • Role-dependent field requirements where applicable
  • Upon successful validation:
    • A new user account is created
    • The account is persisted in the backend database
    • A success response is returned to the client

Endpoint

  • POST /register

4. Role-Aware Registration Logic

Objective

To ensure that user accounts are created with correct platform roles and required metadata.

Description

The platform distinguishes between different user roles during registration, which influences later authorization and platform behavior.

Functional Behavior

  • The system stores the selected user role as part of the account record
  • The system enforces role-specific validation rules when necessary
  • The system ensures that authenticated users carry their role information into later API responses
  • The system uses role information for downstream functionality such as expert-specific behavior and protected flows

5. User Authentication (Login / Sign In) Flow

Objective

To authenticate existing users and grant secure access to platform functionality.

Description

Registered users submit their credentials through the login interface. If the credentials are valid, the backend generates authentication tokens and returns them to the client.

Functional Behavior

  • The system accepts login input including:
    • Email address
    • Password
  • The system validates the submitted credentials against stored user records
  • Upon successful authentication:
    • A JWT access token is generated
    • A JWT refresh token is generated
    • Authenticated user information is returned
  • If authentication fails:
    • The system returns a structured error response
    • No authenticated session is established

Endpoint

  • POST /login

6. JWT-Based Session Management

Objective

To manage user sessions securely in a stateless manner.

Description

The system uses JWT tokens instead of server-stored sessions. This enables both web and mobile clients to authenticate with the same API structure.

Functional Behavior

  • The backend generates JWT tokens after successful login
  • The client stores the access token locally
  • The client includes the token in protected API requests using:
    • Authorization: Bearer <token>
  • The backend validates incoming tokens for protected endpoints
  • Access control is based on token validity and authenticated user identity
  • The system does not rely on server-side session state for authenticated requests

Protected Access Example

  • GET /me

7. Authenticated User Retrieval

Objective

To allow clients to retrieve the currently authenticated user’s information after login or app reload.

Description

The authenticated user endpoint provides a consistent way for clients to confirm session validity and load user-specific data.

Functional Behavior

  • The client sends an authenticated request with a valid bearer token
  • The backend resolves the user from the token
  • The backend returns user information required by the client
  • The endpoint supports persistence of login state across page refreshes or app restarts

Endpoint

  • GET /me

8. Logout Flow

Objective

To terminate the authenticated user session on the client side.

Description

Logout is handled primarily by removing locally stored authentication state and redirecting the user away from protected areas.

Functional Behavior

  • The client removes stored authentication tokens
  • The client clears local authenticated state
  • The user is redirected to a non-protected screen or landing page
  • Requests to protected endpoints fail once the token is removed or no longer sent
  • The backend may optionally acknowledge logout through a dedicated endpoint, but the primary control is client-side token disposal

Endpoint

  • POST /logout

9. Web Application Implementation

Objective

To provide a complete authentication user experience on the web platform.

Components

  • Landing page
  • Sign up page
  • Sign in page
  • Authentication context / provider
  • Protected route handling
  • API communication layer
  • Dashboard entry after login

Responsibilities

  • Render sign up and sign in forms
  • Validate user input before submission
  • Submit authentication requests to the backend
  • Store and manage token state in the browser
  • Restore authenticated state when possible
  • Protect authenticated routes from unauthenticated access
  • Provide logout functionality
  • Support usability features such as password visibility toggling and user feedback messages

10. Mobile Application Implementation

Objective

To provide a complete authentication user experience on the Android mobile application.

Components

  • LandingActivity
  • SignUpActivity
  • SignInActivity
  • DashboardActivity
  • TokenManager
  • Retrofit-based API layer

Responsibilities

  • Render sign up and sign in screens
  • Submit registration and login data to the backend
  • Persist authentication tokens locally on the device
  • Automatically attach bearer tokens to protected requests
  • Restore authenticated state when the app reopens
  • Navigate users into the dashboard after successful login
  • Clear authentication state on logout

11. Backend Implementation

Objective

To provide secure authentication APIs and enforce authentication rules.

Responsibilities

  • Define and maintain the custom user model
  • Validate registration input
  • Validate login credentials
  • Generate JWT access and refresh tokens
  • Expose authentication-related endpoints
  • Protect authenticated endpoints
  • Return structured API responses for success and failure cases

Key Backend Areas

  • models.py
  • serializers.py
  • views.py
  • urls.py
  • settings.py
  • Authentication-related test files

12. Data Validation and Integrity

Objective

To ensure correct user data enters the system and invalid states are prevented.

Functional Behavior

  • The system validates email uniqueness
  • The system validates password confirmation during registration
  • The system validates required input fields
  • The system rejects malformed or incomplete registration data
  • The system rejects invalid login credentials
  • The system returns explicit, structured validation messages to the client

13. Authorization and Protected Access

Objective

To ensure that only authenticated users can access protected parts of the system.

Description

Authentication establishes identity, while authorization determines whether a user may access a protected resource.

Functional Behavior

  • Protected endpoints require a valid JWT bearer token
  • Unauthenticated requests are rejected
  • The authenticated user identity is resolved from the provided token
  • Role information can be used by downstream subsystems to enable role-sensitive behavior
  • Clients must redirect or block users from protected screens when no valid authentication state exists

14. Cross-Platform Consistency

Objective

To provide the same authentication logic across web and mobile environments.

Principles

  • Shared Django backend for both clients
  • Common request and response structure
  • Common token-based authentication model
  • Consistent role handling
  • Consistent login, logout, and authenticated-user retrieval behavior
  • Similar user experience expectations across platforms

15. Error Handling and User Feedback

Objective

To provide clear and actionable responses for authentication failures and validation errors.

Functional Behavior

  • The system returns structured validation errors during registration
  • The system returns authentication failure responses for invalid login attempts
  • The web and mobile clients surface these errors to users in understandable form
  • The system avoids vague or silent failures
  • The system prevents invalid authentication state from being treated as successful login

16. Security Considerations

Objective

To provide a baseline secure authentication design appropriate for the current stage of the project.

Current Security Measures

  • Password-based authentication
  • JWT-based protected API access
  • Server-side credential validation
  • Protected authenticated-user endpoint
  • Client-side removal of tokens on logout

Current Limitations

  • No email verification yet
  • No forgot password flow yet
  • No multi-factor authentication
  • No advanced session invalidation or token blacklist workflow in the current scope

17. Deliverables

The Authentication Subgroup delivers:

  • Functional user registration
  • Functional user login
  • JWT-based authentication infrastructure
  • Authenticated user retrieval endpoint
  • Logout flow
  • Web authentication screens and token handling
  • Mobile authentication screens and token handling
  • Basic protected-route / protected-screen behavior
  • Role-aware account creation support

18. Current Limitations

The following limitations remain in the current implementation:

  • Email verification is not yet implemented
  • Forgot password / password reset is not yet implemented
  • There is no third-party login integration
  • There is no multi-factor authentication
  • Session invalidation is primarily client-side
  • Advanced account recovery flows are outside the current milestone scope

19. Future Extensions

The following features are planned but not included in the current implementation:

  • Email verification
  • Forgot password / password reset
  • External email provider integration
  • Stronger password policy enforcement
  • Multi-factor authentication
  • Improved session lifecycle management
  • Expanded account/profile recovery mechanisms

Clone this wiki locally