forked from chanced/openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth_flow.go
98 lines (85 loc) · 3.02 KB
/
oauth_flow.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package openapi
import "github.com/chanced/openapi/yamlutil"
// OAuthFlows allows configuration of the supported OAuth Flows.
type OAuthFlows struct {
// Configuration for the OAuth Implicit flow
Implicit *OAuthFlow `json:"implicit,omitempty"`
// Configuration for the OAuth Resource Owner Password flow
Password *OAuthFlow `json:"password,omitempty"`
// Configuration for the OAuth Client Credentials flow. Previously called
// application in OpenAPI 2.0.
ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
// Configuration for the OAuth Authorization Code flow. Previously called accessCode in OpenAPI 2.0.
AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
Extensions `json:"-"`
}
type oauthflows OAuthFlows
// MarshalJSON marshals json
func (oaf OAuthFlows) MarshalJSON() ([]byte, error) {
return marshalExtendedJSON(oauthflows(oaf))
}
// UnmarshalJSON unmarshals json
func (oaf *OAuthFlows) UnmarshalJSON(data []byte) error {
var v oauthflows
if err := unmarshalExtendedJSON(data, &v); err != nil {
return err
}
*oaf = OAuthFlows(v)
return nil
}
// MarshalYAML marshals YAML
func (oaf OAuthFlows) MarshalYAML() (interface{}, error) {
return yamlutil.Marshal(oaf)
}
// UnmarshalYAML unmarshals YAML
func (oaf *OAuthFlows) UnmarshalYAML(unmarshal func(interface{}) error) error {
return yamlutil.Unmarshal(unmarshal, oaf)
}
// OAuthFlow configuration details for a supported OAuth Flow
type OAuthFlow struct {
// The authorization URL to be used for this flow. This MUST be in the form
// of a URL. The OAuth2 standard requires the use of TLS.
//
// Applies to: OAuth2 ("implicit", "authorizationCode")
//
// *required*
AuthorizationURL string `json:"authorizationUrl,omitempty"`
// The token URL to be used for this flow. This MUST be in the form of a
// URL. The OAuth2 standard requires the use of TLS.
//
// Applies to: OAuth2Flow ("password", "clientCredentials", "authorizationCode")
//
// *required*
TokenURL string `json:"tokenUrl,omitempty"`
// The URL to be used for obtaining refresh tokens. This MUST be in the form
// of a URL. The OAuth2 standard requires the use of TLS.
RefreshURL string `json:"refreshUrl,omitempty"`
// The available scopes for the OAuth2 security scheme. A map between the
// scope name and a short description for it. The map MAY be empty.
//
// *required*
Scopes map[string]string `json:"scopes"`
Extensions `json:"-"`
}
type oauthflow OAuthFlow
// MarshalJSON marshals json
func (o OAuthFlow) MarshalJSON() ([]byte, error) {
return marshalExtendedJSON(oauthflow(o))
}
// UnmarshalJSON unmarshals json
func (o *OAuthFlow) UnmarshalJSON(data []byte) error {
var v oauthflow
if err := unmarshalExtendedJSON(data, &v); err != nil {
return err
}
*o = OAuthFlow(v)
return nil
}
// MarshalYAML marshals YAML
func (o OAuthFlow) MarshalYAML() (interface{}, error) {
return yamlutil.Marshal(o)
}
// UnmarshalYAML unmarshals YAML
func (o *OAuthFlow) UnmarshalYAML(unmarshal func(interface{}) error) error {
return yamlutil.Unmarshal(unmarshal, o)
}