APIKeySecurity defines an API key security scheme where a key must be provided by the client to perform authorization. APIKeySecurity is a top level DSL. APIKeySecurity takes a name as first argument and an optional DSL as second argument. Example: var APIKey = APIKeySecurity("key", func() {
(name string, fn ...func())
| 57 | // Description("Shared secret") |
| 58 | // }) |
| 59 | func APIKeySecurity(name string, fn ...func()) *expr.SchemeExpr { |
| 60 | if _, ok := eval.Current().(eval.TopExpr); !ok { |
| 61 | eval.IncompatibleDSL() |
| 62 | return nil |
| 63 | } |
| 64 | |
| 65 | if securitySchemeRedefined(name) { |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | e := &expr.SchemeExpr{ |
| 70 | Kind: expr.APIKeyKind, |
| 71 | SchemeName: name, |
| 72 | } |
| 73 | |
| 74 | if len(fn) != 0 { |
| 75 | if !eval.Execute(fn[0], e) { |
| 76 | return nil |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | expr.Root.Schemes = append(expr.Root.Schemes, e) |
| 81 | |
| 82 | return e |
| 83 | } |
| 84 | |
| 85 | // OAuth2Security defines an OAuth2 security scheme. The DSL provided as second |
| 86 | // argument defines the specific flows supported by the scheme. The supported |
no test coverage detected