Skip to content

Commit 72c4c50

Browse files
committed
cmd/faucet: resolve twitter user from final redirect
1 parent 1e457b6 commit 72c4c50

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎cmd/faucet/faucet.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,6 @@ func authTwitter(url string) (string, string, common.Address, error) {
686686
if len(parts) < 4 || parts[len(parts)-2] != "status" {
687687
return "", "", common.Address{}, errors.New("Invalid Twitter status URL")
688688
}
689-
username := parts[len(parts)-3]
690-
691689
// Twitter's API isn't really friendly with direct links. Still, we don't
692690
// want to do ask read permissions from users, so just load the public posts and
693691
// scrape it for the Ethereum address and profile URL.
@@ -697,6 +695,13 @@ func authTwitter(url string) (string, string, common.Address, error) {
697695
}
698696
defer res.Body.Close()
699697

698+
// Resolve the username from the final redirect, no intermediate junk
699+
parts = strings.Split(res.Request.URL.String(), "/")
700+
if len(parts) < 4 || parts[len(parts)-2] != "status" {
701+
return "", "", common.Address{}, errors.New("Invalid Twitter status URL")
702+
}
703+
username := parts[len(parts)-3]
704+
700705
body, err := ioutil.ReadAll(res.Body)
701706
if err != nil {
702707
return "", "", common.Address{}, err

0 commit comments

Comments
 (0)