BasicAuthSecurity defines a basic authentication security scheme. BasicAuthSecurity is a top level DSL. BasicAuthSecurity takes a name as first argument and an optional DSL as second argument. Example: var Basic = BasicAuthSecurity("basicauth", func() { Description("Use your own password!"
(name string, fn ...func())
| 18 | // Description("Use your own password!") |
| 19 | // }) |
| 20 | func BasicAuthSecurity(name string, fn ...func()) *expr.SchemeExpr { |
| 21 | if _, ok := eval.Current().(eval.TopExpr); !ok { |
| 22 | eval.IncompatibleDSL() |
| 23 | return nil |
| 24 | } |
| 25 | |
| 26 | if securitySchemeRedefined(name) { |
| 27 | return nil |
| 28 | } |
| 29 | |
| 30 | e := &expr.SchemeExpr{ |
| 31 | Kind: expr.BasicAuthKind, |
| 32 | SchemeName: name, |
| 33 | } |
| 34 | |
| 35 | if len(fn) != 0 { |
| 36 | if !eval.Execute(fn[0], e) { |
| 37 | return nil |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | expr.Root.Schemes = append(expr.Root.Schemes, e) |
| 42 | |
| 43 | return e |
| 44 | } |
| 45 | |
| 46 | // APIKeySecurity defines an API key security scheme where a key must be |
| 47 | // provided by the client to perform authorization. |