Skip to content

Commit df3f538

Browse files
authored
Merge pull request #160 from AlexanderYastrebov/remove-strings.Split
ginoauth2: use strings.Cut
2 parents 66a94d4 + e9b53d4 commit df3f538

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

ginoauth2.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ func extractToken(r *http.Request) (*oauth2.Token, error) {
107107
return nil, errors.New("no authorization header")
108108
}
109109

110-
th := strings.Split(hdr, " ")
111-
if len(th) != 2 {
112-
return nil, errors.New("incomplete authorization header")
110+
typ, token, ok := strings.Cut(hdr, " ")
111+
if !ok {
112+
return nil, errors.New("invalid authorization header")
113113
}
114-
115-
return &oauth2.Token{AccessToken: th[1], TokenType: th[0]}, nil
114+
return &oauth2.Token{AccessToken: token, TokenType: typ}, nil
116115
}
117116

118117
func requestAuthInfo(o Options, t *oauth2.Token) ([]byte, error) {

0 commit comments

Comments
 (0)