Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions admin/server/auth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
cookieFieldRedirect = "redirect"
cookieFieldCustomDomainFlow = "custom_domain_flow"
cookieFieldAccessToken = "access_token"
browserSessionTTL = 14 * 24 * time.Hour
)

// RegisterEndpoints adds HTTP endpoints for auth.
Expand Down Expand Up @@ -342,7 +343,8 @@ func (a *Authenticator) authLoginCallback(w http.ResponseWriter, r *http.Request
}

// Issue a new persistent auth token
authToken, err := a.admin.IssueUserAuthToken(r.Context(), user.ID, database.AuthClientIDRillWeb, "Browser session", nil, nil, false)
ttl := browserSessionTTL
authToken, err := a.admin.IssueUserAuthToken(r.Context(), user.ID, database.AuthClientIDRillWeb, "Browser session", nil, &ttl, false)
Comment on lines +346 to +347
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundant variable, can just do &browserSessionTTL directly

Comment on lines +346 to +347
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it also needs to integrate with CookieRefreshMiddleware to extend the token's TTL when the token is used. Or something like that – at least we don't want to log people out every 14 days if they are regular users.

(Also, since updating the TTL in the DB is more expensive than updating the cookie, it would need to not do this too often, e.g. only when close to expiration.).

Or do you have a better idea?

if err != nil {
http.Error(w, fmt.Sprintf("failed to issue API token: %s", err), http.StatusInternalServerError)
return
Expand Down Expand Up @@ -405,7 +407,8 @@ func (a *Authenticator) authLoginCustomDomainCallback(w http.ResponseWriter, r *
http.Error(w, err.Error(), http.StatusUnauthorized)
return
}
newAuthToken, err := a.admin.IssueUserAuthToken(r.Context(), validated.OwnerID(), database.AuthClientIDRillWeb, "Browser session", nil, nil, false)
ttl := browserSessionTTL
newAuthToken, err := a.admin.IssueUserAuthToken(r.Context(), validated.OwnerID(), database.AuthClientIDRillWeb, "Browser session", nil, &ttl, false)
if err != nil {
http.Error(w, fmt.Sprintf("failed to issue API token: %s", err), http.StatusInternalServerError)
return
Expand Down
Loading