@@ -26,7 +26,7 @@ import (
26type noOpKeySet struct {
26type noOpKeySet struct {
29−func (noOpKeySet) VerifySignature(ctx context.Context, jwt string) (payload []byte, err error) {
29+func (noOpKeySet) VerifySignature(_ context.Context, jwt string) (payload []byte, err error) {
30 splitStrings := strings.Split(jwt, ".")
30 splitStrings := strings.Split(jwt, ".")
31 payloadString := splitStrings[1]
31 payloadString := splitStrings[1]
32 return base64.RawURLEncoding.DecodeString(payloadString)
32 return base64.RawURLEncoding.DecodeString(payloadString)
@@ -78,16 +78,14 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
78 const nonVerifiedToken = validToken
78 const nonVerifiedToken = validToken
80 BeforeEach(func() {
80 BeforeEach(func() {
81− verifier = func(ctx context.Context, token string) (interface{}, error) {
82− return oidc.NewVerifier(
81+ verifier = oidc.NewVerifier(
83− "https://issuer.example.com",
82+ "https://issuer.example.com",
84− noOpKeySet{},
83+ noOpKeySet{},
85− &oidc.Config{
84+ &oidc.Config{
86− ClientID: "https://test.myapp.com",
85+ ClientID: "https://test.myapp.com",
87− SkipExpiryCheck: true,
86+ SkipExpiryCheck: true,
89− ).Verify(ctx, token)
88+ ).Verify
93 type jwtSessionLoaderTableInput struct {
91 type jwtSessionLoaderTableInput struct {
@@ -110,10 +108,8 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
111 rw := httptest.NewRecorder()
109 rw := httptest.NewRecorder()
113− sessionLoaders := []middlewareapi.TokenToSessionLoader{
111+ sessionLoaders := []middlewareapi.TokenToSessionFunc{
114− {
112+ middlewareapi.CreateTokenToSessionFunc(verifier),
119 // Create the handler with a next handler that will capture the session
115 // Create the handler with a next handler that will capture the session
@@ -175,24 +171,19 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
175 const nonVerifiedToken = validToken
171 const nonVerifiedToken = validToken
177 BeforeEach(func() {
173 BeforeEach(func() {
178− verifier := func(ctx context.Context, token string) (interface{}, error) {
179− return oidc.NewVerifier(
174+ verifier := oidc.NewVerifier(
180− "https://issuer.example.com",
175+ "https://issuer.example.com",
181− noOpKeySet{},
176+ noOpKeySet{},
182− &oidc.Config{
177+ &oidc.Config{
183− ClientID: "https://test.myapp.com",
178+ ClientID: "https://test.myapp.com",
184− SkipExpiryCheck: true,
179+ SkipExpiryCheck: true,
186− ).Verify(ctx, token)
181+ ).Verify
189 j = &jwtSessionLoader{
183 j = &jwtSessionLoader{
190 jwtRegex: regexp.MustCompile(jwtRegexFormat),
184 jwtRegex: regexp.MustCompile(jwtRegexFormat),
191− sessionLoaders: []middlewareapi.TokenToSessionLoader{
185+ sessionLoaders: []middlewareapi.TokenToSessionFunc{
192− {
186+ middlewareapi.CreateTokenToSessionFunc(verifier),
194− TokenToSession: createSessionFromToken,
@@ -402,7 +393,7 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
405− Context("createSessionFromToken", func() {
396+ Context("CreateTokenToSessionFunc", func() {
406 ctx := context.Background()
397 ctx := context.Background()
407 expiresFuture := time.Now().Add(time.Duration(5) * time.Minute)
398 expiresFuture := time.Now().Add(time.Duration(5) * time.Minute)
408 verified := true
399 verified := true
@@ -414,7 +405,7 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
414 jwt.StandardClaims
405 jwt.StandardClaims
417− type createSessionStateTableInput struct {
408+ type tokenToSessionTableInput struct {
418 idToken idTokenClaims
409 idToken idTokenClaims
419 expectedErr error
410 expectedErr error
420 expectedUser string
411 expectedUser string
@@ -423,8 +414,8 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
425 DescribeTable("when creating a session from an IDToken",
416 DescribeTable("when creating a session from an IDToken",
426− func(in createSessionStateTableInput) {
417+ func(in tokenToSessionTableInput) {
427− verifier := func(ctx context.Context, token string) (interface{}, error) {
418+ verifier := func(ctx context.Context, token string) (*oidc.IDToken, error) {
428 oidcVerifier := oidc.NewVerifier(
419 oidcVerifier := oidc.NewVerifier(
429 "https://issuer.example.com",
420 "https://issuer.example.com",
430 noOpKeySet{},
421 noOpKeySet{},
@@ -443,7 +434,7 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
443 rawIDToken, err := jwt.NewWithClaims(jwt.SigningMethodRS256, in.idToken).SignedString(key)
434 rawIDToken, err := jwt.NewWithClaims(jwt.SigningMethodRS256, in.idToken).SignedString(key)
444 Expect(err).ToNot(HaveOccurred())
435 Expect(err).ToNot(HaveOccurred())
446− session, err := createSessionFromToken(ctx, rawIDToken, verifier)
437+ session, err := middlewareapi.CreateTokenToSessionFunc(verifier)(ctx, rawIDToken)
447 if in.expectedErr != nil {
438 if in.expectedErr != nil {
448 Expect(err).To(MatchError(in.expectedErr))
439 Expect(err).To(MatchError(in.expectedErr))
449 Expect(session).To(BeNil())
440 Expect(session).To(BeNil())
@@ -459,7 +450,7 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
459 Expect(session.RefreshToken).To(BeEmpty())
450 Expect(session.RefreshToken).To(BeEmpty())
460 Expect(session.PreferredUsername).To(BeEmpty())
451 Expect(session.PreferredUsername).To(BeEmpty())
462− Entry("with no email", createSessionStateTableInput{
453+ Entry("with no email", tokenToSessionTableInput{
463 idToken: idTokenClaims{
454 idToken: idTokenClaims{
464 StandardClaims: jwt.StandardClaims{
455 StandardClaims: jwt.StandardClaims{
465 Audience: "asdf1234",
456 Audience: "asdf1234",
@@ -476,7 +467,7 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
476 expectedEmail: "123456789",
467 expectedEmail: "123456789",
477 expectedExpires: &expiresFuture,
468 expectedExpires: &expiresFuture,
479− Entry("with a verified email", createSessionStateTableInput{
470+ Entry("with a verified email", tokenToSessionTableInput{
480 idToken: idTokenClaims{
471 idToken: idTokenClaims{
481 StandardClaims: jwt.StandardClaims{
472 StandardClaims: jwt.StandardClaims{
482 Audience: "asdf1234",
473 Audience: "asdf1234",
@@ -495,7 +486,7 @@ Nnc3a3lGVWFCNUMxQnNJcnJMTWxka1dFaHluYmI4Ongtb2F1dGgtYmFzaWM=`
495 expectedEmail: "foo@example.com",
486 expectedEmail: "foo@example.com",
496 expectedExpires: &expiresFuture,
487 expectedExpires: &expiresFuture,
498− Entry("with a non-verified email", createSessionStateTableInput{
489+ Entry("with a non-verified email", tokenToSessionTableInput{
499 idToken: idTokenClaims{
490 idToken: idTokenClaims{
500 StandardClaims: jwt.StandardClaims{
491 StandardClaims: jwt.StandardClaims{
501 Audience: "asdf1234",
492 Audience: "asdf1234",