forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
placeholder_challenger.go
33 lines (27 loc) · 962 Bytes
/
placeholder_challenger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package placeholderchallenger
import (
"fmt"
"net/http"
oauthhandlers "github.com/openshift/origin/pkg/oauthserver/oauth/handlers"
)
type placeholderChallenger struct {
tokenRequestURL string
}
// New returns an AuthenticationChallenger that responds with a warning and link to the web UI for requesting a token
func New(url string) oauthhandlers.AuthenticationChallenger {
return placeholderChallenger{url}
}
// AuthenticationChallenge returns a header that indicates a basic auth challenge for the supplied realm
func (c placeholderChallenger) AuthenticationChallenge(req *http.Request) (http.Header, error) {
headers := http.Header{}
headers.Add("Warning",
fmt.Sprintf(
`%s %s "You must obtain an API token by visiting %s"`,
oauthhandlers.WarningHeaderMiscCode,
oauthhandlers.WarningHeaderOpenShiftSource,
c.tokenRequestURL,
),
)
headers.Add("Link", fmt.Sprintf(`<%s>; rel="related"`, c.tokenRequestURL))
return headers, nil
}