aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/httputil/headers/authorization.go
blob: 145e04f9312ceda7ef82e42542e40cd2e27fe501 (plain) (blame)
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
package headers

import "strings"

const (
	AuthorizationKey = "Authorization"

	TokenTypeBearer TokenType = "bearer"
	TokenTypeMAC    TokenType = "mac"
)

type TokenType string

// String implements stringer interface
func (tt TokenType) String() string {
	return string(tt)
}

func AuthorizationTokenType(token string) TokenType {
	if len(token) > len(TokenTypeBearer) &&
		strings.ToLower(token[:len(TokenTypeBearer)]) == TokenTypeBearer.String() {
		return TokenTypeBearer
	}

	if len(token) > len(TokenTypeMAC) &&
		strings.ToLower(token[:len(TokenTypeMAC)]) == TokenTypeMAC.String() {
		return TokenTypeMAC
	}

	return TokenType("unknown")
}