6
6
"crypto/tls"
7
7
"crypto/x509"
8
8
"encoding/hex"
9
- "errors"
10
9
"fmt"
11
10
"io"
12
11
"net/http"
@@ -22,9 +21,8 @@ import (
22
21
"github.com/openshift/console/pkg/auth/sessions"
23
22
oscrypto "github.com/openshift/library-go/pkg/crypto"
24
23
25
- authv1 "k8s.io/api/authentication/v1"
26
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
24
"k8s.io/client-go/kubernetes"
25
+ authenticationv1 "k8s.io/client-go/kubernetes/typed/authentication/v1"
28
26
"k8s.io/client-go/rest"
29
27
"k8s.io/klog/v2"
30
28
)
@@ -95,6 +93,7 @@ type loginMethod interface {
95
93
Authenticate (http.ResponseWriter , * http.Request ) (* auth.User , error )
96
94
oauth2Config () * oauth2.Config
97
95
GetSpecialURLs () auth.SpecialAuthURLs
96
+ ReviewToken (* http.Request , authenticationv1.TokenReviewInterface ) error
98
97
}
99
98
100
99
// AuthSource allows callers to switch between Tectonic and OpenShift login support.
@@ -305,39 +304,7 @@ func (a *OAuth2Authenticator) LoginFunc(w http.ResponseWriter, r *http.Request)
305
304
}
306
305
307
306
func (a * OAuth2Authenticator ) ReviewToken (r * http.Request ) error {
308
- token , err := sessions .GetSessionTokenFromCookie (r )
309
- if err != nil {
310
- return err
311
- }
312
-
313
- tokenReview := & authv1.TokenReview {
314
- TypeMeta : metav1.TypeMeta {
315
- APIVersion : "authentication.k8s.io/v1" ,
316
- Kind : "TokenReview" ,
317
- },
318
- Spec : authv1.TokenReviewSpec {
319
- Token : token ,
320
- },
321
- }
322
-
323
- completedTokenReview , err := a .
324
- internalK8sClientset .
325
- AuthenticationV1 ().
326
- TokenReviews ().
327
- Create (r .Context (), tokenReview , metav1.CreateOptions {})
328
-
329
- if err != nil {
330
- return fmt .Errorf ("failed to create TokenReview, %v" , err )
331
- }
332
-
333
- // Check if the token is authenticated
334
- if ! completedTokenReview .Status .Authenticated {
335
- if completedTokenReview .Status .Error != "" {
336
- return errors .New (completedTokenReview .Status .Error )
337
- }
338
- return errors .New ("failed to authenticate the token, unknownd error" )
339
- }
340
- return nil
307
+ return a .loginMethod .ReviewToken (r , a .internalK8sClientset .AuthenticationV1 ().TokenReviews ())
341
308
}
342
309
343
310
// LogoutFunc cleans up session cookies.
0 commit comments