Skip to content

Commit

Permalink
Fix oauth2 in openapi2conv.FromV3SecurityScheme (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaznocha authored Feb 21, 2022
1 parent 0846d70 commit 124b07e
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,17 +1124,33 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o
if flows != nil {
var flow *openapi3.OAuthFlow
// TODO: Is this the right priority? What if multiple defined?
if flow = flows.Implicit; flow != nil {
switch {
case flows.Implicit != nil:
result.Flow = "implicit"
} else if flow = flows.AuthorizationCode; flow != nil {
flow = flows.Implicit
result.AuthorizationURL = flow.AuthorizationURL

case flows.AuthorizationCode != nil:
result.Flow = "accessCode"
} else if flow = flows.Password; flow != nil {
flow = flows.AuthorizationCode
result.AuthorizationURL = flow.AuthorizationURL
result.TokenURL = flow.TokenURL

case flows.Password != nil:
result.Flow = "password"
} else if flow = flows.ClientCredentials; flow != nil {
flow = flows.Password
result.TokenURL = flow.TokenURL

case flows.ClientCredentials != nil:
result.Flow = "application"
} else {
flow = flows.ClientCredentials
result.TokenURL = flow.TokenURL

default:
return nil, nil
}

result.Scopes = make(map[string]string, len(flow.Scopes))
for scope, desc := range flow.Scopes {
result.Scopes[scope] = desc
}
Expand Down

0 comments on commit 124b07e

Please sign in to comment.