Last active
July 5, 2017 23:30
-
-
Save odeke-em/87870b5d5cc63f12ed2c718e2d0a1142 to your computer and use it in GitHub Desktop.
Uber OAuth2.0 credentials retrieval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"log" | |
"os" | |
"path/filepath" | |
"github.com/orijtech/uber/oauth2" | |
) | |
func main() { | |
// Make log not print out time info in its prefix. | |
log.SetFlags(0) | |
uberCredsDirPath := os.ExpandEnv("$HOME/.uber") | |
if err := os.MkdirAll(uberCredsDirPath, 0777); err != nil { | |
log.Fatal(err) | |
} | |
scopes := []string{ | |
oauth2.ScopeProfile, oauth2.ScopeRequest, | |
oauth2.ScopeHistory, oauth2.ScopePlaces, | |
oauth2.ScopeRequestReceipt, | |
} | |
token, err := oauth2.AuthorizeByEnvApp(scopes...) | |
if err != nil { | |
log.Fatal(err) | |
} | |
blob, err := json.Marshal(token) | |
if err != nil { | |
log.Fatal(err) | |
} | |
credsPath := filepath.Join(uberCredsDirPath, "credentials.json") | |
f, err := os.Create(credsPath) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer f.Close() | |
f.Write(blob) | |
log.Printf("Successfully saved your OAuth2.0 token to %q", credsPath) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment