forked from sv-tools/openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth-flow.go
104 lines (92 loc) · 2.89 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
99
100
101
102
103
104
package openapi
// OAuthFlow configuration details for a supported OAuth Flow
//
// https://spec.openapis.org/oas/v3.1.1#oauth-flow-object
//
// Example:
//
// implicit:
// authorizationUrl: https://example.com/api/oauth/dialog
// scopes:
// write:pets: modify pets in your account
// read:pets: read your pets
// authorizationCode
// authorizationUrl: https://example.com/api/oauth/dialog
// scopes:
// write:pets: modify pets in your account
// read:pets: read your pets
type OAuthFlow struct {
// 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.
//
// Applies To: oauth2
Scopes map[string]string `json:"scopes,omitempty" yaml:"scopes,omitempty"`
// 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.
//
// Applies To:oauth2 ("implicit", "authorizationCode")
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
// 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.
//
// Applies To: oauth2 ("password", "clientCredentials", "authorizationCode")
TokenURL string `json:"tokenUrl,omitempty" yaml:"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.
//
// Applies To: oauth2
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
}
func (o *OAuthFlow) validateSpec(path string, validator *Validator) []*validationError {
// all the validations are done in the parent object
return nil
}
type OAuthFlowBuilder struct {
spec *Extendable[OAuthFlow]
}
func NewOAuthFlowBuilder() *OAuthFlowBuilder {
return &OAuthFlowBuilder{
spec: NewExtendable[OAuthFlow](&OAuthFlow{}),
}
}
func (b *OAuthFlowBuilder) Build() *Extendable[OAuthFlow] {
return b.spec
}
func (b *OAuthFlowBuilder) Extensions(v map[string]any) *OAuthFlowBuilder {
b.spec.Extensions = v
return b
}
func (b *OAuthFlowBuilder) AddExt(name string, value any) *OAuthFlowBuilder {
b.spec.AddExt(name, value)
return b
}
func (b *OAuthFlowBuilder) Scopes(v map[string]string) *OAuthFlowBuilder {
b.spec.Spec.Scopes = v
return b
}
func (b *OAuthFlowBuilder) AddScope(name, value string) *OAuthFlowBuilder {
if b.spec.Spec.Scopes == nil {
b.spec.Spec.Scopes = make(map[string]string, 1)
}
b.spec.Spec.Scopes[name] = value
return b
}
func (b *OAuthFlowBuilder) AuthorizationURL(v string) *OAuthFlowBuilder {
b.spec.Spec.AuthorizationURL = v
return b
}
func (b *OAuthFlowBuilder) TokenURL(v string) *OAuthFlowBuilder {
b.spec.Spec.TokenURL = v
return b
}
func (b *OAuthFlowBuilder) RefreshURL(v string) *OAuthFlowBuilder {
b.spec.Spec.RefreshURL = v
return b
}