-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathsdk_credentials.go
More file actions
50 lines (41 loc) · 1.18 KB
/
sdk_credentials.go
File metadata and controls
50 lines (41 loc) · 1.18 KB
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
package configuration
import "github.com/checkout/checkout-sdk-go/v2/errors"
type PlatformType string
const (
Previous PlatformType = "PREVIOUS"
Default PlatformType = "DEFAULT"
DefaultOAuth PlatformType = "DEFAULT_OAUTH"
Custom PlatformType = "CUSTOM"
)
type AuthorizationType string
const (
PublicKey AuthorizationType = "PUBLIC_KEY"
SecretKey AuthorizationType = "SECRET_KEY"
PublicKeyOrOauth AuthorizationType = "PUBLIC_KEY_OR_OAUTH"
SecretKeyOrOauth AuthorizationType = "SECRET_KEY_OR_OAUTH"
OAuth AuthorizationType = "OAUTH"
CustomAuth AuthorizationType = "CUSTOM"
)
type (
SdkCredentials interface {
GetAuthorization(authorizationType AuthorizationType) (*SdkAuthorization, error)
}
SdkAuthorization struct {
PlatformType PlatformType
Credential string
}
)
func (s *SdkAuthorization) GetAuthorizationHeader() (string, error) {
switch s.PlatformType {
case Previous, Custom:
return s.Credential, nil
case Default, DefaultOAuth:
return "Bearer " + s.Credential, nil
default:
return "", errors.CheckoutAuthorizationError("Invalid platform type")
}
}
type StaticKeys struct {
SecretKey string
PublicKey string
}