Skip to content

Commit

Permalink
GetAccessToken: detect invalid request token
Browse files Browse the repository at this point in the history
  • Loading branch information
hoisie committed Jan 26, 2011
1 parent f20bc5c commit a3dce44
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ func (rt *RequestToken) AuthorizeUrl() string {
return fmt.Sprintf("%s?oauth_token=%s", authorizeUrl.Raw, rt.OAuthToken)
}

func (o *OAuthClient) GetAccessToken(requestToken *RequestToken, OAuthVerifier string) *AccessToken {
func (o *OAuthClient) GetAccessToken(requestToken *RequestToken, OAuthVerifier string) (*AccessToken, os.Error) {
if requestToken == nil || requestToken.OAuthToken == "" || requestToken.OAuthTokenSecret == "" {
return nil, os.NewError("Invalid Request token")
}

nonce := getNonce(40)
params := map[string]string{
"oauth_nonce": nonce,
Expand Down Expand Up @@ -189,7 +193,7 @@ func (o *OAuthClient) GetAccessToken(requestToken *RequestToken, OAuthVerifier s
resp, err := request.AsString()
tokens, err := http.ParseQuery(resp)
if err != nil {
println(err.String())
return nil, err
}

at := AccessToken{
Expand All @@ -198,7 +202,7 @@ func (o *OAuthClient) GetAccessToken(requestToken *RequestToken, OAuthVerifier s
UserId: tokens["user_id"][0],
ScreenName: tokens["screen_name"][0],
}
return &at
return &at, nil

}

Expand Down

0 comments on commit a3dce44

Please sign in to comment.