Skip to content

Commit

Permalink
Merge pull request #16 from in4it/fix-RetrieveBearerToken
Browse files Browse the repository at this point in the history
add redirectURI parameter to RetrieveBearerToken
  • Loading branch information
Ryan Westlund authored Oct 15, 2021
2 parents 56540cd + d543dc4 commit a669272
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ qbClient, _ := quickbooks.NewQuickbooksClient(clientId, clientSecret, realmId, f

// To do first when you receive the authorization code from quickbooks callback
authorizationCode := "<received-from-callback>"
bearerToken, _ := qbClient.RetrieveBearerToken(authorizationCode)
redirectURI := "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl"
bearerToken, _ := qbClient.RetrieveBearerToken(authorizationCode, redirectURI)
// Save the bearer token inside a db

// When the token expire, you can use the following function
Expand Down
3 changes: 2 additions & 1 deletion examples/auth_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func TestAuthorizationFlow(t *testing.T) {

// To do first when you receive the authorization code from quickbooks callback
authorizationCode := "<received-from-callback>"
bearerToken, err := qbClient.RetrieveBearerToken(authorizationCode)
redirectURI := "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl"
bearerToken, err := qbClient.RetrieveBearerToken(authorizationCode, redirectURI)
require.NoError(t, err)
// Save the bearer token inside a db

Expand Down
4 changes: 2 additions & 2 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ type BearerToken struct {
// Method to retrieve access token (bearer token)
// This method can only be called once
//
func (c *Client) RetrieveBearerToken(authorizationCode string) (*BearerToken, error) {
func (c *Client) RetrieveBearerToken(authorizationCode, redirectURI string) (*BearerToken, error) {
client := &http.Client{}
data := url.Values{}
//set parameters
data.Set("grant_type", "authorization_code")
data.Add("code", authorizationCode)
data.Add("redirect_uri", "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl")
data.Add("redirect_uri", redirectURI)

request, err := http.NewRequest("POST", string(c.discoveryAPI.TokenEndpoint), bytes.NewBufferString(data.Encode()))
if err != nil {
Expand Down

0 comments on commit a669272

Please sign in to comment.