Connect handlers: don't call {fitbit,gfit}.NewClient().
[kraftakt.git] / gfit / gfit.go
index 610ee5c..ec88b19 100644 (file)
@@ -19,8 +19,7 @@ import (
 )
 
 const (
-       csrfToken = "@CSRFTOKEN@"
-       userID    = "me"
+       userID = "me"
 
        dataTypeNameCalories        = "com.google.calories.expended"
        dataTypeNameDistance        = "com.google.distance.delta"
@@ -43,6 +42,10 @@ func oauthConfig() *oauth2.Config {
        }
 }
 
+func AuthURL(ctx context.Context, u *app.User) string {
+       return oauthConfig().AuthCodeURL(u.Sign("Google"), oauth2.AccessTypeOffline)
+}
+
 func Application(ctx context.Context) *fitness.Application {
        return &fitness.Application{
                Name:       "Kraftakt",
@@ -51,12 +54,8 @@ func Application(ctx context.Context) *fitness.Application {
        }
 }
 
-func AuthURL() string {
-       return oauthConfig().AuthCodeURL(csrfToken, oauth2.AccessTypeOffline)
-}
-
 func ParseToken(ctx context.Context, r *http.Request, u *app.User) error {
-       if state := r.FormValue("state"); state != csrfToken {
+       if state := r.FormValue("state"); state != u.Sign("Google") {
                return fmt.Errorf("invalid state parameter: %q", state)
        }