Skip to content

Commit

Permalink
Merge pull request ethereum#16165 from karalabe/faucet-twitter-api
Browse files Browse the repository at this point in the history
cmd/faucet: resolve twitter user from final redirect
  • Loading branch information
karalabe authored Feb 22, 2018
2 parents 1e457b6 + 72c4c50 commit 5be1085
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,6 @@ func authTwitter(url string) (string, string, common.Address, error) {
if len(parts) < 4 || parts[len(parts)-2] != "status" {
return "", "", common.Address{}, errors.New("Invalid Twitter status URL")
}
username := parts[len(parts)-3]

// Twitter's API isn't really friendly with direct links. Still, we don't
// want to do ask read permissions from users, so just load the public posts and
// scrape it for the Ethereum address and profile URL.
Expand All @@ -697,6 +695,13 @@ func authTwitter(url string) (string, string, common.Address, error) {
}
defer res.Body.Close()

// Resolve the username from the final redirect, no intermediate junk
parts = strings.Split(res.Request.URL.String(), "/")
if len(parts) < 4 || parts[len(parts)-2] != "status" {
return "", "", common.Address{}, errors.New("Invalid Twitter status URL")
}
username := parts[len(parts)-3]

body, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", "", common.Address{}, err
Expand Down

0 comments on commit 5be1085

Please sign in to comment.