Authentication Flow
How Identity works in the MehguViewer Federation.
Authentication Flow
MehguViewer uses a strict OIDC (OpenID Connect) flow to handle identity. This ensures that user credentials never touch the Content Servers (Core), and users can maintain a single identity across the entire federation.
The Actors
- User (Resource Owner): The person trying to access content.
- Client (Web/App): The interface the user is using.
- Auth Server (Identity Provider): The server that holds the user database and issues tokens.
- Core Server (Resource Server): The server that holds the Manga/Anime content.
The Token Lifecycle
1. Login (Authorization Code Flow)
The Client redirects the user to the Auth Server's /authorize endpoint.
- The user enters their credentials on the Auth Server.
- The Auth Server redirects back to the Client with a
code. - The Client exchanges the
codefor an Access Token and a Refresh Token.
2. Access Token (JWT)
The Access Token is a short-lived JSON Web Token (e.g., 15 minutes). It contains:
sub: The User ID.iss: The Auth Server URL.exp: Expiration time.global_level: The user's level.
3. Making Requests
When the Client requests content from a Core Server, it sends the Access Token in the header:
GET /api/v1/series/123 HTTP/1.1
Host: core.mehgu.example.com
Authorization: Bearer <ACCESS_TOKEN>4. Verification (Stateless)
The Core Server receives the request. It does not contact the Auth Server to validate every request. Instead:
- It fetches the Public Keys from
https://auth.mehgu.example.com/.well-known/jwks.json(cached). - It verifies the JWT signature using the public key.
- It checks if the token is expired (
exp).
If valid, the request proceeds.
Security Features
Global Blocklist
The Auth Server maintains a list of users that a user has blocked.
- Client Responsibility: The Client fetches the blocklist (
GET /api/v1/me/relationships) and filters out content/comments from blocked users locally. - Core Responsibility: In the future, Core servers may periodically sync blocklists for server-side filtering, but currently, it is client-side for privacy.
Session Management
Users can view and revoke their sessions via GET /api/v1/sessions. Revoking a session invalidates the Refresh Token, preventing new Access Tokens from being issued. Existing Access Tokens remain valid until they expire (short-lived).
Profile Management
Users have full control over their account data.
- Update Profile:
PATCH /api/v1/me(Display Name, Avatar, Locale). - Change Password:
PUT /api/v1/me/password. - Delete Account:
DELETE /api/v1/me(Triggers GDPR erasure).