Skip to content

Commit

Permalink
Edit: token struct
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXu committed Apr 30, 2016
1 parent a231015 commit 37b9351
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions auth/socialFacebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ func ConfigFacebook(r *gin.RouterGroup, clientId string, secretKey string, redir

}

func Routes(oauth *oauth2.Config, r *gin.RouterGroup) {
passportOauth = oauth

r.GET("/login", func(c *gin.Context) {
Login(oauth, c)
})
}

func LoginWithFacebookToken(c *gin.Context) {
var fbtoken FacebookToken
Expand Down Expand Up @@ -177,30 +170,31 @@ func getProfile(c *gin.Context) {
func getFBProfile(token string) (*FacebookProfile, error){
var userInformation FacebookProfile

t := token
t := &oauth2.Token{AccessToken:token}
config := passportOauth

if t == nil {
return userInformation, errors.New("token missing")
return &userInformation, errors.New("token missing")
}

client := config.Client(oauth2.NoContext, t)

resp, err := client.Get(FacebookProfileUrl)
if err != nil {
return userInformation, err
return &userInformation, err
}

defer resp.Body.Close()
contents, readErr := ioutil.ReadAll(resp.Body)

if readErr != nil {
return userInformation, readErr
return &userInformation, readErr
}

err = json.Unmarshal(contents, &userInformation)
if err != nil {
return userInformation, err
return &userInformation, err
}

return userInformation, nil
return &userInformation, nil
}

0 comments on commit 37b9351

Please sign in to comment.