forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paramtoken.go
30 lines (25 loc) · 996 Bytes
/
paramtoken.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package paramtoken
import (
"net/http"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/user"
"github.com/openshift/origin/pkg/auth/authenticator"
)
// Authenticator provides a way to authenticate tokens provided as a parameter
// This only exists to allow websocket connections to use an API token, since they cannot set an Authorize header
// For this authenticator to work, tokens will be part of the request URL, and are more likely to be logged or otherwise exposed.
// Every effort should be made to filter tokens from being logged when using this authenticator.
type Authenticator struct {
param string
auth authenticator.Token
}
func New(param string, auth authenticator.Token) *Authenticator {
return &Authenticator{param, auth}
}
func (a *Authenticator) AuthenticateRequest(req *http.Request) (user.Info, bool, error) {
token := strings.TrimSpace(req.FormValue(a.param))
if token == "" {
return nil, false, nil
}
return a.auth.AuthenticateToken(token)
}