Skip to content

Commit 8a49414

Browse files
authored
Merge pull request #127 from dsumer/master
Fix: Retrieve Twitter and GitHub usernames via OAuth
2 parents adff471 + 9eebf9c commit 8a49414

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

api/provider/github.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type githubProvider struct {
2222
}
2323

2424
type githubUser struct {
25+
UserName string `json:"login"`
2526
Email string `json:"email"`
2627
Name string `json:"name"`
2728
AvatarURL string `json:"avatar_url"`
@@ -75,6 +76,7 @@ func (g githubProvider) GetUserData(ctx context.Context, tok *oauth2.Token) (*Us
7576

7677
data := &UserProvidedData{
7778
Metadata: map[string]string{
79+
userNameKey: u.UserName,
7880
nameKey: u.Name,
7981
avatarURLKey: u.AvatarURL,
8082
},

api/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
const (
11+
userNameKey = "user_name"
1112
avatarURLKey = "avatar_url"
1213
nameKey = "full_name"
1314
aliasKey = "slug"

api/provider/twitter.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
const (
1818
requestURL = "https://api.twitter.com/oauth/request_token"
19-
authorizeURL = "https://api.twitter.com/oauth/authorize"
19+
authenticateURL = "https://api.twitter.com/oauth/authenticate"
2020
tokenURL = "https://api.twitter.com/oauth/access_token"
2121
endpointProfile = "https://api.twitter.com/1.1/account/verify_credentials.json"
2222
)
@@ -32,6 +32,7 @@ type TwitterProvider struct {
3232
}
3333

3434
type twitterUser struct {
35+
UserName string `json:"screen_name"`
3536
Name string `json:"name"`
3637
AvatarURL string `json:"profile_image_url"`
3738
Email string `json:"email"`
@@ -78,6 +79,7 @@ func (t TwitterProvider) FetchUserData(ctx context.Context, tok *oauth.AccessTok
7879

7980
data := &UserProvidedData{
8081
Metadata: map[string]string{
82+
userNameKey: u.UserName,
8183
nameKey: u.Name,
8284
avatarURLKey: u.AvatarURL,
8385
},
@@ -107,7 +109,7 @@ func newConsumer(provider *TwitterProvider) *oauth.Consumer {
107109
provider.Secret,
108110
oauth.ServiceProvider{
109111
RequestTokenUrl: requestURL,
110-
AuthorizeTokenUrl: authorizeURL,
112+
AuthorizeTokenUrl: authenticateURL,
111113
AccessTokenUrl: tokenURL,
112114
})
113115
return c

0 commit comments

Comments
 (0)