From: Florian Forster Date: Tue, 30 Jan 2018 08:44:35 +0000 (+0100) Subject: Implement Fitbit and Google Fit disconnect handlers. X-Git-Url: https://git.octo.it/?p=kraftakt.git;a=commitdiff_plain;h=85a81c5e601b14166dfa0bd9633ba609b1b3ac3d Implement Fitbit and Google Fit disconnect handlers. These allow users to actively delete their tokens. This change also includes: * Rename the "setup" endpoints to "connect". * Enforce authentication for the "connect" endpoints, even though they don't really require it. It's better to handle authentication before redirecting users to the OAuth screen. --- diff --git a/kraftakt.go b/kraftakt.go index b49f787..1f3ac98 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -22,11 +22,13 @@ import ( var delayedHandleNotifications = delay.Func("handleNotifications", handleNotifications) func init() { - http.HandleFunc("/fitbit/setup", fitbitSetupHandler) + http.Handle("/fitbit/connect", AuthenticatedHandler(fitbitConnectHandler)) http.Handle("/fitbit/grant", AuthenticatedHandler(fitbitGrantHandler)) http.Handle("/fitbit/notify", ContextHandler(fitbitNotifyHandler)) - http.HandleFunc("/google/setup", googleSetupHandler) + http.Handle("/fitbit/disconnect", AuthenticatedHandler(fitbitDisconnectHandler)) + http.Handle("/google/connect", AuthenticatedHandler(googleConnectHandler)) http.Handle("/google/grant", AuthenticatedHandler(googleGrantHandler)) + http.Handle("/google/disconnect", AuthenticatedHandler(googleDisconnectHandler)) http.Handle("/", AuthenticatedHandler(indexHandler)) } @@ -123,8 +125,9 @@ func indexHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u return nil } -func fitbitSetupHandler(w http.ResponseWriter, r *http.Request) { +func fitbitConnectHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ *app.User) error { http.Redirect(w, r, fitbit.AuthURL(), http.StatusTemporaryRedirect) + return nil } func fitbitGrantHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u *app.User) error { diff --git a/templates/loggedin.html b/templates/loggedin.html index 24dd19a..6061de7 100644 --- a/templates/loggedin.html +++ b/templates/loggedin.html @@ -18,7 +18,7 @@ Disconnected - Connect + Connect {{end}} @@ -39,7 +39,7 @@ Disconnected - Connect + Connect {{endif}}