forked from jinmatt/go-quickbooks.v2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoauth.go
53 lines (45 loc) · 1.14 KB
/
oauth.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package quickbooks
import (
"golang.org/x/oauth2"
)
const (
AccountingScope = "com.intuit.quickbooks.accounting"
PaymentsScope = "com.intuit.quickbooks.payment"
PayrollScope = "com.intuit.quickbooks.payroll"
PayrollTimetrackingScope = "com.intuit.quickbooks.payroll.timetracking"
PayrollBenefitsScope = "com.intuit.quickbooks.payroll.benefits"
)
type Oauth2Config struct {
oauth2.Config
}
func NewOauth2ConfigProduction() (*Oauth2Config, error) {
return NewOauth2Config(false)
}
func NewOauth2ConfigSandbox() (*Oauth2Config, error) {
return NewOauth2Config(true)
}
func NewOauth2Config(isSandbox bool) (*Oauth2Config, error) {
discovery, err := NewDiscovery(isSandbox)
if err != nil {
return nil, err
}
config := &Oauth2Config{
Config: oauth2.Config{
RedirectURL: "",
ClientID: "",
ClientSecret: "",
Scopes: []string{
AccountingScope,
PaymentsScope,
PayrollScope,
PayrollTimetrackingScope,
PayrollBenefitsScope,
},
Endpoint: oauth2.Endpoint{
AuthURL: discovery.AuthorizationEndpoint,
TokenURL: discovery.TokenEndpoint,
},
},
}
return config, nil
}