stacktic
/
dropbox
Archived
1
0
Fork 0

Support setting the redirect url and authorizing via a provided code

This is useful when authorizing users on a website.
This commit is contained in:
Brian Smith 2015-02-11 19:31:37 -08:00 committed by Arnaud Ysmal
parent ba894b878f
commit 285abe6e58
1 changed files with 12 additions and 3 deletions

View File

@ -235,6 +235,10 @@ func (db *Dropbox) AccessToken() string {
return db.token.AccessToken
}
func (db *Dropbox) SetRedirectUrl(url string) {
db.config.RedirectURL = url
}
func (db *Dropbox) client() *http.Client {
return db.config.Client(db.ctx, db.token)
}
@ -242,15 +246,20 @@ func (db *Dropbox) client() *http.Client {
// Auth displays the URL to authorize this application to connect to your account.
func (db *Dropbox) Auth() error {
var code string
var t *oauth2.Token
var err error
fmt.Printf("Please visit:\n%s\nEnter the code: ",
db.config.AuthCodeURL(""))
fmt.Scanln(&code)
if t, err = db.config.Exchange(oauth2.NoContext, code); err != nil {
return db.AuthCode(code)
}
// Authorizes the given code
func (db *Dropbox) AuthCode(code string) error {
t, err := db.config.Exchange(oauth2.NoContext, code)
if err != nil {
return err
}
db.token = t
db.token.TokenType = "Bearer"
return nil