mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2024-11-24 08:52:25 +02:00
24 lines
541 B
Go
24 lines
541 B
Go
package providers
|
|
|
|
import (
|
|
"github.com/bitly/oauth2_proxy/api"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func validateToken(p Provider, access_token string, header http.Header) bool {
|
|
if access_token == "" || p.Data().ValidateUrl == nil {
|
|
return false
|
|
}
|
|
url := p.Data().ValidateUrl.String()
|
|
if len(header) == 0 {
|
|
url = url + "?access_token=" + access_token
|
|
}
|
|
if resp, err := api.RequestUnparsedResponse(url, header); err != nil {
|
|
log.Printf("token validation request failed: %s", err)
|
|
return false
|
|
} else {
|
|
return resp.StatusCode == 200
|
|
}
|
|
}
|