-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtypes.go
More file actions
74 lines (61 loc) · 2.47 KB
/
Copy pathtypes.go
File metadata and controls
74 lines (61 loc) · 2.47 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package v2
//go:generate mockgen -destination=../../../mocks/services/oauthV2/mock_oauthV2.go -package=mock_oauthV2 github.com/rudderlabs/rudder-server/services/oauth/v2 AuthIdentityProvider
import (
"encoding/json"
"time"
"github.com/rudderlabs/rudder-server/services/controlplane/identity"
"github.com/rudderlabs/rudder-server/utils/misc"
)
// OAuthToken is the access token returned by the oauth server
type OAuthToken struct {
ExpirationDate string `json:"expirationDate"`
Secret json.RawMessage `json:"secret"`
}
func (at *OAuthToken) IsEmpty() bool {
return at.Secret == nil || string(at.Secret) == `{}` || string(at.Secret) == "\"\"" || string(at.Secret) == "null"
}
// Expires returns true if the token expiration date is not empty, it is a valid RFC3339 timestamp and will expire after the given duration
func (at *OAuthToken) Expires(after time.Duration) (bool, error) {
if at.ExpirationDate == "" {
return false, nil
}
expirationDate, err := time.Parse(misc.RFC3339Milli, at.ExpirationDate)
if err != nil {
return false, err
}
return expirationDate.Before(time.Now().Add(after)), nil
}
type AuthIdentityProvider interface {
Identity() identity.Identifier
}
type OAuthResponse struct {
OauthToken OAuthToken
Err string
ErrorMessage string
}
type OAuthTokenParams struct {
AccountID string
WorkspaceID string
DestType string
DestinationID string
}
type OauthTokenRequestBody struct {
HasExpired bool `json:"hasExpired"`
ExpiredSecret json.RawMessage `json:"expiredSecret"`
}
type StatusRequestParams struct {
AccountID string
WorkspaceID string
DestType string
DestinationID string
Status string
}
type OAuthInterceptorResponse struct {
StatusCode int `json:"statusCode"` // This is non-zero when the OAuth interceptor, upon completing its functions, intends to pass on the status code to the caller.
Response string `json:"response,omitempty"` // This is non-empty when the OAuth interceptor, upon completing its functions, intends to pass on the response body to the caller.
ErrorType string `json:"errorType,omitempty"` // This is non-empty when the failure carries an error type (e.g. common.RefTokenInvalidGrant), letting callers act on the specific error rather than inferring it from the status code.
}
type TransportResponse struct {
OriginalResponse string `json:"originalResponse"`
InterceptorResponse OAuthInterceptorResponse `json:"interceptorResponse"`
}