Extract method: buildValidateAuthTokenRequest
Some checks failed
the build failed

This commit is contained in:
Peter Stuifzand 2018-09-15 16:15:35 +02:00
parent 8d99527e45
commit c17cd92268
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 374322D56E5209E8

View File

@ -67,15 +67,11 @@ func (b *memoryBackend) checkAuthToken(header string, token *auth.TokenResponse)
tokenEndpoint := b.TokenEndpoint
req, err := http.NewRequest("GET", tokenEndpoint, nil)
req, err := buildValidateAuthTokenRequest(tokenEndpoint, header)
if err != nil {
log.Println(err)
return false
}
req.Header.Add("Authorization", header)
req.Header.Add("Accept", "application/json")
client := http.Client{}
res, err := client.Do(req)
if err != nil {
@ -100,6 +96,13 @@ func (b *memoryBackend) checkAuthToken(header string, token *auth.TokenResponse)
return true
}
func buildValidateAuthTokenRequest(tokenEndpoint string, header string) (*http.Request, error) {
req, err := http.NewRequest("GET", tokenEndpoint, nil)
req.Header.Add("Authorization", header)
req.Header.Add("Accept", "application/json")
return req, err
}
// setCachedTokenResponseValue remembers the value of the auth token response in redis
func setCachedTokenResponseValue(conn redis.Conn, key string, r *auth.TokenResponse) error {
_, err := conn.Do("HMSET", redis.Args{}.Add(key).AddFlat(r)...)