"google.golang.org/appengine/log"
)
-var oauth2Config = &oauth2.Config{
- ClientID: app.Config.FitbitClientID,
- ClientSecret: app.Config.FitbitClientSecret,
- Endpoint: oauth2fitbit.Endpoint,
- RedirectURL: "https://kraftakt.octo.it/fitbit/grant",
- Scopes: []string{
- "activity",
- "heartrate",
- "profile",
- "sleep",
- },
+
+func oauthConfig() *oauth2.Config {
+ return &oauth2.Config{
+ ClientID: app.Config.FitbitClientID,
+ ClientSecret: app.Config.FitbitClientSecret,
+ Endpoint: oauth2fitbit.Endpoint,
+ RedirectURL: "https://kraftakt.octo.it/fitbit/grant",
+ Scopes: []string{
+ "activity",
+ "heartrate",
+ "profile",
+ "sleep",
+ },
+ }
}
const csrfToken = "@CSRFTOKEN@"
func AuthURL() string {
- return oauth2Config.AuthCodeURL(csrfToken, oauth2.AccessTypeOffline)
+ return oauthConfig().AuthCodeURL(csrfToken, oauth2.AccessTypeOffline)
}
func ParseToken(ctx context.Context, r *http.Request, u *app.User) error {
return fmt.Errorf("invalid state parameter: %q", state)
}
- tok, err := oauth2Config.Exchange(ctx, r.FormValue("code"))
+ tok, err := oauthConfig().Exchange(ctx, r.FormValue("code"))
if err != nil {
return err
}
return false
}
- mac := hmac.New(sha1.New, []byte(oauth2Config.ClientSecret+"&"))
+ mac := hmac.New(sha1.New, []byte(oauthConfig().ClientSecret+"&"))
mac.Write(payload)
signatureWant := mac.Sum(nil)
fitbitUserID = "-"
}
- c, err := u.OAuthClient(ctx, "Fitbit", oauth2Config)
+ c, err := u.OAuthClient(ctx, "Fitbit", oauthConfig())
if err != nil {
return nil, err
}
dataTypeNameActivitySegment = "com.google.activity.segment"
)
-var oauthConfig = &oauth2.Config{
- ClientID: app.Config.GoogleClientID,
- ClientSecret: app.Config.GoogleClientSecret,
- Endpoint: oauth2google.Endpoint,
- RedirectURL: "https://kraftakt.octo.it/google/grant",
- Scopes: []string{
- fitness.FitnessActivityWriteScope,
- fitness.FitnessBodyWriteScope,
- fitness.FitnessLocationWriteScope,
- },
+func oauthConfig() *oauth2.Config {
+ return &oauth2.Config{
+ ClientID: app.Config.GoogleClientID,
+ ClientSecret: app.Config.GoogleClientSecret,
+ Endpoint: oauth2google.Endpoint,
+ RedirectURL: "https://kraftakt.octo.it/google/grant",
+ Scopes: []string{
+ fitness.FitnessActivityWriteScope,
+ fitness.FitnessBodyWriteScope,
+ fitness.FitnessLocationWriteScope,
+ },
+ }
}
func Application(ctx context.Context) *fitness.Application {
}
func AuthURL() string {
- return oauthConfig.AuthCodeURL(csrfToken, oauth2.AccessTypeOffline)
+ return oauthConfig().AuthCodeURL(csrfToken, oauth2.AccessTypeOffline)
}
func ParseToken(ctx context.Context, r *http.Request, u *app.User) error {
return fmt.Errorf("invalid state parameter: %q", state)
}
- tok, err := oauthConfig.Exchange(ctx, r.FormValue("code"))
+ tok, err := oauthConfig().Exchange(ctx, r.FormValue("code"))
if err != nil {
return err
}
}
func NewClient(ctx context.Context, u *app.User) (*Client, error) {
- c, err := u.OAuthClient(ctx, "Google", oauthConfig)
+ c, err := u.OAuthClient(ctx, "Google", oauthConfig())
if err != nil {
return nil, err
}