Serge Bazanski | cc25bdf | 2018-10-25 14:02:58 +0200 | [diff] [blame] | 1 | // Copyright 2015 go-swagger maintainers |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package client |
| 16 | |
| 17 | import ( |
| 18 | "encoding/base64" |
| 19 | |
| 20 | "github.com/go-openapi/runtime" |
| 21 | "github.com/go-openapi/strfmt" |
| 22 | ) |
| 23 | |
| 24 | // PassThroughAuth never manipulates the request |
| 25 | var PassThroughAuth runtime.ClientAuthInfoWriter |
| 26 | |
| 27 | func init() { |
| 28 | PassThroughAuth = runtime.ClientAuthInfoWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error { return nil }) |
| 29 | } |
| 30 | |
| 31 | // BasicAuth provides a basic auth info writer |
| 32 | func BasicAuth(username, password string) runtime.ClientAuthInfoWriter { |
| 33 | return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error { |
| 34 | encoded := base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) |
| 35 | return r.SetHeaderParam("Authorization", "Basic "+encoded) |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | // APIKeyAuth provides an API key auth info writer |
| 40 | func APIKeyAuth(name, in, value string) runtime.ClientAuthInfoWriter { |
| 41 | if in == "query" { |
| 42 | return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error { |
| 43 | return r.SetQueryParam(name, value) |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | if in == "header" { |
| 48 | return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error { |
| 49 | return r.SetHeaderParam(name, value) |
| 50 | }) |
| 51 | } |
| 52 | return nil |
| 53 | } |
| 54 | |
| 55 | // BearerToken provides a header based oauth2 bearer access token auth info writer |
| 56 | func BearerToken(token string) runtime.ClientAuthInfoWriter { |
| 57 | return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error { |
| 58 | return r.SetHeaderParam("Authorization", "Bearer "+token) |
| 59 | }) |
| 60 | } |