-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth_flow.go
90 lines (72 loc) · 3.95 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
package openapi
import (
"net/url"
"github.com/MarkRosemaker/errpath"
)
// OAuthFlowImplicit allows configuration details for the OAuth Implicit flow.
type OAuthFlowImplicit struct {
// REQUIRED. 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.
AuthorizationURL *url.URL `json:"authorizationUrl" yaml:"authorizationUrl"`
// 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 *url.URL `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
// REQUIRED. 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.
Scopes MapOfStrings `json:"scopes" yaml:"scopes"`
// This object MAY be extended with Specification Extensions.
Extensions Extensions `json:",inline" yaml:",inline"`
}
func (f *OAuthFlowImplicit) Validate() error {
if f.AuthorizationURL == nil {
return &errpath.ErrField{Field: "authorizationUrl", Err: &errpath.ErrRequired{}}
}
if f.Scopes == nil {
return &errpath.ErrField{Field: "scopes", Err: &errpath.ErrRequired{}}
}
return validateExtensions(f.Extensions)
}
// OAuthFlowPassword allows configuration details for the OAuth Resource Owner Password flow.
type OAuthFlowPassword struct {
// REQUIRED. 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.
TokenURL *url.URL `json:"tokenUrl" yaml:"tokenUrl"`
// 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 *url.URL `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
// REQUIRED. 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.
Scopes MapOfStrings `json:"scopes" yaml:"scopes"`
// This object MAY be extended with Specification Extensions.
Extensions Extensions `json:",inline" yaml:",inline"`
}
func (f *OAuthFlowPassword) Validate() error {
if f.TokenURL == nil {
return &errpath.ErrField{Field: "tokenUrl", Err: &errpath.ErrRequired{}}
}
if f.Scopes == nil {
return &errpath.ErrField{Field: "scopes", Err: &errpath.ErrRequired{}}
}
return validateExtensions(f.Extensions)
}
// OAuthFlowClientCredentials allows configuration details for the OAuth Client Credentials flow.
type OAuthFlowClientCredentials = OAuthFlowPassword
// OAuthFlowAuthorizationCode allows configuration details for the OAuth Authorization Code flow.
type OAuthFlowAuthorizationCode struct {
// REQUIRED. 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.
AuthorizationURL *url.URL `json:"authorizationUrl" yaml:"authorizationUrl"`
// REQUIRED. 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.
TokenURL *url.URL `json:"tokenUrl" yaml:"tokenUrl"`
// 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 *url.URL `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
// REQUIRED. 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.
Scopes MapOfStrings `json:"scopes" yaml:"scopes"`
// This object MAY be extended with Specification Extensions.
Extensions Extensions `json:",inline" yaml:",inline"`
}
func (f *OAuthFlowAuthorizationCode) Validate() error {
if f.AuthorizationURL == nil {
return &errpath.ErrField{Field: "authorizationUrl", Err: &errpath.ErrRequired{}}
}
if f.TokenURL == nil {
return &errpath.ErrField{Field: "tokenUrl", Err: &errpath.ErrRequired{}}
}
if f.Scopes == nil {
return &errpath.ErrField{Field: "scopes", Err: &errpath.ErrRequired{}}
}
return validateExtensions(f.Extensions)
}