Debian Codegraph @

pkg/authentication/authenticator/interfaces.go

raw
1 /*
2 Copyright 2014 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package authenticator
18
19 import (
20 "context"
21 "net/http"
22
23 "k8s.io/apiserver/pkg/authentication/user"
24 )
25
26 // Token checks a string value against a backing authentication store and
27 // returns a Response or an error if the token could not be checked.
28 type Token interface {
29 AuthenticateToken(ctx context.Context, token string) (*Response, bool, error)
30 }
31
32 // Request attempts to extract authentication information from a request and
33 // returns a Response or an error if the request could not be checked.
34 type Request interface {
35 AuthenticateRequest(req *http.Request) (*Response, bool, error)
36 }
37
38 // TokenFunc is a function that implements the Token interface.
39 type TokenFunc func(ctx context.Context, token string) (*Response, bool, error)
40
41 // AuthenticateToken implements authenticator.Token.
42 func (f TokenFunc) AuthenticateToken(ctx context.Context, token string) (*Response, bool, error) {
43 return f(ctx, token)
44 }
45
46 // RequestFunc is a function that implements the Request interface.
47 type RequestFunc func(req *http.Request) (*Response, bool, error)
48
49 // AuthenticateRequest implements authenticator.Request.
50 func (f RequestFunc) AuthenticateRequest(req *http.Request) (*Response, bool, error) {
51 return f(req)
52 }
53
54 // Response is the struct returned by authenticator interfaces upon successful
55 // authentication. It contains information about whether the authenticator
56 // authenticated the request, information about the context of the
57 // authentication, and information about the authenticated user.
58 type Response struct {
59 // Audiences is the set of audiences the authenticator was able to validate
60 // the token against. If the authenticator is not audience aware, this field
61 // will be empty.
62 Audiences Audiences
63 // User is the UserInfo associated with the authentication context.
64 User user.Info
65 }