-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
51 lines (46 loc) · 1009 Bytes
/
token.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"github.com/labstack/echo"
"net/http"
)
type H map[string]interface{}
var authFailed = H{
"apiVersion": "authentication.k8s.io/v1beta1",
"kind": "TokenReview",
"status": H{
"authenticated": false,
},
}
type APIScheme struct {
Version string `json:"apiVersion"`
Kind string `json:"kind"`
Spec APISpec `json:"spec"`
}
type APISpec struct {
Token string `json:"token"`
}
func token(c echo.Context) error {
var apiScheme APIScheme
if err := c.Bind(&apiScheme); err == nil {
_, user, err := authLDAP(apiScheme.Spec.Token)
if err == nil && user != nil {
c.JSON(http.StatusOK, H{
"apiVersion": "authentication.k8s.io/v1beta1",
"kind": "TokenReview",
"status": H{
"authenticated": true,
"user": H{
"username": user.Name,
"uid": user.Id,
"groups": user.Groups,
},
},
})
} else {
c.JSON(http.StatusUnauthorized, authFailed)
}
} else {
c.JSON(http.StatusUnauthorized, authFailed)
}
return nil
}