Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions core/sessions/ldapauth/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,17 +554,17 @@ func (l *ldapAuthenticator) SetAuthToken(ctx context.Context, user *sessions.Use
// Check presence in local users table. Set localauth_user column true if present.
// This flag omits the session/token from being purged by the sync daemon/reaper.go
isLocalCLIAdmin := false
err = l.ds.QueryRowxContext(ctx, "SELECT EXISTS (SELECT 1 FROM users WHERE email = $1)", user.Email).Scan(&isLocalCLIAdmin)
err = tx.QueryRowxContext(ctx, "SELECT EXISTS (SELECT 1 FROM users WHERE email = $1)", user.Email).Scan(&isLocalCLIAdmin)
if err != nil {
return fmt.Errorf("error checking user presence in users table: %w", err)
}

// Remove any existing API tokens
if _, err = l.ds.ExecContext(ctx, "DELETE FROM ldap_user_api_tokens WHERE user_email = $1", user.Email); err != nil {
if _, err = tx.ExecContext(ctx, "DELETE FROM ldap_user_api_tokens WHERE user_email = $1", user.Email); err != nil {
return fmt.Errorf("error executing DELETE FROM ldap_user_api_tokens: %w", err)
}
// Create new API token for user
_, err = l.ds.ExecContext(
_, err = tx.ExecContext(
ctx,
"INSERT INTO ldap_user_api_tokens (user_email, user_role, localauth_user, token_key, token_salt, token_hashed_secret, created_at) VALUES ($1, $2, $3, $4, $5, $6, now())",
user.Email,
Expand Down
6 changes: 3 additions & 3 deletions core/sessions/oidcauth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,12 @@ func (oi *oidcAuthenticator) SetAuthToken(ctx context.Context, user *clsessions.

err = sqlutil.TransactDataSource(ctx, oi.ds, nil, func(tx sqlutil.DataSource) error {
// Remove any existing API tokens
if _, err = oi.ds.ExecContext(ctx, "DELETE FROM oidc_user_api_tokens WHERE user_email = $1", user.Email); err != nil {
if _, err = tx.ExecContext(ctx, "DELETE FROM oidc_user_api_tokens WHERE user_email = $1", user.Email); err != nil {
return fmt.Errorf("error executing DELETE FROM oidc_user_api_tokens: %w", err)
}
// Create new API token for user
_, err = oi.ds.ExecContext(ctx,
"INSERT INTO oidc_user_api_tokens (user_email, user_role, token_key, token_salt, token_hashed_secret, created_at) VALUES ($1, $2, $3, $4, $5, $6, now())",
_, err = tx.ExecContext(ctx,
"INSERT INTO oidc_user_api_tokens (user_email, user_role, token_key, token_salt, token_hashed_secret, created_at) VALUES ($1, $2, $3, $4, $5, now())",
user.Email,
user.Role,
token.AccessKey,
Expand Down
Loading