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
2 changes: 1 addition & 1 deletion internal/api/anonymous.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ func (a *API) SignupAnonymously(w http.ResponseWriter, r *http.Request) error {
}

metering.RecordLogin(metering.LoginTypeAnonymous, newUser.ID, nil)
return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}
6 changes: 6 additions & 0 deletions internal/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func sendJSON(w http.ResponseWriter, status int, obj interface{}) error {
return shared.SendJSON(w, status, obj)
}

func sendTokenJSON(w http.ResponseWriter, status int, obj interface{}) error {
w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate")
w.Header().Set("Pragma", "no-cache")
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

These apply just in general to all Auth requests, so maybe it can be added as middleware?

return shared.SendJSON(w, status, obj)
}

func isAdmin(u *models.User, config *conf.GlobalConfiguration) bool {
return config.JWT.Aud == u.Aud && u.HasRole(config.JWT.AdminGroupName)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/api/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (a *API) verifyTOTPFactor(w http.ResponseWriter, r *http.Request, params *V
Provider: metering.ProviderMFATOTP,
})

return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)

}

Expand Down Expand Up @@ -892,7 +892,7 @@ func (a *API) verifyPhoneFactor(w http.ResponseWriter, r *http.Request, params *
Provider: metering.ProviderMFAPhone,
})

return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}

func (a *API) verifyWebAuthnFactor(w http.ResponseWriter, r *http.Request, params *VerifyFactorParams) error {
Expand Down Expand Up @@ -1012,7 +1012,7 @@ func (a *API) verifyWebAuthnFactor(w http.ResponseWriter, r *http.Request, param
Provider: metering.ProviderMFAWebAuthn,
})

return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}

func (a *API) VerifyFactor(w http.ResponseWriter, r *http.Request) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (a *API) Signup(w http.ResponseWriter, r *http.Request) error {
"immediate_login_after_signup": true,
},
})
return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}
if user.HasBeenInvited() {
// Remove sensitive fields
Expand Down
4 changes: 2 additions & 2 deletions internal/api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (a *API) ResourceOwnerPasswordGrant(ctx context.Context, w http.ResponseWri
metering.RecordLogin(metering.LoginTypePassword, user.ID, &metering.LoginData{
Provider: provider,
})
return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}

func (a *API) PKCE(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
Expand Down Expand Up @@ -283,7 +283,7 @@ func (a *API) PKCE(ctx context.Context, w http.ResponseWriter, r *http.Request)
metering.RecordLogin(metering.LoginTypePKCE, user.ID, &metering.LoginData{
Provider: flowState.ProviderType,
})
return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}

func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user *models.User, sessionId *uuid.UUID, authenticationMethod models.AuthenticationMethod) (string, int64, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/api/token_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,5 @@ func (a *API) IdTokenGrant(ctx context.Context, w http.ResponseWriter, r *http.R
Provider: providerType,
})

return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}
2 changes: 1 addition & 1 deletion internal/api/token_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func (a *API) RefreshTokenGrant(ctx context.Context, w http.ResponseWriter, r *h
return err
}

return sendJSON(w, http.StatusOK, tokenResponse)
return sendTokenJSON(w, http.StatusOK, tokenResponse)
}
2 changes: 1 addition & 1 deletion internal/api/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (a *API) verifyPost(w http.ResponseWriter, r *http.Request, params *VerifyP
Provider: provider,
})

return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}

func (a *API) signupVerify(r *http.Request, ctx context.Context, conn *storage.Connection, user *models.User) (*models.User, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/api/web3.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (a *API) web3GrantSolana(ctx context.Context, w http.ResponseWriter, r *htt
},
})

return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}

func (a *API) web3GrantEthereum(ctx context.Context, w http.ResponseWriter, r *http.Request, params *Web3GrantParams) error {
Expand Down Expand Up @@ -335,5 +335,5 @@ func (a *API) web3GrantEthereum(ctx context.Context, w http.ResponseWriter, r *h
return err
}
}
return sendJSON(w, http.StatusOK, token)
return sendTokenJSON(w, http.StatusOK, token)
}