@@ -19,7 +19,7 @@ import (
1919 "github.com/openshift/origin/pkg/oauthserver/authenticator/password/bootstrap"
2020)
2121
22- type endpointDetails struct {
22+ type tokenRequest struct {
2323 publicMasterURL string
2424 // osinOAuthClient is the private OAuth client used by this endpoint.
2525 // It starts out nil and is lazily initialized when this endpoint is called.
@@ -38,13 +38,8 @@ type endpointDetails struct {
3838 openShiftLogoutPrefix string
3939}
4040
41- // TODO this interface needs to be moved
42- type Endpoints interface {
43- Install (mux oauthserver.Mux , paths ... string )
44- }
45-
46- func NewEndpoints (publicMasterURL , openShiftLogoutPrefix string , osinOAuthClientGetter func () (* osincli.Client , error ), tokens v1.OAuthAccessTokenInterface ) Endpoints {
47- return & endpointDetails {
41+ func NewTokenRequest (publicMasterURL , openShiftLogoutPrefix string , osinOAuthClientGetter func () (* osincli.Client , error ), tokens v1.OAuthAccessTokenInterface ) oauthserver.Endpoints {
42+ return & tokenRequest {
4843 publicMasterURL : publicMasterURL ,
4944 osinOAuthClientGetter : osinOAuthClientGetter ,
5045 ready : make (chan struct {}),
@@ -53,23 +48,19 @@ func NewEndpoints(publicMasterURL, openShiftLogoutPrefix string, osinOAuthClient
5348 }
5449}
5550
56- // Install registers the request token endpoints into a mux. It is expected that the
57- // provided prefix will serve all operations
58- func (e * endpointDetails ) Install (mux oauthserver.Mux , paths ... string ) {
59- for _ , prefix := range paths {
60- mux .HandleFunc (path .Join (prefix , urls .RequestTokenEndpoint ), e .readyHandler (e .requestToken ))
61- mux .HandleFunc (path .Join (prefix , urls .DisplayTokenEndpoint ), e .readyHandler (e .displayToken ))
62- mux .HandleFunc (path .Join (prefix , urls .ImplicitTokenEndpoint ), e .implicitToken )
63- }
51+ func (t * tokenRequest ) Install (mux oauthserver.Mux , prefix string ) {
52+ mux .HandleFunc (path .Join (prefix , urls .RequestTokenEndpoint ), t .readyHandler (t .requestToken ))
53+ mux .HandleFunc (path .Join (prefix , urls .DisplayTokenEndpoint ), t .readyHandler (t .displayToken ))
54+ mux .HandleFunc (path .Join (prefix , urls .ImplicitTokenEndpoint ), t .implicitToken )
6455}
6556
6657// TODO we may want to start doing live lookups for this endpoint
67- func (e * endpointDetails ) readyHandler (delegate func (http.ResponseWriter , * http.Request )) func (http.ResponseWriter , * http.Request ) {
58+ func (t * tokenRequest ) readyHandler (delegate func (http.ResponseWriter , * http.Request )) func (http.ResponseWriter , * http.Request ) {
6859 return func (w http.ResponseWriter , h * http.Request ) {
6960 select {
70- case <- e .ready :
61+ case <- t .ready :
7162 default :
72- if err := e .safeInitOsinOAuthClientOnce (); err != nil {
63+ if err := t .safeInitOsinOAuthClientOnce (); err != nil {
7364 utilruntime .HandleError (fmt .Errorf ("failed to get Osin OAuth client for token endpoint: %v" , err ))
7465 http .Error (w , "OAuth token endpoint is not ready" , http .StatusInternalServerError )
7566 return
@@ -81,36 +72,36 @@ func (e *endpointDetails) readyHandler(delegate func(http.ResponseWriter, *http.
8172
8273// safeInitOsinOAuthClientOnce initializes osinOAuthClient exactly once using osinOAuthClientGetter.
8374// It is goroutine safe, reentrant and can be safely called multiple times.
84- func (e * endpointDetails ) safeInitOsinOAuthClientOnce () error {
75+ func (t * tokenRequest ) safeInitOsinOAuthClientOnce () error {
8576 // Use a lock and nil check to make sure we never close endpoints.ready more than once
8677 // and that we only try to fetch osinOAuthClient until the first time we are successful
87- e .initLock .Lock ()
88- defer e .initLock .Unlock ()
89- if e .osinOAuthClient == nil {
90- osinOAuthClient , err := e .osinOAuthClientGetter ()
78+ t .initLock .Lock ()
79+ defer t .initLock .Unlock ()
80+ if t .osinOAuthClient == nil {
81+ osinOAuthClient , err := t .osinOAuthClientGetter ()
9182 if err != nil {
9283 return err
9384 }
94- e .osinOAuthClient = osinOAuthClient
95- close (e .ready )
85+ t .osinOAuthClient = osinOAuthClient
86+ close (t .ready )
9687 }
9788 return nil
9889}
9990
10091// requestToken works for getting a token in your browser and seeing what your token is
101- func (e * endpointDetails ) requestToken (w http.ResponseWriter , req * http.Request ) {
102- authReq := e .osinOAuthClient .NewAuthorizeRequest (osincli .CODE )
92+ func (t * tokenRequest ) requestToken (w http.ResponseWriter , req * http.Request ) {
93+ authReq := t .osinOAuthClient .NewAuthorizeRequest (osincli .CODE )
10394 oauthURL := authReq .GetAuthorizeUrl ()
10495
10596 http .Redirect (w , req , oauthURL .String (), http .StatusFound )
10697}
10798
108- func (e * endpointDetails ) displayToken (w http.ResponseWriter , req * http.Request ) {
99+ func (t * tokenRequest ) displayToken (w http.ResponseWriter , req * http.Request ) {
109100 w .Header ().Set ("Content-Type" , "text/html; charset=UTF-8" )
110101 requestURL := urls .OpenShiftOAuthTokenRequestURL ("" ) // relative url to token request endpoint
111- data := tokenData {RequestURL : requestURL , PublicMasterURL : e .publicMasterURL }
102+ data := tokenData {RequestURL : requestURL , PublicMasterURL : t .publicMasterURL }
112103
113- authorizeReq := e .osinOAuthClient .NewAuthorizeRequest (osincli .CODE )
104+ authorizeReq := t .osinOAuthClient .NewAuthorizeRequest (osincli .CODE )
114105 authorizeData , err := authorizeReq .HandleRequest (req )
115106 if err != nil {
116107 data .Error = fmt .Sprintf ("Error handling auth request: %v" , err )
@@ -119,7 +110,7 @@ func (e *endpointDetails) displayToken(w http.ResponseWriter, req *http.Request)
119110 return
120111 }
121112
122- accessReq := e .osinOAuthClient .NewAccessRequest (osincli .AUTHORIZATION_CODE , authorizeData )
113+ accessReq := t .osinOAuthClient .NewAccessRequest (osincli .AUTHORIZATION_CODE , authorizeData )
123114 accessData , err := accessReq .GetToken ()
124115 if err != nil {
125116 data .Error = fmt .Sprintf ("Error getting token: %v" , err )
@@ -128,7 +119,7 @@ func (e *endpointDetails) displayToken(w http.ResponseWriter, req *http.Request)
128119 return
129120 }
130121
131- token , err := e .tokens .Get (accessData .AccessToken , metav1.GetOptions {})
122+ token , err := t .tokens .Get (accessData .AccessToken , metav1.GetOptions {})
132123 if err != nil {
133124 data .Error = "Error checking token" // do not leak error to user, do not log error
134125 w .WriteHeader (http .StatusInternalServerError )
@@ -138,7 +129,7 @@ func (e *endpointDetails) displayToken(w http.ResponseWriter, req *http.Request)
138129
139130 if token .UserName == bootstrap .BootstrapUser {
140131 // only the bootstrap user has a session we maintain for one more than OAuth flow
141- data .LogoutURL = e .openShiftLogoutPrefix
132+ data .LogoutURL = t .openShiftLogoutPrefix
142133 }
143134
144135 data .AccessToken = accessData .AccessToken
@@ -204,7 +195,7 @@ var tokenTemplate = template.Must(template.New("tokenTemplate").Parse(`
204195{{ end }}
205196` ))
206197
207- func (e * endpointDetails ) implicitToken (w http.ResponseWriter , req * http.Request ) {
198+ func (t * tokenRequest ) implicitToken (w http.ResponseWriter , req * http.Request ) {
208199 w .Header ().Set ("Content-Type" , "text/plain" )
209200 _ , _ = w .Write ([]byte (`
210201You have reached this page by following a redirect Location header from an OAuth authorize request.
0 commit comments