-
Notifications
You must be signed in to change notification settings - Fork 38
/
auth_flow_test.go
37 lines (29 loc) · 1.12 KB
/
auth_flow_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package examples
import (
"fmt"
"testing"
"github.com/rwestlund/quickbooks-go"
"github.com/stretchr/testify/require"
)
func TestAuthorizationFlow(t *testing.T) {
clientId := "<your-client-id>"
clientSecret := "<your-client-secret>"
realmId := "<realm-id>"
qbClient, err := quickbooks.NewClient(clientId, clientSecret, realmId, false, "", nil)
require.NoError(t, err)
// To do first when you receive the authorization code from quickbooks callback
authorizationCode := "<received-from-callback>"
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
// When the token expire, you can use the following function
bearerToken, err = qbClient.RefreshToken(bearerToken.RefreshToken)
require.NoError(t, err)
// Make a request!
info, err := qbClient.FindCompanyInfo()
require.NoError(t, err)
fmt.Println(info)
// Revoke the token, this should be done only if a user unsubscribe from your app
require.NoError(t, qbClient.RevokeToken(bearerToken.RefreshToken))
}