update recipe modal
This commit is contained in:
parent
ac45ca47d5
commit
2328da0ce8
11 changed files with 238 additions and 40 deletions
47
server/helpers/googleconfig.go
Normal file
47
server/helpers/googleconfig.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
||||
func GetClientSecret(path string) (*oauth2.Config, error) {
|
||||
b, err := os.ReadFile("client_secret.json")
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read client secret file: %v", err)
|
||||
}
|
||||
|
||||
clientSecret, err := google.ConfigFromJSON(b, "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/spreadsheets.readonly")
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse client secret file to config: %v", err)
|
||||
}
|
||||
|
||||
return clientSecret, nil
|
||||
}
|
||||
|
||||
func GetToken(path string) (*oauth2.Token, error) {
|
||||
file, err := os.Open(path)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read token file: %v", err)
|
||||
}
|
||||
|
||||
token := map[string]string{}
|
||||
|
||||
err = json.NewDecoder(file).Decode(&token)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse token file to token: %v", err)
|
||||
}
|
||||
|
||||
return &oauth2.Token{
|
||||
AccessToken: token["access_token"],
|
||||
RefreshToken: token["refresh_token"],
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue