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

Commit

Permalink
feat: unmashall user data to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Dec 5, 2019
1 parent cf1e39f commit 828c65c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const (
port = "8000"
)

// GoogleAPIUserInfo the user data returned from Google API Services
type GoogleAPIUserInfo struct {
Email string `json:"email"`
Hd string `json:"hd"`
ID string `json:"id"`
Picture string `json:"picture"`
VerifiedEmail bool `json:"verified_email"`
}
func generateOauthStateTracker() string {
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, 10)
Expand All @@ -46,7 +54,9 @@ func getUserDataFromGoogle(googleOauthConfig *oauth2.Config, code string) ([]byt
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("failed read response: %s", err.Error())
var userInfo *GoogleAPIUserInfo
if err = json.Unmarshal(contents, &userInfo); err != nil {
return GetUserDataFromGoogleResponse{}, fmt.Errorf("Error reading data from google: %w", err)
}
return contents, nil
}
Expand Down

0 comments on commit 828c65c

Please sign in to comment.