Skip to content

Commit fd6d731

Browse files
authored
Fix retreiveID token when encryption and compression are enabled (#690)
1 parent 75b0580 commit fd6d731

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

e2e/e2e_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,110 @@ var _ = Describe("Code Flow login/logout DisableLogoutAuth", func() {
28032803
})
28042804
})
28052805

2806+
var _ = Describe("Code Flow login/logout compressed and encrypted ID token", func() {
2807+
var portNum string
2808+
var proxyAddress string
2809+
errGroup, _ := errgroup.WithContext(context.Background())
2810+
var server *http.Server
2811+
2812+
AfterEach(func() {
2813+
if server != nil {
2814+
err := server.Shutdown(context.Background())
2815+
Expect(err).NotTo(HaveOccurred())
2816+
}
2817+
if errGroup != nil {
2818+
err := errGroup.Wait()
2819+
Expect(err).NotTo(HaveOccurred())
2820+
}
2821+
})
2822+
2823+
BeforeEach(func() {
2824+
var err error
2825+
var upstreamSvcPort string
2826+
2827+
server, upstreamSvcPort = startAndWaitTestUpstream(errGroup, false, false, false)
2828+
portNum, err = generateRandomPort()
2829+
Expect(err).NotTo(HaveOccurred())
2830+
proxyAddress = localURI + portNum
2831+
2832+
proxyArgs := []string{
2833+
"--discovery-url=" + idpRealmURI,
2834+
"--openid-provider-timeout=300s",
2835+
"--tls-openid-provider-ca-certificate=" + tlsCaCertificate,
2836+
"--tls-openid-provider-client-certificate=" + tlsCertificate,
2837+
"--tls-openid-provider-client-private-key=" + tlsPrivateKey,
2838+
"--listen=" + allInterfaces + portNum,
2839+
"--client-id=" + testClient,
2840+
"--client-secret=" + testClientSecret,
2841+
"--upstream-url=" + localURI + upstreamSvcPort,
2842+
"--no-redirects=false",
2843+
"--skip-access-token-clientid-check=true",
2844+
"--skip-access-token-issuer-check=true",
2845+
"--enable-idp-session-check=false",
2846+
"--enable-default-deny=false",
2847+
"--enable-logout-redirect=true",
2848+
"--enable-id-token-cookie=true",
2849+
"--post-logout-redirect-uri=https://" + testExternalURI,
2850+
"--resources=uri=/*|roles=uma_authorization,offline_access",
2851+
"--openid-provider-retry-count=30",
2852+
"--enable-refresh-tokens=true",
2853+
"--encryption-key=" + testKey,
2854+
"--secure-cookie=false",
2855+
"--post-login-redirect-path=" + postLoginRedirectPath,
2856+
"--enable-register-handler=true",
2857+
"--enable-pkce=false",
2858+
"--tls-cert=" + tlsCertificate,
2859+
"--tls-private-key=" + tlsPrivateKey,
2860+
"--upstream-ca=" + tlsCaCertificate,
2861+
"--enable-encrypted-token=true",
2862+
"--enable-logout-auth=false",
2863+
"--enable-compress-token=true",
2864+
}
2865+
2866+
osArgs := make([]string, 0, 1+len(proxyArgs))
2867+
osArgs = append(osArgs, os.Args[0])
2868+
osArgs = append(osArgs, proxyArgs...)
2869+
startAndWait(portNum, osArgs)
2870+
})
2871+
2872+
When("Performing standard login", func() {
2873+
It("should login with user/password and logout with redirect successfully",
2874+
Label("code_flow"),
2875+
Label("compressed_encrypted_id_token"),
2876+
func(_ context.Context) {
2877+
var err error
2878+
rClient := resty.New()
2879+
rClient.SetTLSClientConfig(&tls.Config{RootCAs: caPool, MinVersion: tls.VersionTLS13})
2880+
resp := codeFlowLogin(rClient, proxyAddress, http.StatusOK, testUser, testPass)
2881+
Expect(resp.Header().Get("Proxy-Accepted")).To(Equal("true"))
2882+
body := resp.Body()
2883+
Expect(strings.Contains(string(body), postLoginRedirectPath)).To(BeTrue())
2884+
Expect(err).NotTo(HaveOccurred())
2885+
2886+
By("make another request with access token")
2887+
resp, err = rClient.R().Get(proxyAddress + anyURI)
2888+
Expect(err).NotTo(HaveOccurred())
2889+
Expect(resp.Header().Get("Proxy-Accepted")).To(Equal("true"))
2890+
body = resp.Body()
2891+
Expect(strings.Contains(string(body), anyURI)).To(BeTrue())
2892+
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
2893+
2894+
By("log out")
2895+
//nolint:gosec
2896+
rClient.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
2897+
resp, err = rClient.R().Get(proxyAddress + logoutURI)
2898+
Expect(err).NotTo(HaveOccurred())
2899+
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
2900+
Expect(strings.Contains(string(resp.Body()), testExternalURI)).To(BeTrue())
2901+
2902+
rClient.SetRedirectPolicy(resty.NoRedirectPolicy())
2903+
resp, _ = rClient.R().Get(proxyAddress)
2904+
Expect(resp.StatusCode()).To(Equal(http.StatusSeeOther))
2905+
},
2906+
)
2907+
})
2908+
})
2909+
28062910
var _ = Describe("Code Flow Request Upstream Compression", func() {
28072911
var portNum1 string
28082912
var proxyAddress1 string

pkg/proxy/handlers/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func RetrieveIDToken(
126126
}
127127

128128
if enableCompressToken {
129-
token, err = session.DecryptAndDecompressToken(token, encryptionKey)
129+
token, err = session.DecryptAndDecompressToken(encrypted, encryptionKey)
130130
if err != nil {
131131
return "", "", errors.Join(apperrors.ErrDecryptAndDecompressToken, err)
132132
}

0 commit comments

Comments
 (0)