-
Notifications
You must be signed in to change notification settings - Fork 15
/
auth.go
42 lines (31 loc) · 875 Bytes
/
auth.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
package jwt
import (
"strings"
"github.com/dgrijalva/jwt-go"
)
// Claims interface.
type Claims interface {
jwt.Claims
Subject() string
}
// Reader is a claims reader interface.
type Reader interface {
Read(token string, recv Claims) error
}
// ReaderFunc allows regular function with a proper signature to be used as a Reader.
type ReaderFunc func(string, jwt.Claims) error
func (fn ReaderFunc) Read(token string, recv Claims) error { return fn(token, recv) }
func getAuthorizartionValue(value interface{}) (string, error) {
authValue, is := value.(string)
if !is {
return "", errInvalidValueType
}
parts := strings.Split(authValue, " ")
if len(parts) != 2 {
return "", errMalformedAuthValue
}
if kind := strings.ToLower(strings.TrimSpace(parts[0])); kind != "bearer" {
return "", errUnsupportedAuthMethod{kind: kind}
}
return parts[1], nil
}