blob: 1822a21755cfe1a0d2731c08eddb169f97d7475e (
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 (
"fmt"
"net/http"
"strings"
"github.com/lestrrat-go/jwx/v3/jwt"
)
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 {
fmt.Printf("error: %v\n", err)
return jwt.New()
}
return token
}
|