forked from rwestlund/quickbooks-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth_flow_test.go
35 lines (28 loc) · 1.02 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
package examples
import (
"fmt"
"github.com/rwestlund/quickbooks-go"
"github.com/stretchr/testify/require"
"testing"
)
func TestAuthorizationFlow(t *testing.T) {
clientId := "<your-client-id>"
clientSecret := "<your-client-secret>"
realmId := "<realm-id>"
qbClient, err := quickbooks.NewQuickbooksClient(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>"
bearerToken, err := qbClient.RetrieveBearerToken(authorizationCode)
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.FetchCompanyInfo()
require.NoError(t, err)
fmt.Println(info)
// Revoke the token, this should be done only if a user unsubscribe from your app
qbClient.RevokeToken(bearerToken.RefreshToken)
}