Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
feat: use viper config instead of env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Dec 9, 2019
1 parent aa4c7c7 commit 08cf63d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func initConfig() {
viper.AddConfigPath(home)
viper.SetConfigFile(".kamanda/refresh_token.json")
}
viper.Set("GOOGLE_OAUTH_CLIENT_ID", os.Getenv("GOOGLE_OAUTH_CLIENT_ID"))
viper.Set("GOOGLE_OAUTH_CLIENT_ID", os.Getenv("GOOGLE_OAUTH_CLIENT_ID"))
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
Expand Down
13 changes: 7 additions & 6 deletions oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"github.com/go-chi/chi"
"github.com/pkg/browser"
"github.com/spf13/viper"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"io/ioutil"
Expand Down Expand Up @@ -93,8 +94,8 @@ func getGoogleOAuthConfig(port string) *oauth2.Config {
}
return &oauth2.Config{
RedirectURL: redirectURL,
ClientID: os.Getenv("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: os.Getenv("GOOGLE_OAUTH_CLIENT_SECRET"),
ClientID: viper.GetString("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: viper.GetString("GOOGLE_OAUTH_CLIENT_SECRET"),
Scopes: googleOAuthScopes(),
Endpoint: google.Endpoint,
}
Expand Down Expand Up @@ -128,8 +129,8 @@ func LoginWithLocalhost() {
return
}
refreshTokenObject := RefreshToken{
ClientID: os.Getenv("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: os.Getenv("GOOGLE_OAUTH_CLIENT_SECRET"),
ClientID: viper.GetString("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: viper.GetString("GOOGLE_OAUTH_CLIENT_SECRET"),
RefreshToken: data.RefreshToken,
Type: "authorized_user",
}
Expand Down Expand Up @@ -175,8 +176,8 @@ func LoginWithoutLocalhost() error {
return fmt.Errorf("An error occurred while exchanging code with token: %w", err)
}
refreshTokenObject := RefreshToken{
ClientID: os.Getenv("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: os.Getenv("GOOGLE_OAUTH_CLIENT_SECRET"),
ClientID: viper.GetString("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: viper.GetString("GOOGLE_OAUTH_CLIENT_SECRET"),
RefreshToken: data.RefreshToken,
Type: "authorized_user",
}
Expand Down

0 comments on commit 08cf63d

Please sign in to comment.