mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-16 07:46:35 +00:00
The session cookie has no Max-Age, so it is lost when the browser closes. The password flow compensates via a "Remember me" checkbox issuing an LTA cookie; OAuth2/OIDC sign-in had no such UI. Issuing a regular LTA cookie after an OAuth callback would skip the IdP for LOGIN_REMEMBER_DAYS. Instead, this introduces a separate LongTermAuthorizationSSO purpose: the cookie is opt-in via the existing "Remember me" checkbox, and when presented without a session, autoSignIn redirects through the IdP with OIDC prompt=none for silent re-auth. On login_required / interaction_required / consent_required / account_selection_required we transparently fall back to interactive sign-in. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12321 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forgejo.org/models/auth"
|
|
"forgejo.org/models/db"
|
|
user_model "forgejo.org/models/user"
|
|
)
|
|
|
|
// DeleteSource deletes a AuthSource record in DB.
|
|
func DeleteSource(ctx context.Context, source *auth.Source) error {
|
|
count, err := db.GetEngine(ctx).Count(&user_model.User{LoginSource: source.ID})
|
|
if err != nil {
|
|
return err
|
|
} else if count > 0 {
|
|
return auth.ErrSourceInUse{
|
|
ID: source.ID,
|
|
}
|
|
}
|
|
|
|
count, err = db.GetEngine(ctx).Count(&user_model.ExternalLoginUser{LoginSourceID: source.ID})
|
|
if err != nil {
|
|
return err
|
|
} else if count > 0 {
|
|
return auth.ErrSourceInUse{
|
|
ID: source.ID,
|
|
}
|
|
}
|
|
|
|
if registerableSource, ok := source.Cfg.(auth.RegisterableSource); ok {
|
|
if err := registerableSource.UnregisterSource(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if _, err := db.GetEngine(ctx).Where("login_source_id = ?", source.ID).Delete(new(auth.AuthorizationToken)); err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = db.GetEngine(ctx).ID(source.ID).Delete(new(auth.Source))
|
|
return err
|
|
}
|