Skip to content

Instantly share code, notes, and snippets.

@odeke-em
Last active July 5, 2017 23:30
Show Gist options
  • Save odeke-em/87870b5d5cc63f12ed2c718e2d0a1142 to your computer and use it in GitHub Desktop.
Save odeke-em/87870b5d5cc63f12ed2c718e2d0a1142 to your computer and use it in GitHub Desktop.
Uber OAuth2.0 credentials retrieval
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