Skip to content

Commit

Permalink
Merge pull request #11 from Stratoscale/default-auth
Browse files Browse the repository at this point in the history
 Add default behavior for auth functions
  • Loading branch information
nirarg-stratoscale committed Jun 6, 2018
2 parents 0274885 + 8418584 commit addf1fa
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example/client/pet/mock_API.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/client/store/mock_API.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions example/restapi/configure_swagger_petstore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/restapi/mock_PetAPI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/restapi/mock_StoreAPI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions templates/server/configureapi.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,25 @@ func Handler(c Config) (http.Handler, error) {
{{ range .SecurityDefinitions -}}
{{ if .IsBasicAuth -}}
api.{{ pascalize .ID }}Auth = func(user string, pass string) ({{if not ( eq .Principal "interface{}" )}}*{{ end }}{{.Principal}}, error) {
if c.Auth{{ pascalize .ID }} == nil {
return "", nil
}
return c.Auth{{ pascalize .ID }}(user, pass)
}
{{ end -}}
{{ if .IsAPIKeyAuth -}}
api.{{ pascalize .ID }}Auth = func(token string) ({{if not ( eq .Principal "interface{}" )}}*{{ end }}{{.Principal}}, error) {
if c.Auth{{ pascalize .ID }} == nil {
return token, nil
}
return c.Auth{{ pascalize .ID }}(token)
}
{{ end }}
{{ if .IsOAuth2 -}}
if c.Auth == nil {
return nil, fmt.Errorf("Authenticator was not defined")
}
api.{{ pascalize .ID }}Auth = func(token string, scopes []string) ({{if not ( eq .Principal "interface{}" )}}*{{ end }}{{.Principal}}, error) {
if c.Auth{{ pascalize .ID }} == nil {
return token, nil
}
return c.Auth{{ pascalize .ID }}(token, scopes)
}
{{ end -}}
Expand Down

0 comments on commit addf1fa

Please sign in to comment.