You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-11-29 22:48:19 +02:00
Create generic Authorization Header constructor
This commit is contained in:
31
providers/util.go
Normal file
31
providers/util.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
tokenTypeBearer = "Bearer"
|
||||
tokenTypeToken = "token"
|
||||
|
||||
acceptHeader = "Accept"
|
||||
acceptApplicationJSON = "application/json"
|
||||
)
|
||||
|
||||
func makeAuthorizationHeader(prefix, token string, extraHeaders map[string]string) http.Header {
|
||||
header := make(http.Header)
|
||||
for key, value := range extraHeaders {
|
||||
header.Add(key, value)
|
||||
}
|
||||
header.Set("Authorization", fmt.Sprintf("%s %s", prefix, token))
|
||||
return header
|
||||
}
|
||||
|
||||
func makeOIDCHeader(accessToken string) http.Header {
|
||||
// extra headers required by the IDP when making authenticated requests
|
||||
extraHeaders := map[string]string{
|
||||
acceptHeader: acceptApplicationJSON,
|
||||
}
|
||||
return makeAuthorizationHeader(tokenTypeBearer, accessToken, extraHeaders)
|
||||
}
|
||||
Reference in New Issue
Block a user