Skip to content
Open
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
10 changes: 5 additions & 5 deletions internal/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (a *API) adminUserUpdate(w http.ResponseWriter, r *http.Request) error {
}
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserModifiedAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserModifiedAction, map[string]interface{}{
"user_id": user.ID,
"user_email": user.Email,
"user_phone": user.Phone,
Expand Down Expand Up @@ -457,7 +457,7 @@ func (a *API) adminUserCreate(w http.ResponseWriter, r *http.Request) error {

user.Identities = identities

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserSignedUpAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserSignedUpAction, map[string]interface{}{
"user_id": user.ID,
"user_email": user.Email,
"user_phone": user.Phone,
Expand Down Expand Up @@ -527,7 +527,7 @@ func (a *API) adminUserDelete(w http.ResponseWriter, r *http.Request) error {
}

err := db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserDeletedAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserDeletedAction, map[string]interface{}{
"user_id": user.ID,
"user_email": user.Email,
"user_phone": user.Phone,
Expand Down Expand Up @@ -579,7 +579,7 @@ func (a *API) adminUserDeleteFactor(w http.ResponseWriter, r *http.Request) erro
db := a.db.WithContext(ctx)

err := db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.DeleteFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.DeleteFactorAction, map[string]interface{}{
"user_id": user.ID,
"factor_id": factor.ID,
}); terr != nil {
Expand Down Expand Up @@ -633,7 +633,7 @@ func (a *API) adminUserUpdateFactor(w http.ResponseWriter, r *http.Request) erro
}
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UpdateFactorAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UpdateFactorAction, map[string]interface{}{
"user_id": user.ID,
"factor_id": factor.ID,
"factor_type": factor.FactorType,
Expand Down
6 changes: 3 additions & 3 deletions internal/api/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (a *API) createAccountFromExternalIdentity(tx *storage.Connection, r *http.
return 0, nil, apierrors.NewInternalServerError("Error updating user").WithInternalError(terr)
}
if decision.CandidateEmail.Verified || config.Mailer.Autoconfirm {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserSignedUpAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserSignedUpAction, map[string]interface{}{
"provider": providerType,
}); terr != nil {
return 0, nil, terr
Expand Down Expand Up @@ -436,7 +436,7 @@ func (a *API) createAccountFromExternalIdentity(tx *storage.Connection, r *http.
}
}
} else {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.LoginAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.LoginAction, map[string]interface{}{
"provider": providerType,
}); terr != nil {
return 0, nil, terr
Expand Down Expand Up @@ -491,7 +491,7 @@ func (a *API) processInvite(r *http.Request, tx *storage.Connection, userData *p
return nil, apierrors.NewInternalServerError("Database error updating user").WithInternalError(err)
}

if err := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.InviteAcceptedAction, "", map[string]interface{}{
if err := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.InviteAcceptedAction, map[string]interface{}{
"provider": providerType,
}); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/api/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (a *API) DeleteIdentity(w http.ResponseWriter, r *http.Request) error {

provider := identityToBeDeleted.Provider
err = db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.IdentityUnlinkAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.IdentityUnlinkAction, map[string]interface{}{
"identity_id": identityToBeDeleted.ID,
"provider": identityToBeDeleted.Provider,
"provider_id": identityToBeDeleted.ProviderID,
Expand Down
2 changes: 1 addition & 1 deletion internal/api/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (a *API) Invite(w http.ResponseWriter, r *http.Request) error {
user.Identities = []models.Identity{*identity}
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserInvitedAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserInvitedAction, map[string]interface{}{
"user_id": user.ID,
"user_email": user.Email,
}); terr != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a *API) Logout(w http.ResponseWriter, r *http.Request) error {
u := getUser(ctx)

err := db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, u, models.LogoutAction, "", nil); terr != nil {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, u, models.LogoutAction, nil); terr != nil {
return terr
}

Expand Down
2 changes: 1 addition & 1 deletion internal/api/magic_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (a *API) MagicLink(w http.ResponseWriter, r *http.Request) error {
}

err = db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, "", nil); terr != nil {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, nil); terr != nil {
return terr
}
return a.sendMagicLink(r, tx, user, flowType)
Expand Down
4 changes: 2 additions & 2 deletions internal/api/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (a *API) adminGenerateLink(w http.ResponseWriter, r *http.Request) error {
var terr error
switch params.Type {
case mail.MagicLinkVerification, mail.RecoveryVerification:
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, "", nil); terr != nil {
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, nil); terr != nil {
return terr
}
user.RecoveryToken = hashedToken
Expand Down Expand Up @@ -180,7 +180,7 @@ func (a *API) adminGenerateLink(w http.ResponseWriter, r *http.Request) error {
}
user.Identities = []models.Identity{*identity}
}
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserInvitedAction, "", map[string]interface{}{
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.UserInvitedAction, map[string]interface{}{
"user_id": user.ID,
"user_email": user.Email,
}); terr != nil {
Expand Down
18 changes: 9 additions & 9 deletions internal/api/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (a *API) enrollPhoneFactor(w http.ResponseWriter, r *http.Request, params *
if terr := tx.Create(factor); terr != nil {
return terr
}
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.EnrollFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.EnrollFactorAction, map[string]interface{}{
"factor_id": factor.ID,
"factor_type": factor.FactorType,
}); terr != nil {
Expand Down Expand Up @@ -240,7 +240,7 @@ func (a *API) enrollWebAuthnFactor(w http.ResponseWriter, r *http.Request, param
if terr := tx.Create(factor); terr != nil {
return terr
}
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.EnrollFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.EnrollFactorAction, map[string]interface{}{
"factor_id": factor.ID,
"factor_type": factor.FactorType,
}); terr != nil {
Expand Down Expand Up @@ -309,7 +309,7 @@ func (a *API) enrollTOTPFactor(w http.ResponseWriter, r *http.Request, params *E
return terr
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.EnrollFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.EnrollFactorAction, map[string]interface{}{
"factor_id": factor.ID,
}); terr != nil {
return terr
Expand Down Expand Up @@ -437,7 +437,7 @@ func (a *API) challengePhoneFactor(w http.ResponseWriter, r *http.Request) error
return terr
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.CreateChallengeAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.CreateChallengeAction, map[string]interface{}{
"factor_id": factor.ID,
"factor_status": factor.Status,
}); terr != nil {
Expand Down Expand Up @@ -469,7 +469,7 @@ func (a *API) challengeTOTPFactor(w http.ResponseWriter, r *http.Request) error
if terr := factor.WriteChallengeToDatabase(tx, challenge); terr != nil {
return terr
}
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.CreateChallengeAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.CreateChallengeAction, map[string]interface{}{
"factor_id": factor.ID,
"factor_status": factor.Status,
}); terr != nil {
Expand Down Expand Up @@ -692,7 +692,7 @@ func (a *API) verifyTOTPFactor(w http.ResponseWriter, r *http.Request, params *V
verified := false
err = db.Transaction(func(tx *storage.Connection) error {
var terr error
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.VerifyFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.VerifyFactorAction, map[string]interface{}{
"factor_id": factor.ID,
"challenge_id": challenge.ID,
"factor_type": factor.FactorType,
Expand Down Expand Up @@ -844,7 +844,7 @@ func (a *API) verifyPhoneFactor(w http.ResponseWriter, r *http.Request, params *
verified := false
err = db.Transaction(func(tx *storage.Connection) error {
var terr error
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.VerifyFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.VerifyFactorAction, map[string]interface{}{
"factor_id": factor.ID,
"challenge_id": challenge.ID,
"factor_type": factor.FactorType,
Expand Down Expand Up @@ -960,7 +960,7 @@ func (a *API) verifyWebAuthnFactor(w http.ResponseWriter, r *http.Request, param
verified := false
err = db.Transaction(func(tx *storage.Connection) error {
var terr error
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.VerifyFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.VerifyFactorAction, map[string]interface{}{
"factor_id": factor.ID,
"challenge_id": challenge.ID,
"factor_type": factor.FactorType,
Expand Down Expand Up @@ -1078,7 +1078,7 @@ func (a *API) UnenrollFactor(w http.ResponseWriter, r *http.Request) error {
if terr := tx.Destroy(factor); terr != nil {
return terr
}
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UnenrollFactorAction, utilities.GetIPAddress(r), map[string]interface{}{
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UnenrollFactorAction, map[string]interface{}{
"factor_id": factor.ID,
"factor_status": factor.Status,
"session_id": session.ID,
Expand Down
4 changes: 2 additions & 2 deletions internal/api/oauthserver/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (s *Server) handleAuthorizationCodeGrant(ctx context.Context, w http.Respon
authMethod := models.OAuthProviderAuthorizationCode

// Create audit log entry for OAuth token exchange
if terr := models.NewAuditLogEntry(s.config.AuditLog, r, tx, user, models.LoginAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(s.config.AuditLog, r, tx, user, models.LoginAction, map[string]interface{}{
"provider_type": "oauth_provider_authorization_code",
"client_id": client.ID.String(),
}); terr != nil {
Expand Down Expand Up @@ -610,7 +610,7 @@ func (s *Server) UserRevokeOAuthGrant(w http.ResponseWriter, r *http.Request) er
}

// Create audit log entry
if terr := models.NewAuditLogEntry(s.config.AuditLog, r, tx, user, models.TokenRevokedAction, "", map[string]interface{}{
if terr := models.NewAuditLogEntry(s.config.AuditLog, r, tx, user, models.TokenRevokedAction, map[string]interface{}{
"oauth_client_id": clientID.String(),
"action": "revoke_oauth_grant",
}); terr != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (a *API) SmsOtp(w http.ResponseWriter, r *http.Request) error {

messageID := ""
err = db.Transaction(func(tx *storage.Connection) error {
if err := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, "", map[string]interface{}{
if err := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, map[string]interface{}{
"channel": params.Channel,
}); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions internal/api/passkey_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/supabase/auth/internal/api/apierrors"
"github.com/supabase/auth/internal/models"
"github.com/supabase/auth/internal/storage"
"github.com/supabase/auth/internal/utilities"
)

// AdminPasskeyList handles GET /admin/users/{user_id}/passkeys.
Expand Down Expand Up @@ -58,7 +57,7 @@ func (a *API) AdminPasskeyDelete(w http.ResponseWriter, r *http.Request) error {
return terr
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.PasskeyDeletedAction, utilities.GetIPAddress(r), map[string]any{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, adminUser, models.PasskeyDeletedAction, map[string]any{
"user_id": user.ID,
"passkey_id": cred.ID,
}); terr != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/passkey_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (a *API) PasskeyAuthenticationVerify(w http.ResponseWriter, r *http.Request
return terr
}

if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.LoginAction, utilities.GetIPAddress(r), map[string]any{
if terr = models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.LoginAction, map[string]any{
"passkey_id": passkeyCredential.ID,
}); terr != nil {
return terr
Expand Down
4 changes: 2 additions & 2 deletions internal/api/passkey_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (a *API) PasskeyUpdate(w http.ResponseWriter, r *http.Request) error {
return terr
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.PasskeyUpdatedAction, utilities.GetIPAddress(r), map[string]any{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.PasskeyUpdatedAction, map[string]any{
"passkey_id": cred.ID,
}); terr != nil {
return terr
Expand Down Expand Up @@ -132,7 +132,7 @@ func (a *API) PasskeyDelete(w http.ResponseWriter, r *http.Request) error {
return terr
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.PasskeyDeletedAction, utilities.GetIPAddress(r), map[string]any{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.PasskeyDeletedAction, map[string]any{
"passkey_id": cred.ID,
}); terr != nil {
return terr
Expand Down
2 changes: 1 addition & 1 deletion internal/api/passkey_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (a *API) PasskeyRegistrationVerify(w http.ResponseWriter, r *http.Request)
return terr
}

if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.PasskeyCreatedAction, utilities.GetIPAddress(r), map[string]any{
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.PasskeyCreatedAction, map[string]any{
"passkey_id": passkeyCredential.ID,
}); terr != nil {
return terr
Expand Down
2 changes: 1 addition & 1 deletion internal/api/reauthenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (a *API) Reauthenticate(w http.ResponseWriter, r *http.Request) error {

messageID := ""
err := db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserReauthenticateAction, "", nil); terr != nil {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserReauthenticateAction, nil); terr != nil {
return terr
}
if email != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a *API) Recover(w http.ResponseWriter, r *http.Request) error {
}

err = db.Transaction(func(tx *storage.Connection) error {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, "", nil); terr != nil {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, nil); terr != nil {
return terr
}
return a.sendPasswordRecovery(r, tx, user, flowType)
Expand Down
4 changes: 2 additions & 2 deletions internal/api/resend.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (a *API) Resend(w http.ResponseWriter, r *http.Request) error {
err = db.Transaction(func(tx *storage.Connection) error {
switch params.Type {
case mail.SignupVerification:
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserConfirmationRequestedAction, "", nil); terr != nil {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserConfirmationRequestedAction, nil); terr != nil {
return terr
}
flowType := getFlowFromChallenge(params.CodeChallenge)
Expand All @@ -135,7 +135,7 @@ func (a *API) Resend(w http.ResponseWriter, r *http.Request) error {
}
return a.sendConfirmation(r, tx, user, flowType)
case smsVerification:
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, "", nil); terr != nil {
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserRecoveryRequestedAction, nil); terr != nil {
return terr
}
mID, terr := a.sendPhoneConfirmation(r, tx, user, params.Phone, phoneConfirmationOtp, sms_provider.SMSProvider)
Expand Down
Loading