blob: 5985a0fc42e258a3bbfabf38d8531162726ba15c (
plain)
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 authz
import (
"net/http"
"strings"
"github.com/lestrrat-go/jwx/v3/jwt"
xlog "gitlab.com/mokhax/spike/pkg/log"
)
func TokenFrom(r *http.Request) jwt.Token {
authorization := r.Header.Get("Authorization")
if authorization == "" || !strings.Contains(authorization, "Bearer") {
return jwt.New()
}
token, err := jwt.ParseRequest(r,
jwt.WithContext(r.Context()),
jwt.WithHeaderKey("Authorization"),
jwt.WithValidate(false), // TODO:: Connect this to a JSON Web Key Set
jwt.WithVerify(false), // TODO:: Connect this to a JSON Web Key Set
)
if err != nil {
xlog.WithFields(r, xlog.Fields{"error": err})
return jwt.New()
}
return token
}
|