Skip to content

Commit

Permalink
feat: Support authorization with provided access token and secret
Browse files Browse the repository at this point in the history
  • Loading branch information
mogita committed Aug 7, 2019
1 parent 6125afe commit a37b4d9
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions fanfou/fanfou.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (c *Client) GetRequestTokenAndURL(callbackURL string) (*RequestToken, strin
}

// AuthorizeClient completes the OAuth authorization to the client
// so it can communicate with Fanfou API
// so it can make requests to protected contents
//
// If you use "oob" mode, you also need to provide the verificationCode
func (c *Client) AuthorizeClient(requestToken *RequestToken, verificationCode string) (*AccessToken, error) {
Expand Down Expand Up @@ -185,7 +185,7 @@ func (c *Client) AuthorizeClient(requestToken *RequestToken, verificationCode st
}

// AuthorizeClientWithXAuth completes the OAuth authorization to the client
// with XAuth so it can communicate with Fanfou API
// with XAuth so it can make requests to protected contents
//
// This method is a simplified OAuth process, taking username and password
// to authorize the client, without the need to redirect to the web UI
Expand All @@ -210,6 +210,26 @@ func (c *Client) AuthorizeClientWithXAuth(username, password string) error {
return nil
}

// AuthorizeClientWithAccessTokens completes the OAuth authorization to the client
// with provided access token and secret so it can make requests to protected
// contents
func (c *Client) AuthorizeClientWithAccessTokens(accessToken, accessTokenSecret string, additionalData map[string]string) error {
tokens := oauth.AccessToken{
Token: accessToken,
Secret: accessTokenSecret,
AdditionalData: additionalData,
}

var err error
c.client, err = c.oauthConsumer.MakeHttpClient(&tokens)

if err != nil {
return err
}

return nil
}

// NewRequest creates an API request. A relative URL can be provided in uri,
// in which case it is resolved relative to the BaseURL of the Client.
//
Expand Down

1 comment on commit a37b4d9

@mogita
Copy link
Owner Author

@mogita mogita commented on a37b4d9 Aug 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.