Skip to content

Commit 31f9669

Browse files
brechtvlbartvdbraak
authored andcommitted
BLENDER: Remember login for OAuth / Blender ID
Otherwise for some browsers, users have to login again for every session.
1 parent ff7009f commit 31f9669

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

routers/web/auth/oauth.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"code.gitea.io/gitea/modules/session"
2222
"code.gitea.io/gitea/modules/setting"
2323
"code.gitea.io/gitea/modules/templates"
24+
"code.gitea.io/gitea/modules/timeutil"
2425
"code.gitea.io/gitea/modules/web/middleware"
26+
auth_service "code.gitea.io/gitea/services/auth"
2527
source_service "code.gitea.io/gitea/services/auth/source"
2628
"code.gitea.io/gitea/services/auth/source/oauth2"
2729
"code.gitea.io/gitea/services/context"
@@ -368,6 +370,17 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
368370
return
369371
}
370372

373+
// BLENDER: remember login for Blender ID.
374+
// A proper OAuth implementation would check how long the access token is
375+
// valid depending on the provider, but since this is only for Blender ID
376+
// we can just set days in the Gitea config.
377+
nt, token, err := auth_service.CreateAuthTokenForUserID(ctx, u.ID)
378+
if err != nil {
379+
ctx.ServerError("CreateAuthTokenForUserID", err)
380+
return
381+
}
382+
ctx.SetSiteCookie(setting.CookieRememberName, nt.ID+":"+token, setting.LogInRememberDays*timeutil.Day)
383+
371384
// force to generate a new CSRF token
372385
ctx.Csrf.PrepareForSessionUser(ctx)
373386

0 commit comments

Comments
 (0)