2016-06-07 01:27:44 +03:00
|
|
|
package request
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-06-07 03:45:30 +03:00
|
|
|
// Strips 'Bearer ' prefix from bearer token string
|
|
|
|
func stripBearerPrefixFromTokenString(tok string) (string, error) {
|
|
|
|
// Should be a bearer token
|
|
|
|
if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
|
|
|
|
return tok[7:], nil
|
|
|
|
}
|
|
|
|
return tok, nil
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:51:01 +03:00
|
|
|
// AuthorizationHeaderExtractor extracts a bearer token from Authorization header
|
2016-06-07 02:55:41 +03:00
|
|
|
// Uses PostExtractionFilter to strip "Bearer " prefix from header
|
2016-06-07 01:27:44 +03:00
|
|
|
var AuthorizationHeaderExtractor = &PostExtractionFilter{
|
|
|
|
HeaderExtractor{"Authorization"},
|
2016-06-07 03:45:30 +03:00
|
|
|
stripBearerPrefixFromTokenString,
|
2016-06-07 01:27:44 +03:00
|
|
|
}
|
|
|
|
|
2021-08-03 16:51:01 +03:00
|
|
|
// OAuth2Extractor is an Extractor for OAuth2 access tokens. Looks in 'Authorization'
|
2016-06-07 02:55:41 +03:00
|
|
|
// header then 'access_token' argument for a token.
|
2016-06-07 01:27:44 +03:00
|
|
|
var OAuth2Extractor = &MultiExtractor{
|
|
|
|
AuthorizationHeaderExtractor,
|
2016-06-07 03:18:24 +03:00
|
|
|
ArgumentExtractor{"access_token"},
|
2016-06-07 01:27:44 +03:00
|
|
|
}
|