Sync shared snapshot from 7b5a4e6
This commit is contained in:
1 parent
695ff742d6
commit
68f6dd5a87
47 files changed
+587
-726
No files matched your search
@@ -131,6 +131,7 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
sharedauth "repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
||||
authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
|
||||
"repos.gfranz.ch/Gabriel20xx/shared/backend/authproxy"
|
||||
)
|
||||
|
||||
// User is this service's own /auth/... response shape - UNCHANGED from
|
||||
@@ -222,25 +223,14 @@ func UserFromContext(ctx context.Context) *User {
|
||||
// sessionToken reads the AuthGuard session cookie off the incoming request.
|
||||
// See the top-of-file doc comment's "Session cookie / token model" section.
|
||||
func (s *Service) sessionToken(r *http.Request) string {
|
||||
cookie, err := r.Cookie(authclient.DefaultCookieName)
|
||||
if err != nil || cookie.Value == "" {
|
||||
return ""
|
||||
}
|
||||
return cookie.Value
|
||||
return authproxy.SessionToken(r)
|
||||
}
|
||||
|
||||
// clearSessionCookies clears both the AuthGuard cookie (as a fallback -
|
||||
// normally AuthGuard's own Set-Cookie, forwarded via authclient.ForwardCookies,
|
||||
// already does this) and the pre-migration cookie name.
|
||||
func (s *Service) clearSessionCookies(w http.ResponseWriter) {
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: authclient.DefaultCookieName, Value: "", Path: "/", HttpOnly: true,
|
||||
Secure: s.secureCookies, SameSite: http.SameSiteLaxMode, MaxAge: -1,
|
||||
})
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: s.cookieName, Value: "", Path: "/", HttpOnly: true,
|
||||
Secure: s.secureCookies, SameSite: http.SameSiteLaxMode, MaxAge: -1,
|
||||
})
|
||||
authproxy.ClearSessionCookies(w, s.cookieName, s.secureCookies)
|
||||
}
|
||||
|
||||
// toUser translates AuthGuard's PublicUser into this service's own User
|
||||
@@ -1144,9 +1134,8 @@ func (s *Service) SetPassword(ctx context.Context, id int64, password string) er
|
||||
// non-APIError (a transport failure actually reaching AuthGuard) falls back
|
||||
// to a generic 500 with fallbackMessage.
|
||||
func writeAuthGuardError(w http.ResponseWriter, err error, fallbackMessage string) {
|
||||
var apiErr *authclient.APIError
|
||||
if errors.As(err, &apiErr) {
|
||||
writeError(w, apiErr.StatusCode, apiErr.Message)
|
||||
if statusCode, message, ok := authproxy.APIErrorResponse(err); ok {
|
||||
writeError(w, statusCode, message)
|
||||
return
|
||||
}
|
||||
writeError(w, http.StatusInternalServerError, fallbackMessage)
|
||||
|
||||
Reference in new issue
Block a user