Skip to content

Commit d4df86a

Browse files
krotscheckfenollp
andauthored
Add OIDC Schema format as per spec (#287)
Co-authored-by: Pierre Fenoll <[email protected]>
1 parent 4bb44a2 commit d4df86a

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

openapi3/security_scheme.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ var _ jsonpointer.JSONPointable = (*SecuritySchemes)(nil)
2828
type SecurityScheme struct {
2929
ExtensionProps
3030

31-
Type string `json:"type,omitempty" yaml:"type,omitempty"`
32-
Description string `json:"description,omitempty" yaml:"description,omitempty"`
33-
Name string `json:"name,omitempty" yaml:"name,omitempty"`
34-
In string `json:"in,omitempty" yaml:"in,omitempty"`
35-
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
36-
BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
37-
Flows *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
31+
Type string `json:"type,omitempty" yaml:"type,omitempty"`
32+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
33+
Name string `json:"name,omitempty" yaml:"name,omitempty"`
34+
In string `json:"in,omitempty" yaml:"in,omitempty"`
35+
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
36+
BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
37+
Flows *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
38+
OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
3839
}
3940

4041
func NewSecurityScheme() *SecurityScheme {
@@ -49,6 +50,13 @@ func NewCSRFSecurityScheme() *SecurityScheme {
4950
}
5051
}
5152

53+
func NewOIDCSecurityScheme(oidcUrl string) *SecurityScheme {
54+
return &SecurityScheme{
55+
Type: "openIdConnect",
56+
OpenIdConnectUrl: oidcUrl,
57+
}
58+
}
59+
5260
func NewJWTSecurityScheme() *SecurityScheme {
5361
return &SecurityScheme{
5462
Type: "http",
@@ -114,7 +122,9 @@ func (ss *SecurityScheme) Validate(c context.Context) error {
114122
case "oauth2":
115123
hasFlow = true
116124
case "openIdConnect":
117-
return fmt.Errorf("Support for security schemes with type '%v' has not been implemented", ss.Type)
125+
if ss.OpenIdConnectUrl == "" {
126+
return fmt.Errorf("No OIDC URL found for openIdConnect security scheme %q", ss.Name)
127+
}
118128
default:
119129
return fmt.Errorf("Security scheme 'type' can't be '%v'", ss.Type)
120130
}

openapi3/security_scheme_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,24 @@ var securitySchemeExamples = []securitySchemeExample{
198198
`),
199199
valid: true,
200200
},
201+
{
202+
title: "OIDC Type With URL",
203+
raw: []byte(`
204+
{
205+
"type": "openIdConnect",
206+
"openIdConnectUrl": "https://example.com/.well-known/openid-configuration"
207+
}
208+
`),
209+
valid: true,
210+
},
211+
{
212+
title: "OIDC Type Without URL",
213+
raw: []byte(`
214+
{
215+
"type": "openIdConnect",
216+
"openIdConnectUrl": ""
217+
}
218+
`),
219+
valid: false,
220+
},
201221
}

0 commit comments

Comments
 (0)