Add periodic validation of auth tokens to expire sessions for deactivated users
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 344
- Forks
- 47
- Avg merge
- 4d 4h
- Merged PRs (30d)
- 26
Description
Description
The Authenticate and AuthCallback APIs support multiple Authentication Strategies, such as mailotp and Google login. Once the login is successful, a session is created in the database. The session ID has an expiry time of 1 month.
The Authenticate call initiates a StartFlow procedure, which creates a Flow with the configuration settings of the strategy. Once the AuthCallback is called, the respective flow entry is consumed, and a session is created with the flow ID in the database. The session ID is sent to the browser client with Cookies in the Response header after encoding it.
For the Google strategy, the AuthCallback function fetches the authentication token for the user from the Google Authentication server. Frontier uses this token to retrieve the user's profile information (such as email address, etc.).
After that, it creates the session. The session is valid for the next 30 days, even if the user is no longer valid.
Approach
Google strategy
One approach could be to store the refresh token with session metadata.
// In applyOIDC in core/authenticate/service.go
authToken, err := idp.Token(ctx, request.Code, flow.Nonce)
if err != nil {
return nil, err
}
// Get user info and create/get user
oauthProfile, err := idp.GetUser(ctx, authToken)
if err != nil {
return nil, err
}
newUser, err := s.getOrCreateUser(ctx, oauthProfile.Email, oauthProfile.Name)
if err != nil {
return nil, err
}
// Create session with tokens
session, err := h.sessionService.Create(ctx, newUser.ID)
if err != nil {
return nil, err
}
// Store both ID token and refresh token
session.Metadata["id_token"] = authToken.Extra("id_token").(string)
session.Metadata["refresh_token"] = authToken.RefreshToken
session.Metadata["oidc_provider"] = flow.Method
return &RegistrationFinishResponse{
User: newUser,
Flow: flow,
}, nil
Mailotp strategy
- If authenticated via email OTP, require re-verification every X days
Benefits:
- Get new access tokens without requiring user re-authentication
- Detect when the user's access has been revoked (refresh will fail)
- Maintain longer sessions while still ensuring the user's access is valid
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with core/authenticate/service.go, especially the Authenticate and AuthCallback flow and the applyOIDC section around the referenced lines. Trace how sessions are created and how mailotp and Google strategies represent authentication state. Done should include a decided validation or re-verification approach that expires sessions when a user's authentication is no longer valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- authentication
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100