oauth2_proxy/providers/internal_util.go

24 lines
541 B
Go
Raw Normal View History

2015-05-13 01:48:13 +00:00
package providers
import (
2015-05-21 06:50:21 +00:00
"github.com/bitly/oauth2_proxy/api"
2015-05-13 01:48:13 +00:00
"log"
"net/http"
)
2015-06-06 18:15:43 +00:00
func validateToken(p Provider, access_token string, header http.Header) bool {
2015-05-13 01:48:13 +00:00
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
}
}