raystack / raystack/frontier

Add periodic validation of auth tokens to expire sessions for deactivated users

Open
#1,051 1 comment 0 reactions 0 assignees View on GitHub

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.).

https://github.com/raystack/frontier/blob/33bbf4a9207d23fbd83573dda24a59a7048da3ea/core/authenticate/service.go#L660-L667

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:

  1. Get new access tokens without requiring user re-authentication
  2. Detect when the user's access has been revoked (refresh will fail)
  3. Maintain longer sessions while still ensuring the user's access is valid

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.