u
Anirudh Oppiliappan x@icyphox.sh
Sun, 11 Feb 2024 10:13:40 +0200
1 files changed,
4 insertions(+),
2 deletions(-)
jump to
M
web.go
→
web.go
@@ -2993,7 +2993,7 @@ mastopost.HandleFunc("/oauth/authorize", oauthorize)
mastopost.HandleFunc("/oauth/token", oauthtoken) mastoget.HandleFunc("/api/v1/instance", instance) mastopost.HandleFunc("/api/v1/apps", apiapps) - mastoget.HandleFunc("/api/v1/apps/verify_credentials", injectapp(verifycreds)) + mastoget.HandleFunc("/api/v1/apps/verify_credentials", checktoken(verifycreds)) loggedmux := handlers.LoggingHandler(os.Stdout, mux) err = http.Serve(listener, loggedmux)@@ -3004,7 +3004,7 @@ }
// Verifies that accesstoken is valid and injects the associated // MastoApp in the request context -func injectapp(h http.HandlerFunc) http.HandlerFunc { +func checktoken(h http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { authHeader := r.Header.Get("Authorization") split := strings.Split(authHeader, "Bearer")@@ -3021,6 +3021,8 @@ elog.Println("masto: invalid access token")
w.WriteHeader(http.StatusUnauthorized) return } + + fmt.Printf("logged in! app: %s\n", app.Name) ctx := context.WithValue(r.Context(), "app", app) r = r.WithContext(ctx)