You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@guacamole.apache.org by "adb014 (via GitHub)" <gi...@apache.org> on 2026/04/07 23:28:45 UTC

[PR] OpenID code flow, client secret and PKCE [guacamole-client]

adb014 opened a new pull request, #1198:
URL: https://github.com/apache/guacamole-client/pull/1198

   The existing OpenID extension only supports OpenID implicit flow. Knowing that this method is deprecated in OAuth2 due to its poor security, Guacamole really needs to add code flow authorization to its OpenID extension.
   
   This pull request add code flow, but also allows for pkce challenges to be passed to the authorization endpoint and pkce verifiers and client secrets to be passed to the token endpoint. This options for this are 
   
   ```
   openid-flow-type: implicit | code
   openid-authorization-endpoint: https://identity-provider/auth
   openid-token-endpoint:  https://identity-provider/token
   openid-jwks-endpoint: https://identity-provider/jwks
   openid-issuer: identity-provider
   openid-client-id: my-client-id
   openid-client-secret: my-client-secret | null
   openid-pkce-required: true | false
   openid-redirect-uri: https://example.net/guacamole
   ```
   
   Allowing the existing implicit flow code to be used by default without changes to existing configurations. 
   
   One problem I had is that the getLoginURI method didn't seem to allow me to save the PKCE verifier and in any case I didn't want the code returned by the identity provider to appear in the browser navigation bar. So I created a local REST redirect api to talk to the identity provider and receive the response. If you know how to use the AuthenticationSessionManager within getLoginURI and  hide the returned code in the navigation bar this might be done differently. 
   
   There is a draft JAR built against guacamole 1.6.0 on my fork of guacamole-client 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - don’t introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find any apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only
   needed a couple of values. 
   
   The slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the http post/get operations are one off each time.
   
   I've updated the code using httpClient and included asynchronous operation to release control back to the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regrets is the right thing to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178837656


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   Ok I wrote a version based on "org.springframework.security.oauth2" and here are the list of new depedencies identified by their lack of license, even after exclusion of the maximum number of transitive dependencies 
   
   ```
   ERROR: License information missing for org.springframework.security:spring-security-oauth2-jose:jar:6.2.4
   ERROR: License information missing for org.springframework.security:spring-security-core:jar:6.2.4
   ERROR: License information missing for org.springframework.security:spring-security-crypto:jar:6.2.4
   ERROR: License information missing for org.springframework:spring-aop:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-context:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-expression:jar:6.1.6
   ERROR: License information missing for org.springframework.security:spring-security-oauth2-core:jar:6.2.4
   ERROR: License information missing for org.springframework:spring-core:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-jcl:jar:6.1.6
   ERROR: License information missing for com.nimbusds:nimbus-jose-jwt:jar:9.24.4
   ERROR: License information missing for com.github.stephenc.jcip:jcip-annotations:jar:1.0-1
   ERROR: License information missing for org.springframework.security:spring-security-oauth2-client:jar:6.2.4
   ERROR: License information missing for org.springframework.security:spring-security-web:jar:6.2.4
   ERROR: License information missing for com.nimbusds:oauth2-oidc-sdk:jar:9.43.3
   ERROR: License information missing for com.nimbusds:content-type:jar:2.2
   ERROR: License information missing for net.minidev:json-smart:jar:2.4.10
   ERROR: License information missing for net.minidev:accessors-smart:jar:2.4.9
   ERROR: License information missing for org.ow2.asm:asm:jar:9.3
   ERROR: License information missing for com.nimbusds:lang-tag:jar:1.7
   ERROR: License information missing for org.springframework:spring-web:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-beans:jar:6.1.6
   ```
   
   Is it a problem if pull in that many additional dependencies ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3180465502


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   Ok, a "mvn dependency:tree" ahow me that the version 3.0.5 of springframework core referenced in doc/licenses is not in fact used anywhere. However, looking further the springframework OAuth2 package needs at least springframework core version 6 and both need Java17+.  I'd thought that Guacamole was still trying to keep Java11 compatibility, so this change would mean that at leaset Java17 would be needed for this module. See https://issues.apache.org/jira/browse/GUACAMOLE-1806 where compatability with Java8/Java11 seems to be required
   
   
    



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069529515


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {
+            throw new GuacamoleException("JsonUrlReader : Missing URL");
+        }
+        
+        try {
+            // Open connection, using HttpURLConnection
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+
+            conn.setRequestMethod(method);
+            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+
+            if (! method.equalsIgnoreCase("GET")) {

Review Comment:
   I had commented on this Friday, but it seems I did it in a self-review that I deleted. So here is my comment again
   
   Going to the[ RFC 7231 for HTTP/1.1  ](https://datatracker.ietf.org/doc/html/rfc7231#section-4.1) we see the text
   
   ```
     The method token is case-sensitive because it might be used as a gateway to object-based systems with case-sensitive method names.
   ```
   
   so any use of non uppercase method names is against the standard and should be ignored



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4594881251

   From shat I understand in my other PR this should be rebased against staging/1.6.1. However, I didn't create a personal branch for these change and so as far as I can see any forced push is going to mess up this PR...
   
   @necouchman can to resolve any outsatnding issues you have with this PR, I'll correct for the requested changes and after rebase against staging/1.6.1 and generate a new PR


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - No introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find and apache commons I/O function that treated both POST and GET.  The slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the htpp post/get operations are one off each time.
   
   I've updated the code using httpClient and included asynchronous operation to release control back the the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regrets is the right time to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062367026


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+     private static String issuer = null;
+
+    /**
+     * The detected authorization edpoint
+     */
+     private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token edpoint
+     */
+     private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+     private static URI jwks_uri = null;
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-well-known-endpoint";
+        }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the authorization
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.
+     */
+    public String getIssuer() {
+        return issuer;
+    }
+
+    /**
+     * Returns the authorization endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The authorization endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getAuthorizationEndpoint() {
+        return authorization_endpoint;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The token endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getTokenEndpoint() {
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the endpoint (URI) of the JWKS service which defines how
+     * received ID tokens (JWTs) shall be validated, as configured from
+     * the well-known endpoint.
+     *
+     * @return
+     *     The endpoint (URI) of the JWKS service which defines how received ID
+     *     tokens (JWTs) shall be validated, as configured from the
+     *     well-known endpoint.
+     */
+    public URI getJWKSEndpoint() {
+        return jwks_uri;
+    }
+
+    /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;
+
+    /*
+     * Creates an OpenIDWellKnown class that reads the json from an OIDC
+     * well-known endpoint and saves these values for later use. Use Guice
+     * to ensure environment exists before initializing.
+     */
+    public OpenIDWellKnown() {
+    }
+
+    @Inject
+    public void init() {
+        // Call to well-known endpoint might fail, so allow several tries before giving up
+        ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+        
+        Runnable task = new Runnable() {
+            int attempts = 0;
+
+            @Override
+            public void run() {
+                attempts++;
+
+                try {
+                    Map<String,Object> json = JsonUrlReader.fetch("GET", getWellKnownEndpoint().toURL(), "");

Review Comment:
   At the moment JsonUrlReader will be called 24 times failing each time and eventually stop. Yes I could have a fast return from init() if the well-known endpoint is missing
   
   The missing well-known endpoint just means the getters of confWellKnown will always return null, which is what we want in confService 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062355441


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -334,7 +419,130 @@ public String getIssuer() throws GuacamoleException {
      *     property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token
+     *     endpoint property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+    
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return confWellKnown.getWellKnownEndpoint();
+    }    

Review Comment:
   It’s not called anywhere. It’s implemented for completeness of the confService class, so all configuration variables have a getter. It might be used later. 
   
   It can be removed if you prefer



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - don’t introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find any apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only
   needed a couple of values. 
   
   The slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the http post/get operations are one off each time.
   
   I've updated the code using httpClient and included asynchronous operation to release control back to the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regret is the right thing to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - don’t introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find any apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only
   needed a couple of values. 
   
   The slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the http post/get operations are one off each time. Though using org.apache.http.impl.client.HttpClient is an option that might be attractive as it supplies functions to more cleanly treat the posted form data. 
   
   I've updated the code using httpClient and included asynchronous operation to release control back to the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regret is the right thing to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - don’t introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.net.httpUrlConnection is a bit old and ugly, but I couldn't find any apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only needed a couple of values. 
   
   The slightly more modern  java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the http post/get operations are one off each time. Though using org.apache.http.impl.client.HttpClient is an option that might be attractive as it supplies functions to more cleanly treat the posted form data. 
   
   I've updated the code using java.net.http.httpClient and included asynchronous operation to release control back to the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regret is the right thing to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "necouchman (via GitHub)" <gi...@apache.org>.
necouchman commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3176617467


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -260,11 +339,16 @@ public class ConfigurationService {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the authorization
-     *     endpoint property is missing.
+     *     If guacamole.properties cannot be parsed, or it authorization and
+     *     well-known endpoints are property is missing.

Review Comment:
   There are a couple of typos, here - I think the original `or if the` language was correct, and the change should just be to change the second line to  `and well-known endpoint properties are missing.`



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -260,11 +339,16 @@ public class ConfigurationService {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the authorization
-     *     endpoint property is missing.
+     *     If guacamole.properties cannot be parsed, or it authorization and
+     *     well-known endpoints are property is missing.
      */
     public URI getAuthorizationEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_AUTHORIZATION_ENDPOINT);
+        URI authorization_endpoint = environment.getProperty(OPENID_AUTHORIZATION_ENDPOINT);
+        authorization_endpoint = authorization_endpoint == null ? confWellKnown.getAuthorizationEndpoint() : authorization_endpoint;

Review Comment:
   This is a nice succinct line of code, but I don't know that it makes for terribly readable code. Also, there is a form of the `environment.getProperty()` call that lets you specify a default value, so you could really just combine this line with the above:
   ```
   URI authorization_endpoint = environment.getProperty(OPENID_AUTHORIZATION_ENDPOINT, confWellKnown.getAuthorizationEndpoint());
   ```



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.

Review Comment:
   -> `well-known endpoint properties are missing.`



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the reponse type of the OpenID service as configured with guacamole.properties.
+     *
+     * @return
+     *     The reponse type of the OpenID service, as configured with guacamole.properties. Can
+     *     be either 'id_token', 'token' or 'code'.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public OpenIDResponseType getResponseType() throws GuacamoleException {
+        return environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+    }
+
+    /**
+     * Returns true if the response type defines an implict flow
+     *
+     * @return
+     *     The whether implicit flow is used or not, as configured with guacamole.properties.

Review Comment:
   This should be something more like:
   ```
   true if implicit flow should be used, otherwise false.
   ```
   
   And the mention of guacamole.properties can be in the main body of the comment above.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -98,26 +107,36 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
                 .setExpectedAudience(confService.getClientID())
                 .setVerificationKeyResolver(resolver)
                 .build();
-
+                
+        /* Exchange code → token */
+        if (! confService.isImplicitFlow()) {

Review Comment:
   You can remove the space between the `!` and `confService`.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;
+    
+    /**
+     * Empty constructor of the class to populate data recovered from a OIDC
+     * well-known URL. The class will be populated on injection by Guice
+     */
+    public OpenIDWellKnown() { }
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "openid-well-known-endpoint"; }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    private URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.
+     */
+    public String getIssuer() {
+        return issuer;
+    }
+
+    /**
+     * Returns the authorization endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The authorization endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getAuthorizationEndpoint() {
+        return authorization_endpoint;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The token endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getTokenEndpoint() {
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the endpoint (URI) of the JWKS service which defines how
+     * received ID tokens (JWTs) shall be validated, as configured from
+     * the well-known endpoint.
+     *
+     * @return
+     *     The endpoint (URI) of the JWKS service which defines how received ID
+     *     tokens (JWTs) shall be validated, as configured from the
+     *     well-known endpoint.
+     */
+    public URI getJWKSEndpoint() {
+        return jwks_uri;
+    }
+
+    /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;
+
+    /*

Review Comment:
   This is missing the extra `*` that defines this as a JSDoc-style comment block.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -313,10 +397,15 @@ public URI getRedirectURI() throws GuacamoleException {
      *
      * @throws GuacamoleException
      *     If guacamole.properties cannot be parsed, or if the issuer property
-     *     is missing.
+     *     and well-known endpoints are property is missing.
      */
     public String getIssuer() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_ISSUER);
+        String issuer = environment.getProperty(OPENID_ISSUER);
+        issuer = issuer == null ? confWellKnown.getIssuer() : issuer;

Review Comment:
   Similar to the above in `getAuthorizationEndpoint()`, I'd suggest this line use the `getProperty()` call that uses `confWellKnown.getIssuer()` as the default value.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;

Review Comment:
   This can also be changed to make the well-known endpoint call the default value.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -313,10 +397,15 @@ public URI getRedirectURI() throws GuacamoleException {
      *
      * @throws GuacamoleException
      *     If guacamole.properties cannot be parsed, or if the issuer property
-     *     is missing.
+     *     and well-known endpoints are property is missing.

Review Comment:
   -> `and well-known endpoint properties are missing.`



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;

Review Comment:
   Also can use default value of `getProperty()`, here.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the reponse type of the OpenID service as configured with guacamole.properties.
+     *
+     * @return
+     *     The reponse type of the OpenID service, as configured with guacamole.properties. Can
+     *     be either 'id_token', 'token' or 'code'.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public OpenIDResponseType getResponseType() throws GuacamoleException {
+        return environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+    }
+
+    /**
+     * Returns true if the response type defines an implict flow
+     *
+     * @return
+     *     The whether implicit flow is used or not, as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public boolean isImplicitFlow() throws GuacamoleException {
+        OpenIDResponseType response_type = environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+        return response_type != OpenIDResponseType.CODE;
+    }
+
+    /**
+     * Returns the OIDC client secret used for toen validation, as configured

Review Comment:
   `toen` -> `token`



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the reponse type of the OpenID service as configured with guacamole.properties.
+     *
+     * @return
+     *     The reponse type of the OpenID service, as configured with guacamole.properties. Can
+     *     be either 'id_token', 'token' or 'code'.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public OpenIDResponseType getResponseType() throws GuacamoleException {
+        return environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+    }
+
+    /**
+     * Returns true if the response type defines an implict flow
+     *
+     * @return
+     *     The whether implicit flow is used or not, as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public boolean isImplicitFlow() throws GuacamoleException {
+        OpenIDResponseType response_type = environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+        return response_type != OpenIDResponseType.CODE;
+    }
+
+    /**
+     * Returns the OIDC client secret used for toen validation, as configured
+     * with guacamole.properties. This value is typically provided by the OIDC
+     * service when OIDC credentials are generated for your application, and
+     * may be null.
+     *
+     * @return
+     *     The client secret to use when communicating with the OIDC service,
+     *     as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public String getClientSecret() throws GuacamoleException {
+       return environment.getProperty(OPENID_CLIENT_SECRET);
+    }
+
+    /**
+     * Returns  a boolean value of whether "Proof Key for Code Exchange (PKCE)"

Review Comment:
   There's an extra space between `Returns` and `a`, here.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.

Review Comment:
   -> `and well-known endpoint properties are missing.`



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;
+    
+    /**
+     * Empty constructor of the class to populate data recovered from a OIDC
+     * well-known URL. The class will be populated on injection by Guice
+     */
+    public OpenIDWellKnown() { }
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "openid-well-known-endpoint"; }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    private URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);

Review Comment:
   Note that this call to `getProperty()` will *not* throw a `GuacamoleException` if the `OPENID_WELL_KNOWN_ENDPOINT` property is missing. It will return null. If you want the behavior you've described in the `@throws` block of the method documentation, you'll need to use `getRequiredProperty()`, instead.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the reponse type of the OpenID service as configured with guacamole.properties.
+     *
+     * @return
+     *     The reponse type of the OpenID service, as configured with guacamole.properties. Can
+     *     be either 'id_token', 'token' or 'code'.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public OpenIDResponseType getResponseType() throws GuacamoleException {
+        return environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+    }
+
+    /**
+     * Returns true if the response type defines an implict flow

Review Comment:
   ...otherwise false, as configured in guacamole.properties.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the reponse type of the OpenID service as configured with guacamole.properties.
+     *
+     * @return
+     *     The reponse type of the OpenID service, as configured with guacamole.properties. Can
+     *     be either 'id_token', 'token' or 'code'.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public OpenIDResponseType getResponseType() throws GuacamoleException {
+        return environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+    }
+
+    /**
+     * Returns true if the response type defines an implict flow
+     *
+     * @return
+     *     The whether implicit flow is used or not, as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public boolean isImplicitFlow() throws GuacamoleException {
+        OpenIDResponseType response_type = environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+        return response_type != OpenIDResponseType.CODE;
+    }
+
+    /**
+     * Returns the OIDC client secret used for toen validation, as configured
+     * with guacamole.properties. This value is typically provided by the OIDC
+     * service when OIDC credentials are generated for your application, and
+     * may be null.
+     *
+     * @return
+     *     The client secret to use when communicating with the OIDC service,
+     *     as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public String getClientSecret() throws GuacamoleException {
+       return environment.getProperty(OPENID_CLIENT_SECRET);
+    }
+
+    /**
+     * Returns  a boolean value of whether "Proof Key for Code Exchange (PKCE)"
+     * will be used, as configured with guacamole.properties. The choice of
+     * whether to use PKCE is up to you, but the OIDC service must support
+     * it. By default will be false.
+     *
+     * @return
+     *     The whether to use PKCE or not, as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public boolean isPKCERequired() throws GuacamoleException {
+        Boolean enabled = environment.getProperty(OPENID_PKCE_REQUIRED);
+        return enabled != null && enabled;

Review Comment:
   Two things:
   * I don't think there's any reason to use a `Boolean` here when you're just returning a `boolean`.
   * Again, make use of the default value option - if false is the default, this can be simplified to:
   ```
   return environment.getProperty(OPENID_PKCE_REQUIRED, false);
   ```



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -330,11 +419,117 @@ public String getIssuer() throws GuacamoleException {
      *     guacamole.properties.
      *
      * @throws GuacamoleException
-     *     If guacamole.properties cannot be parsed, or if the JWKS endpoint
-     *     property is missing.
+     *     If guacamole.properties cannot be parsed, or if the JWKS and
+     *     well-known endpoints are property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token and
+     *     well-known endpoints are property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the reponse type of the OpenID service as configured with guacamole.properties.
+     *
+     * @return
+     *     The reponse type of the OpenID service, as configured with guacamole.properties. Can
+     *     be either 'id_token', 'token' or 'code'.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public OpenIDResponseType getResponseType() throws GuacamoleException {
+        return environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+    }
+
+    /**
+     * Returns true if the response type defines an implict flow
+     *
+     * @return
+     *     The whether implicit flow is used or not, as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public boolean isImplicitFlow() throws GuacamoleException {
+        OpenIDResponseType response_type = environment.getProperty(OPENID_RESPONSE_TYPE, DEFAULT_RESPONSE_TYPE);
+        return response_type != OpenIDResponseType.CODE;
+    }
+
+    /**
+     * Returns the OIDC client secret used for toen validation, as configured
+     * with guacamole.properties. This value is typically provided by the OIDC
+     * service when OIDC credentials are generated for your application, and
+     * may be null.
+     *
+     * @return
+     *     The client secret to use when communicating with the OIDC service,
+     *     as configured with guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed.
+     */
+    public String getClientSecret() throws GuacamoleException {
+       return environment.getProperty(OPENID_CLIENT_SECRET);
+    }
+
+    /**
+     * Returns  a boolean value of whether "Proof Key for Code Exchange (PKCE)"
+     * will be used, as configured with guacamole.properties. The choice of
+     * whether to use PKCE is up to you, but the OIDC service must support
+     * it. By default will be false.
+     *
+     * @return
+     *     The whether to use PKCE or not, as configured with guacamole.properties.

Review Comment:
   Similar to above, this should be something more like:
   ```
   true if PKCE should be used, otherwise false.
   ```



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDResponseType.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import org.apache.guacamole.properties.EnumGuacamoleProperty.PropertyValue;
+
+/**
+ * This enum represents the valid OIDC reponse types that can be used
+ */
+ public enum OpenIDResponseType {
+     /*
+      * Response type "id_token" used for implciit flow as specified in the OpenID standard
+      */
+     @PropertyValue("id_token")
+     ID_TOKEN("id_token"),
+     
+     /* Response type "token" used for implicit flow by certain Identity Providers, notably
+      * AWS Cognito. This corresponds to the official OIDC response_type "id_token token" 
+      * that returns both the "id_token" and "access_token" parameters
+      */
+     @PropertyValue("token")
+     TOKEN("token"),
+     
+     /**
+      * Response type "code" used for code flow authentication
+      */
+     @PropertyValue("code")
+     CODE("code");
+     
+     /*
+      * The string value of the response type used
+      */
+     public final String STRING_VALUE;

Review Comment:
   The comment blocks in this section each use a slightly different style. The style used elsewhere in the code is as follows:
   ```
   /**
    * Documentation of the enum type, variable, etc.
    */
   ```



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;

Review Comment:
   Two issues, here:
   * I'm not sure these should be `static`? I know this is a `Singleton` class, but you're still expecting that these are private and would be accessed via the get methods defined below, so I think they should not be static?
   * If they're static, the generally-accepted style is `UPPER_CASE_WITH_UNDERSCORES`. If they're not static, the generally-accepted style used elsewhere in the code is `camelCaseWithoutUnderscores`.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -70,20 +73,26 @@ public class TokenValidationService {
     private NonceService nonceService;
 
     /**
-     * Validates the given ID token, returning the JwtClaims contained therein.
-     * If the ID token is invalid, null is returned.
+     * Validates the given ID token, using implicit flow. Also validates codes,
+     * exchanging them for id_tokens before validation. If the id_token or
+     * code is invalid, null is returned, otherwise the JwtClaims in the
+     * id_token are returned.
      *
      * @param token
-     *     The ID token to validate.
+     *     The ID token to validate if implicit flow or the code to exchange for
+     *     an id_token and then validate.
+     *
+     * @param verifier
+     *     A PKCE verifier or null if not used. Only used with code flow
      *
      * @return
-     *     The JWT claims contained within the given ID token if it passes tests,
-     *     or null if the token is not valid.
+     *     The JWT claims contained within the id_token if it passes tests,
+     *     or null if the id_token is not valid.

Review Comment:
   Would it make more sense, here to throw an exception instead of returning `null` if the id_token is invalid? Presumably an invalid id_token constitutes an authentication failure, which should then be passed back to the user, perhaps using `GuacamoleInvalidCredentialsException`? Or is there some reason within the code flow that `null` is preferred for this?



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/PKCEUtil.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+
+/**
+ * Utility class for generating PKCE parameters.
+ *
+ * Supports:
+ *   - code_verifier (random Base64URL)
+ *   - code_challenge (S256)
+ */
+public final class PKCEUtil {
+    /**
+     * Get the verifier data from a cryptographically secure random source
+     */
+    private static final SecureRandom RANDOM = new SecureRandom();
+
+    /*
+     * Class to create PKCE challenges and verifiers. This class should not be instantiated
+     */
+    private PKCEUtil() {}
+
+    /**
+     * Generates a high-entropy PKCE code_verifier.
+     *
+     * @return
+     *      A 256bit or 64 byte random Base64 URL encode string
+     */
+    public static String generateCodeVerifier() {
+        byte[] bytes = new byte[64];
+        RANDOM.nextBytes(bytes);
+        return base64Url(bytes);
+    }
+
+    /**
+     * Computes the PKCE code_challenge = BASE64URL(SHA256(code_verifier)).
+     *
+     * @param String verifier
+     *      A string containing the S256 verifier calculated bu generateCodeVerifier
+     *
+     * @return
+     *      The generated S256 code challenge used for the PKCE request encoded 
+     *      in Base64 URL format.
+     */
+    public static String generateCodeChallenge(String verifier) throws Exception {
+        MessageDigest sha = MessageDigest.getInstance("SHA-256");
+        byte[] hash = sha.digest(verifier.getBytes("US-ASCII"));
+        return base64Url(hash);
+    }
+
+    /**
+     * Base64URL encoding without padding.

Review Comment:
   This should be a little more descriptive...
   ```
   A method that Base64URL-encodes a provided byte array without padding...
   ```



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;
+    
+    /**
+     * Empty constructor of the class to populate data recovered from a OIDC
+     * well-known URL. The class will be populated on injection by Guice
+     */
+    public OpenIDWellKnown() { }
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "openid-well-known-endpoint"; }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    private URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.
+     */
+    public String getIssuer() {
+        return issuer;
+    }
+
+    /**
+     * Returns the authorization endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The authorization endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getAuthorizationEndpoint() {
+        return authorization_endpoint;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The token endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getTokenEndpoint() {
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the endpoint (URI) of the JWKS service which defines how
+     * received ID tokens (JWTs) shall be validated, as configured from
+     * the well-known endpoint.
+     *
+     * @return
+     *     The endpoint (URI) of the JWKS service which defines how received ID
+     *     tokens (JWTs) shall be validated, as configured from the
+     *     well-known endpoint.
+     */
+    public URI getJWKSEndpoint() {
+        return jwks_uri;
+    }
+
+    /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;

Review Comment:
   This injected variable should be at the top with the other class variables, before any methods are defined.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;
+    
+    /**
+     * Empty constructor of the class to populate data recovered from a OIDC
+     * well-known URL. The class will be populated on injection by Guice
+     */
+    public OpenIDWellKnown() { }
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "openid-well-known-endpoint"; }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    private URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.

Review Comment:
   These comments should be consistent about using `well-known` vs. `well_known`. I think `well-known` is the way to go.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationSession.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid;
+
+import org.apache.guacamole.net.auth.AuthenticationSession;
+
+/**
+ * Representation of an in-progress OpenID authentication attempt.
+ */
+

Review Comment:
   No blank line needed, here.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationSession.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid;
+
+import org.apache.guacamole.net.auth.AuthenticationSession;
+
+/**
+ * Representation of an in-progress OpenID authentication attempt.
+ */
+public class OpenIDAuthenticationSession extends AuthenticationSession {
+    /**

Review Comment:
   There still should be a blank line above this one.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -131,6 +150,73 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
         return null;
     }
 
+    /**
+     * URLEncodes a key/value pair
+     *
+     * @param key
+     *     The key to encode
+     *
+     * @param value
+     *     The value to encode
+     *
+     * @return
+     *     The urlencoded kay/value pair
+     */
+     private String urlencode(String key, String value) {
+         StringBuilder builder = new StringBuilder();
+         return builder.append(URLEncoder.encode(key, StandardCharsets.UTF_8))
+                       .append("=")
+                       .append(URLEncoder.encode(value, StandardCharsets.UTF_8))
+                       .toString();
+     }
+
+    /**
+     * Exchanges the authorization code for tokens.
+     *
+     * @param code
+     *     The authorization code received from the IdP.
+     *
+     * @param codeVerifier
+     *     The PKCE verifier (or null if PKCE is disabled).
+     *
+     * @return
+     *     The token string returned.
+     *
+     * @throws GuacamoleException
+     *     If a valid token is not returned.
+     */
+    private String exchangeCode(String code, String verifier) throws GuacamoleException {
+
+        try {
+            StringBuilder bodyBuilder = new StringBuilder();
+            bodyBuilder.append(urlencode("grant_type", "authorization_code")).append("&");
+            bodyBuilder.append(urlencode("code", code)).append("&");
+            bodyBuilder.append(urlencode("redirect_uri", confService.getRedirectURI().toString())).append("&");
+            bodyBuilder.append(urlencode("scope", confService.getScope())).append("&");
+            bodyBuilder.append(urlencode("client_id", confService.getClientID()));
+
+            String clientSecret = confService.getClientSecret();
+            if (clientSecret != null && !clientSecret.trim().isEmpty()) {
+                bodyBuilder.append("&").append(urlencode("client_secret", clientSecret));
+            }
+
+            if (confService.isPKCERequired()) {
+                bodyBuilder.append("&").append(urlencode("code_verifier", verifier));
+            }
+
+            Map<String,Object> json = 
+                    JsonUrlReader.fetch("POST", confService.getTokenEndpoint(),
+                                        bodyBuilder.toString());
+
+            return (String) json.get("id_token");
+
+        }
+        catch (Exception e) {
+            logger.info("Rejected invalid OpenID code exchange: {}", e.getMessage(), e);
+        }

Review Comment:
   Catching `Exception` here is probably not a good idea:
   * This method `throws GuacamoleException`, but if you catch the overall `Exception` class, here, that will never actually happen, and this method will just return null every time. I suspect we actually want the `GuacamoleException` exceptions to be passed on to the callers.
   * By catching `Exception` this makes the very generic logger message here both misleading and unhelpful. The OpenID code exchange isn't necessarily rejected, here, as it states - it could be that a property wasn't properly configured or there was an issue retrieving it. You are passing through the underlying exception and message, which is good, but the initial log message doesn't really help.
   * Also, `logger.info()` is probably not the correct level, here - this constitutes an error, not an informational message, so it should be `logger.error()`.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I think there are multiple things to think about:
   * Risk is certainly one of them, though it's a bit of a trade. You either write your own functions and risk that you've done something bad and it will have to be corrected, or you rely on someone else. There's risk either way.
   * Maintainability is more what I had in mind - if someone else already has a class and set of functions for reading JSON from a URL, and they're actively maintaining it, it allows the Guacamole project to use that and not have to maintain a set of classes for reading JSON URLs, which is not the goal of this project. It's why we aren't writing our own JDBC drivers, SAML client, OpenID client, LDAP client, etc.
   
   To your point, as long as the Spring OAuth2 code is licensed in a way that allows us to leverage it, I have no problem with considering using a different OAuth2 client or some code from that. I don't think there's anything specific that ties Guacamole to the currently-implemented OpenID client.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -110,6 +120,66 @@ public class ConfigurationService {
 
     };
 
+    /**
+     * The token endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_TOKEN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-token-endpoint";
+        }
+    };
+
+    /**
+     * The reponse type of the OpenID service.
+     */
+    private static final EnumGuacamoleProperty<OpenIDResponseType> OPENID_RESPONSE_TYPE =
+            new EnumGuacamoleProperty<OpenIDResponseType>(OpenIDResponseType.class) {
+
+        @Override
+        public String getName() { return "openid-response-type"; }
+
+    };
+
+    /**
+     * OIDC client secret which should be submitted to the OIDC service when
+     * validating tokens with code flow
+     */
+    private static final StringGuacamoleProperty OPENID_CLIENT_SECRET =
+            new StringGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-client-secret";
+        }
+    };
+
+    /**
+     * True if "Proof Key for Code Exchange" (PKCE) must be used.
+     */
+    private static final BooleanGuacamoleProperty OPENID_PKCE_REQUIRED =
+            new BooleanGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-pkce-required";
+        }
+    };
+
+    /**
+     * The maximum amount of time to allow for an in-progress OpenID
+     * authentication attempt to be completed, in minutes. A user that takes
+     * longer than this amount of time to complete authentication with their
+     * identity provider will be redirected back to the identity provider to
+     * try again.
+     */
+    private static final IntegerGuacamoleProperty OPENID_AUTH_TIMEOUT =
+            new IntegerGuacamoleProperty() {
+        @Override
+        public String getName() { return "openid-auth-timeout"; }
+
+    };
+
+

Review Comment:
   There are a few more minor tweaks that should be made, here - adding some newlines after the `getName()` overrides in a couple of places.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178537076


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -131,6 +150,73 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
         return null;
     }
 
+    /**
+     * URLEncodes a key/value pair
+     *
+     * @param key
+     *     The key to encode
+     *
+     * @param value
+     *     The value to encode
+     *
+     * @return
+     *     The urlencoded kay/value pair
+     */
+     private String urlencode(String key, String value) {
+         StringBuilder builder = new StringBuilder();
+         return builder.append(URLEncoder.encode(key, StandardCharsets.UTF_8))
+                       .append("=")
+                       .append(URLEncoder.encode(value, StandardCharsets.UTF_8))
+                       .toString();
+     }
+
+    /**
+     * Exchanges the authorization code for tokens.
+     *
+     * @param code
+     *     The authorization code received from the IdP.
+     *
+     * @param codeVerifier
+     *     The PKCE verifier (or null if PKCE is disabled).
+     *
+     * @return
+     *     The token string returned.
+     *
+     * @throws GuacamoleException
+     *     If a valid token is not returned.
+     */
+    private String exchangeCode(String code, String verifier) throws GuacamoleException {
+
+        try {
+            StringBuilder bodyBuilder = new StringBuilder();
+            bodyBuilder.append(urlencode("grant_type", "authorization_code")).append("&");
+            bodyBuilder.append(urlencode("code", code)).append("&");
+            bodyBuilder.append(urlencode("redirect_uri", confService.getRedirectURI().toString())).append("&");
+            bodyBuilder.append(urlencode("scope", confService.getScope())).append("&");
+            bodyBuilder.append(urlencode("client_id", confService.getClientID()));
+
+            String clientSecret = confService.getClientSecret();
+            if (clientSecret != null && !clientSecret.trim().isEmpty()) {
+                bodyBuilder.append("&").append(urlencode("client_secret", clientSecret));
+            }
+
+            if (confService.isPKCERequired()) {
+                bodyBuilder.append("&").append(urlencode("code_verifier", verifier));
+            }
+
+            Map<String,Object> json = 
+                    JsonUrlReader.fetch("POST", confService.getTokenEndpoint(),
+                                        bodyBuilder.toString());
+
+            return (String) json.get("id_token");
+
+        }
+        catch (Exception e) {
+            logger.info("Rejected invalid OpenID code exchange: {}", e.getMessage(), e);
+        }

Review Comment:
   If "org.springframework.security.oauth2" is used this function needs to be rethought.. Yeah I shouldn't catch all exceptions, only the one that represents a failure to exchange a code for a token.
   
   I'll revisit this after looking at using "org.springframework.security.oauth2"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4222878163

   > Thinking about it, I still have one issue. Guacamole displays the data returned by keycloak in the navigation bar, including the "code" field for code flow... If the user refreshs the page, as they often do if there is a problem, authenticateUser will be called again with the stale code and this will be posted to the identity provider. The identity provider detects this as a code "reuse" and probably an attack. This is bad
   
   Forget it. I'm an idiot.. The existing js code converts the query parameters into a URL fragment so they won't be posted to the server on a refresh.. The code as it stands is ok.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062393808


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {
+            throw new GuacamoleException("JsonUrlReader : Missing URL");
+        }
+        
+        try {
+            // Open connection, using HttpURLConnection
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+
+            conn.setRequestMethod(method);
+            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+
+            if (! method.equalsIgnoreCase("GET")) {

Review Comment:
   I thought my JsonUrlReader might end up used elsewhere and the case insensitive compare was just a bit of future idiot proofing. As you prefer



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178570925


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;

Review Comment:
   I added a CountDownLatch to this class and blocked the getters till the call to the Well Known endpoint suceeds, fails or the endpoint is absent. So resolved



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178546039


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;
+    
+    /**
+     * Empty constructor of the class to populate data recovered from a OIDC
+     * well-known URL. The class will be populated on injection by Guice
+     */
+    public OpenIDWellKnown() { }
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "openid-well-known-endpoint"; }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    private URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);

Review Comment:
   Hang on.. Looking at getProperty n Environment.java it throws a GuacamoleException ! So not treating this one; or at least only the comment ;-)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - No introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find and apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only
   needed a couple of values. 
   
   The slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the htpp post/get operations are one off each time.
   
   I've updated the code using httpClient and included asynchronous operation to release control back the the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regrets is the right time to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069571725


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    /**
+     * Class to GET and POST to a URL and read the returned JSON. This class should
+     * not be instantiated.
+     */
+    private JsonUrlReader() {}
+
+    /**
+     * Method to POST or GET to a URL and recover the JSON in the form of a Map
+     *
+     * @param String method
+     *      The htpp method to use. Should be "GET", "POST" or "PATCH".
+     *
+     * @param URI uri
+     *      A URI value giving the address where to recover the JSON
+     *
+     * @param String body
+     *      A pre-encoded body string to be sent to the address if the method is
+     *      "POST" or "PATCH". Ignored if the method is "GET".
+     *
+     * @return
+     *      A Map<String,Object> containing the decoded json values.
+     */
+    public static Map<String, Object> fetch(String method, URI uri, String body) throws IOException {
+        if (uri == null || uri.toString().isEmpty()) {
+            throw new IOException("JsonUrlReader: Missing URL");
+        }
+
+        try {
+            HttpClient client = HttpClient.newHttpClient();
+            HttpRequest request = HttpRequest.newBuilder()
+                    .uri(uri)
+                    .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
+                    .method(method,

Review Comment:
   On my machine using "GET" here doesn't crash here with an IllegalArgumentException though the documentation makes me think it should. Should I protect this in a if/else block ?
   
   ```
   .method(method, (method == "GET" ? HttpRequest.BodyPublishers.NoBody() :  HttpRequest.BodyPublishers.ofString(body == null ? "" : body, StandardCharsets.UTF_8)))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062402827


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {
+            throw new GuacamoleException("JsonUrlReader : Missing URL");

Review Comment:
   You’re of cause right. It should probably return an IOException



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062407123


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {

Review Comment:
   Good point. I’ll fix it when I’m not on my phone 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3098735410


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   Hi @necouchman, thinking again about what you said above I might have misunderstood your ultimate goal. Do you mean you want to "outsource" potentially risky functions to a known and trusted source ? 
   
   If that is the case rather than do this at the Url2Json level, we could do it directly wiith the Spring IDC/OAuth2 code "org.springframework.security.oauth2". This would be a relatively easy change and comes with the advantage of the security risks in the OIDC code are delegated to Spring ;-) ... Though if we do that for the code flow authorization in OIDC, then the existing Jwt claims verification code should be replaced with the equivalent code in Spring.
   
   Frankly I have no hangups about the desired implementation , and I'll reimplement it however you want 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178500945


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;

Review Comment:
   Sure if its Singleton making them static is redundant. I removed the "static"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178546039


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;
+    
+    /**
+     * Empty constructor of the class to populate data recovered from a OIDC
+     * well-known URL. The class will be populated on injection by Guice
+     */
+    public OpenIDWellKnown() { }
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "openid-well-known-endpoint"; }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    private URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);

Review Comment:
   Hang on.. Looking at getProperty n Environment.java it throws a GuacamoleException ! So not treating this one



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069571725


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    /**
+     * Class to GET and POST to a URL and read the returned JSON. This class should
+     * not be instantiated.
+     */
+    private JsonUrlReader() {}
+
+    /**
+     * Method to POST or GET to a URL and recover the JSON in the form of a Map
+     *
+     * @param String method
+     *      The htpp method to use. Should be "GET", "POST" or "PATCH".
+     *
+     * @param URI uri
+     *      A URI value giving the address where to recover the JSON
+     *
+     * @param String body
+     *      A pre-encoded body string to be sent to the address if the method is
+     *      "POST" or "PATCH". Ignored if the method is "GET".
+     *
+     * @return
+     *      A Map<String,Object> containing the decoded json values.
+     */
+    public static Map<String, Object> fetch(String method, URI uri, String body) throws IOException {
+        if (uri == null || uri.toString().isEmpty()) {
+            throw new IOException("JsonUrlReader: Missing URL");
+        }
+
+        try {
+            HttpClient client = HttpClient.newHttpClient();
+            HttpRequest request = HttpRequest.newBuilder()
+                    .uri(uri)
+                    .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
+                    .method(method,

Review Comment:
   On my machine using "GET" here doesn't crash here with an IllegalArgumentException though the documentation makes me think it should. Should I protect this in a if/else block ? Or is 
   
   ```
   .method(method, (method == "GET" ? HttpRequest.BodyPublishers.NoBody() :  HttpRequest.BodyPublishers.ofString(body == null ? "" : body, StandardCharsets.UTF_8)))
   ```
   
   just too ugly ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4506781788

   > Thanks for continuing to work on this @adb014. I've got the next round of requested changes - several more style issues that need to be addressed to make sure that the style conforms to the generally-accepted and used style throughout the code, along with some exception-handling issues and a couple of other minor things.
   > 
   > Also, your commit messages need some tweaks:
   > 
   > * Make sure they are descriptive of the changes.
   > * Make sure they are tagged with the `GUACAMOLE-2258:` prefix.
   
   Aren't all the commits warpped up into a single commit against the guacamole-client repo when the PR is accepted with a seperate description ?  I've just given my commits a bit of description so that I can personally find the right commit if needed. If the commit messages are all imported in to guacamole, yes I understand that they'll need to be more descriptive and tagged


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "necouchman (via GitHub)" <gi...@apache.org>.
necouchman commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4507589426

   > Aren't all the commits warpped up into a single commit against the [guacamole-client](https://issues.apache.org/jira/browse/GUACAMOLE-client) repo when the PR is accepted with a seperate description ? 
   
   No - a merge commit is added, but each of your commits will still be there, and thus they need to be descriptive, not just to you, but to the entire community.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062223129


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   If I only wanted the JsonUrlReader class for the well-known endpoint, you’d be right. I also use it in the exchange of a code for a token, which must use a POST with the parameters in the body. With a quick look around not finding something appropriate I implemented it myself. 
   
   If you have an idea that can read json from a url with both POST and GET, I’ll get rid of this function. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outbound HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - don’t introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.net.httpUrlConnection is a bit old and ugly, but I couldn't find any apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only needed a couple of values. 
   
   The slightly more modern  java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the http post/get operations are one off each time. Though using org.apache.http.impl.client.HttpClient is an option that might be attractive as it supplies functions to more cleanly treat the posted form data. 
   
   I've updated the code using java.net.http.httpClient and included asynchronous operation to release control back to the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regret is the right thing to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4232339071

   @necouchman anticipating that you’ll want a patch to the manual, I started think what is needed but ran into a question. At the moment the configuration is split into required and optional configuration options. However, with the proposed changes only openid-client-id and openid-redirect-uri. The other existing « required » options can either remain required or be replaced with openid-well-known-endpoint. 
   
   To me the split required/optional make less sense now. What I propose is a discussion implicit flow versus code flow and another section on the well-known endpoint and the fact it can replace up to 4 (3 with implicit flow) other required configuration options. I then propose to combine the existing required and optional sections into a single section. 
   
   How do you want this addressed ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "necouchman (via GitHub)" <gi...@apache.org>.
necouchman commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3064072529


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {
+            throw new GuacamoleException("JsonUrlReader : Missing URL");
+        }
+        
+        try {
+            // Open connection, using HttpURLConnection
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+
+            conn.setRequestMethod(method);
+            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+
+            if (! method.equalsIgnoreCase("GET")) {

Review Comment:
   It was not intended to be a rhetorical question/remark - I was legitimately asking if there are situations where those requests come back in varying cases. Just because I've never seen it that way doesn't mean that it doesn't happen :-).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178430086


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationSession.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid;
+
+import org.apache.guacamole.net.auth.AuthenticationSession;
+
+/**
+ * Representation of an in-progress OpenID authentication attempt.
+ */
+public class OpenIDAuthenticationSession extends AuthenticationSession {
+    /**

Review Comment:
   I think this is a display issue, in the git there is a line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178837656


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   Ok I wrote a version based on "org.springframework.security.oauth2" and here are the list of new depedencies identified by their lack of license, even after exclusion of the maximum number of transitive dependencies 
   
   ```
   ERROR: License information missing for org.springframework.security:spring-security-oauth2-jose:jar:6.2.4
   ERROR: License information missing for org.springframework.security:spring-security-core:jar:6.2.4
   ERROR: License information missing for org.springframework.security:spring-security-crypto:jar:6.2.4
   ERROR: License information missing for org.springframework:spring-aop:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-context:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-expression:jar:6.1.6
   ERROR: License information missing for org.springframework.security:spring-security-oauth2-core:jar:6.2.4
   ERROR: License information missing for org.springframework:spring-core:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-jcl:jar:6.1.6
   ERROR: License information missing for com.nimbusds:nimbus-jose-jwt:jar:9.24.4
   ERROR: License information missing for com.github.stephenc.jcip:jcip-annotations:jar:1.0-1
   ERROR: License information missing for org.springframework.security:spring-security-oauth2-client:jar:6.2.4
   ERROR: License information missing for org.springframework.security:spring-security-web:jar:6.2.4
   ERROR: License information missing for com.nimbusds:oauth2-oidc-sdk:jar:9.43.3
   ERROR: License information missing for com.nimbusds:content-type:jar:2.2
   ERROR: License information missing for net.minidev:json-smart:jar:2.4.10
   ERROR: License information missing for net.minidev:accessors-smart:jar:2.4.9
   ERROR: License information missing for org.ow2.asm:asm:jar:9.3
   ERROR: License information missing for com.nimbusds:lang-tag:jar:1.7
   ERROR: License information missing for org.springframework:spring-web:jar:6.1.6
   ERROR: License information missing for org.springframework:spring-beans:jar:6.1.6
   ```
   
   Is it a problem if pull in that many additional dependencies ? The springframwork OAuth2 code needs springframework core to be at least version 4 and higher if possible. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178852112


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   As far as I can see there is no way to get rid of an httpclient in some form without upgrading springframework core. What do you want to do ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062381711


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+     private static String issuer = null;
+
+    /**
+     * The detected authorization edpoint
+     */
+     private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token edpoint
+     */
+     private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+     private static URI jwks_uri = null;
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-well-known-endpoint";
+        }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the authorization
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }

Review Comment:
   See comment for the getter in confService. It’s as you prefer. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - No introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find and apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only
   needed a couple of values. 
   
   The slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the htpp post/get operations are one off each time.
   
   I've updated the code using httpClient and included asynchronous operation to release control back the the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regrets is the right time to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069571725


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    /**
+     * Class to GET and POST to a URL and read the returned JSON. This class should
+     * not be instantiated.
+     */
+    private JsonUrlReader() {}
+
+    /**
+     * Method to POST or GET to a URL and recover the JSON in the form of a Map
+     *
+     * @param String method
+     *      The htpp method to use. Should be "GET", "POST" or "PATCH".
+     *
+     * @param URI uri
+     *      A URI value giving the address where to recover the JSON
+     *
+     * @param String body
+     *      A pre-encoded body string to be sent to the address if the method is
+     *      "POST" or "PATCH". Ignored if the method is "GET".
+     *
+     * @return
+     *      A Map<String,Object> containing the decoded json values.
+     */
+    public static Map<String, Object> fetch(String method, URI uri, String body) throws IOException {
+        if (uri == null || uri.toString().isEmpty()) {
+            throw new IOException("JsonUrlReader: Missing URL");
+        }
+
+        try {
+            HttpClient client = HttpClient.newHttpClient();
+            HttpRequest request = HttpRequest.newBuilder()
+                    .uri(uri)
+                    .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
+                    .method(method,

Review Comment:
   On my machine using "GET" here doesn't crash here with an IllegalArgumentException though the documentation makes me think it should. Should I protect this in a if/else block ?
   
   ```
   .method(method, (method == "GET" ? HttpRequest.BodPublishers.NoBody() :  HttpRequest.BodyPublishers.ofString(body == null ? "" : body, StandardCharsets.UTF_8)))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4221018067

   I’m on my phone at the moment, so will look at this later. Though I tested with 7 scenarios 
   
   - id_token + well-known 
   - id_token + manual endpoint and issuer 
   - token + well-known 
   - token + manual endpoint and issuer 
   - code + well-known 
   - code + manual endpoint and issuer 
   - code + manual endpoint and issuer + pkce
   
   The PKCE path seemed sufficiently independent that it only needed testing once. All of these were tested against a local keycloak only. 
   
   If the well-known endpoint is not given then the calls like confService.getIssuer() will see the manual value in priority and return it. If only the well-known endpoint is set, then the confWellKnown.getIssuer() method is called from within confService.gerIssuer(). This call might fail initially if the well-known data is not available yet. I tested in docker and the guacamole container starts faster than keycloak 😆


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062167479


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -131,6 +138,119 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
         return null;
     }
 
+    /**
+     * Validates the given ID token, using code flow, returning the JwtClaims
+     * contained therein. If the ID token is invalid, null is returned.
+     *
+     * @param code
+     *     The code to validate and receive the id_token.
+     *
+     * @param verifier
+     *     A PKCE verifier or null if not used.
+     *
+     * @return
+     *     The JWT claims contained within the given ID token if it passes tests,
+     *     or null if the token is not valid.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties could not be parsed.
+     */
+    public JwtClaims validateCode(String code, String verifier) throws GuacamoleException {
+        // Validating the token requires a JWKS key resolver
+        HttpsJwks jwks = new HttpsJwks(confService.getJWKSEndpoint().toString());
+        HttpsJwksVerificationKeyResolver resolver = new HttpsJwksVerificationKeyResolver(jwks);
+
+        /* Exchange code → token */
+        String token = exchangeCode(code, verifier);
+
+        // Create JWT consumer for validating received token
+        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
+                .setRequireExpirationTime()
+                .setMaxFutureValidityInMinutes(confService.getMaxTokenValidity())
+                .setAllowedClockSkewInSeconds(confService.getAllowedClockSkew())
+                .setRequireSubject()
+                .setExpectedIssuer(confService.getIssuer())
+                .setExpectedAudience(confService.getClientID())
+                .setVerificationKeyResolver(resolver)
+                .build();
+
+        try {
+            // Validate JWT
+            return jwtConsumer.processToClaims(token);
+        }
+        // Log any failures to validate/parse the JWT
+        catch (InvalidJwtException e) {
+            logger.info("Rejected invalid OpenID token: {}", e.getMessage(), e);
+        }
+
+        return null;
+    }

Review Comment:
   There is a nonce in the existing method in the call to jwtConsumer. Treating that with an if/then in the jwtConsumerBuilder seemed that I end up making the code sufficiently different that a new validateToken method was better. Pretty much a matter of choice. Ok I,ll dedup it. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178509216


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;

Review Comment:
   Though  I've noticed a race condition in OpenIDWellKnown.java.. It's possible to call configService.getAuthorizationEndpoint() and the other getters that depend on the Well Known endpoint before OpenIDWellKnown.init() has finished setting its variables. It this case the module initialization completely fails!! It depends on Guice for when things are injected...
   
   At this point I think the getters in OpenIDWellKnown should block until the init function has completed, failed or if there is non WellKnown endpoint set. I'll fix this and propose a modification soon



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178538943


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+    private static String issuer = null;
+
+    /**
+     * The detected authorization endpoint
+     */
+    private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token endpoint
+     */
+    private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+    private static URI jwks_uri = null;
+    
+    /**
+     * Empty constructor of the class to populate data recovered from a OIDC
+     * well-known URL. The class will be populated on injection by Guice
+     */
+    public OpenIDWellKnown() { }
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+
+        @Override
+        public String getName() { return "openid-well-known-endpoint"; }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    private URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);

Review Comment:
   It can be null, so it shouldn't throw an exception



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4518776159

   Looking at the CI build failure there is an error
   
   ```
   #20 49.15 [INFO] 02 05 2026 12:26:17.271:INFO [launcher]: Starting browser Firefox
   #20 49.15 [INFO] 02 05 2026 12:26:17.279:ERROR [launcher]: Cannot start Firefox
   #20 49.15 [INFO] 	
   #20 49.15 [INFO] Command '/usr/bin/firefox' requires the firefox snap to be installed.
   #20 49.15 [INFO] Please install it with:
   #20 49.15 [INFO] 
   #20 49.15 [INFO] snap install firefox
   #20 49.15 [INFO] 
   #20 49.15 [INFO] 
   #20 49.15 [INFO] 02 05 2026 12:26:17.279:ERROR [launcher]: Firefox stdout: 
   #20 49.15 [INFO] 02 05 2026 12:26:17.279:ERROR [launcher]: Firefox stderr: 
   ```
   
   in the build of guacamole-common-js. I rebased against the latest main branch and tested again and it build here. Can you relaunch the workflow, as this looks like the build problem is not with my code ? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "necouchman (via GitHub)" <gi...@apache.org>.
necouchman commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4627350842

   > From what I understand in my other PR this should be rebased against staging/1.6.1. However, I didn't create a personal branch for these change and so as far as I can see any forced push is going to mess up this PR...
   > 
   > @necouchman can to resolve any outsatnding issues you have with this PR, I'll correct for the requested changes and after rebase against staging/1.6.1 and generate a new PR
   
   I believe this should stay based against the `main` branch - it's enough of a "feature" change, and a pretty large one at that, that I think it should be in the 1.7.0 release and not in a patch release.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4217751935

   Looking at the discussion in #517, I finally decided to add the well-known endpoint and an enum for the response_type to limit the values allowed. Given this it was also easy to add the use of "token" response_types as discussed in #517 for AWS Cognito. 
   
   A minimal guacamole.properties can then be
   
   ```
   openid-response-type: id_token | token | code
   openid-well-known-endpoint: https://identity-provider/well-known
   openid-token-endpoint:  https://identity-provider/token
   openid-client-id: my-client-id
   openid-client-secret: my-client-secret | null
   openid-pkce-required: true | false
   openid-redirect-uri: https://example.net/guacamole
   ```
   
   Can't see anything else to add to this patch. Can someone review it ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "necouchman (via GitHub)" <gi...@apache.org>.
necouchman commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3061614236


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -20,17 +20,24 @@
 package org.apache.guacamole.auth.openid.token;
 
 import com.google.inject.Inject;
+import java.net.URLEncoder;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+

Review Comment:
   Please remove this additional blank line.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   The Apache Commons IO project has some classes that might already do this. Maybe it would be better to use one of those than to re-invent it?
   
   https://www.baeldung.com/java-read-json-from-url



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+     private static String issuer = null;
+
+    /**
+     * The detected authorization edpoint
+     */
+     private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token edpoint
+     */
+     private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+     private static URI jwks_uri = null;
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-well-known-endpoint";
+        }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the authorization
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.
+     */
+    public String getIssuer() {
+        return issuer;
+    }
+
+    /**
+     * Returns the authorization endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The authorization endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getAuthorizationEndpoint() {
+        return authorization_endpoint;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The token endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getTokenEndpoint() {
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the endpoint (URI) of the JWKS service which defines how
+     * received ID tokens (JWTs) shall be validated, as configured from
+     * the well-known endpoint.
+     *
+     * @return
+     *     The endpoint (URI) of the JWKS service which defines how received ID
+     *     tokens (JWTs) shall be validated, as configured from the
+     *     well-known endpoint.
+     */
+    public URI getJWKSEndpoint() {
+        return jwks_uri;
+    }
+
+    /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;
+
+    /*
+     * Creates an OpenIDWellKnown class that reads the json from an OIDC
+     * well-known endpoint and saves these values for later use. Use Guice
+     * to ensure environment exists before initializing.
+     */
+    public OpenIDWellKnown() {
+    }

Review Comment:
   Having a variable and a constructor this far down, while not explicitly violating any style guideline, is a bit unconventional and not how we tend to do things in the existing code base. The order tends to be (more or less): variables, constructors, and then methods.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationProviderModule.java:
##########
@@ -42,7 +45,7 @@ protected void configure() {
         bind(ConfigurationService.class);
         bind(NonceService.class).in(Scopes.SINGLETON);
         bind(TokenValidationService.class);
-        
+        bind(OpenIDAuthenticationSessionManager.class);

Review Comment:
   The blank line can stay, and this new line should be above it - it separates the OpenID-specific binds from the generic one.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -131,6 +138,119 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
         return null;
     }
 
+    /**
+     * Validates the given ID token, using code flow, returning the JwtClaims
+     * contained therein. If the ID token is invalid, null is returned.
+     *
+     * @param code
+     *     The code to validate and receive the id_token.
+     *
+     * @param verifier
+     *     A PKCE verifier or null if not used.
+     *
+     * @return
+     *     The JWT claims contained within the given ID token if it passes tests,
+     *     or null if the token is not valid.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties could not be parsed.
+     */
+    public JwtClaims validateCode(String code, String verifier) throws GuacamoleException {
+        // Validating the token requires a JWKS key resolver
+        HttpsJwks jwks = new HttpsJwks(confService.getJWKSEndpoint().toString());
+        HttpsJwksVerificationKeyResolver resolver = new HttpsJwksVerificationKeyResolver(jwks);
+
+        /* Exchange code → token */
+        String token = exchangeCode(code, verifier);
+
+        // Create JWT consumer for validating received token
+        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
+                .setRequireExpirationTime()
+                .setMaxFutureValidityInMinutes(confService.getMaxTokenValidity())
+                .setAllowedClockSkewInSeconds(confService.getAllowedClockSkew())
+                .setRequireSubject()
+                .setExpectedIssuer(confService.getIssuer())
+                .setExpectedAudience(confService.getClientID())
+                .setVerificationKeyResolver(resolver)
+                .build();
+
+        try {
+            // Validate JWT
+            return jwtConsumer.processToClaims(token);
+        }
+        // Log any failures to validate/parse the JWT
+        catch (InvalidJwtException e) {
+            logger.info("Rejected invalid OpenID token: {}", e.getMessage(), e);
+        }
+
+        return null;
+    }

Review Comment:
   It seems like this new method does almost exactly the same thing as the existing `validateToken()` method, save the call to the `exchangeCode()` method. Surely we can avoid the duplication, here.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}

Review Comment:
   Please document this constructor.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -131,6 +138,119 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
         return null;
     }
 
+    /**
+     * Validates the given ID token, using code flow, returning the JwtClaims
+     * contained therein. If the ID token is invalid, null is returned.
+     *
+     * @param code
+     *     The code to validate and receive the id_token.
+     *
+     * @param verifier
+     *     A PKCE verifier or null if not used.
+     *
+     * @return
+     *     The JWT claims contained within the given ID token if it passes tests,
+     *     or null if the token is not valid.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties could not be parsed.
+     */
+    public JwtClaims validateCode(String code, String verifier) throws GuacamoleException {
+        // Validating the token requires a JWKS key resolver
+        HttpsJwks jwks = new HttpsJwks(confService.getJWKSEndpoint().toString());
+        HttpsJwksVerificationKeyResolver resolver = new HttpsJwksVerificationKeyResolver(jwks);
+
+        /* Exchange code → token */
+        String token = exchangeCode(code, verifier);
+
+        // Create JWT consumer for validating received token
+        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
+                .setRequireExpirationTime()
+                .setMaxFutureValidityInMinutes(confService.getMaxTokenValidity())
+                .setAllowedClockSkewInSeconds(confService.getAllowedClockSkew())
+                .setRequireSubject()
+                .setExpectedIssuer(confService.getIssuer())
+                .setExpectedAudience(confService.getClientID())
+                .setVerificationKeyResolver(resolver)
+                .build();
+
+        try {
+            // Validate JWT
+            return jwtConsumer.processToClaims(token);
+        }
+        // Log any failures to validate/parse the JWT
+        catch (InvalidJwtException e) {
+            logger.info("Rejected invalid OpenID token: {}", e.getMessage(), e);
+        }
+
+        return null;
+    }
+    
+    /**
+     * URLEncodes a key/value pair
+     *
+     * @param key
+     *     The key to encode
+     *
+     * @param value
+     *     The value to encode
+     *
+     * @return
+     *     The urlencoded kay/value pair
+     */
+     private String urlencode(String key, String value) {
+         StringBuilder builder = new StringBuilder();
+         return builder.append(URLEncoder.encode(key, StandardCharsets.UTF_8))
+                       .append("=")
+                       .append(URLEncoder.encode(value, StandardCharsets.UTF_8))
+                       .toString();
+     }
+
+    /**
+     * Exchanges the authorization code for tokens.
+     *
+     * @param code
+     *     The authorization code received from the IdP.
+     * @param codeVerifier

Review Comment:
   Please add a blank line in between these `@param` blocks.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+     private static String issuer = null;
+
+    /**
+     * The detected authorization edpoint
+     */
+     private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token edpoint
+     */
+     private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+     private static URI jwks_uri = null;
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-well-known-endpoint";
+        }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the authorization
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }

Review Comment:
   Aside from being called inside this class in the `init()` method, the only other call that I see is in the `ConfigurationService`, which, as I mention in the comment above, may not be necessary. I think that call can be removed and this can be changed to `private`.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -334,7 +419,130 @@ public String getIssuer() throws GuacamoleException {
      *     property is missing.
      */
     public URI getJWKSEndpoint() throws GuacamoleException {
-        return environment.getRequiredProperty(OPENID_JWKS_ENDPOINT);
+        URI jwks_uri =  environment.getProperty(OPENID_JWKS_ENDPOINT);
+        jwks_uri = jwks_uri == null ? confWellKnown.getJWKSEndpoint() : jwks_uri;
+        if (jwks_uri == null) {
+            throw new GuacamoleException("Property openid-jwks-endpoint or openid-well-known-endpoint is required");
+        }
+        return jwks_uri;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The token endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the token
+     *     endpoint property is missing.
+     */
+    public URI getTokenEndpoint() throws GuacamoleException {
+        URI token_endpoint = environment.getProperty(OPENID_TOKEN_ENDPOINT);
+        token_endpoint = token_endpoint == null ? confWellKnown.getTokenEndpoint() : token_endpoint;
+        if (token_endpoint == null) {
+            throw new GuacamoleException("Property openid-token-endpoint or openid-well-known-endpoint is required");
+        }
+        return token_endpoint;
+    }
+    
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the well-known
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return confWellKnown.getWellKnownEndpoint();
+    }    

Review Comment:
   Is this method really necessary? I don't see this being actually called anywhere in the code? It seems like the well-known endpoint is only ever used inside the `OpenIDWellKnown` class.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+     private static String issuer = null;
+
+    /**
+     * The detected authorization edpoint
+     */
+     private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token edpoint
+     */
+     private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+     private static URI jwks_uri = null;
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-well-known-endpoint";
+        }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the authorization
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.
+     */
+    public String getIssuer() {
+        return issuer;
+    }
+
+    /**
+     * Returns the authorization endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The authorization endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getAuthorizationEndpoint() {
+        return authorization_endpoint;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The token endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getTokenEndpoint() {
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the endpoint (URI) of the JWKS service which defines how
+     * received ID tokens (JWTs) shall be validated, as configured from
+     * the well-known endpoint.
+     *
+     * @return
+     *     The endpoint (URI) of the JWKS service which defines how received ID
+     *     tokens (JWTs) shall be validated, as configured from the
+     *     well-known endpoint.
+     */
+    public URI getJWKSEndpoint() {
+        return jwks_uri;
+    }
+
+    /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;
+
+    /*
+     * Creates an OpenIDWellKnown class that reads the json from an OIDC
+     * well-known endpoint and saves these values for later use. Use Guice
+     * to ensure environment exists before initializing.
+     */
+    public OpenIDWellKnown() {
+    }
+
+    @Inject
+    public void init() {
+        // Call to well-known endpoint might fail, so allow several tries before giving up
+        ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+        
+        Runnable task = new Runnable() {
+            int attempts = 0;
+
+            @Override
+            public void run() {
+                attempts++;
+
+                try {
+                    Map<String,Object> json = JsonUrlReader.fetch("GET", getWellKnownEndpoint().toURL(), "");

Review Comment:
   What happens, here, if the administrator has not provided a well-known endpoint? The call, above, to `getProperty()` in the `getWellKnownEndpoint()` implementation, will return `null` if the property has not been provided. My guess is that this should be checked before kicking off this scheduler? Am I missing where that check happens?



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -20,12 +20,17 @@
 package org.apache.guacamole.auth.openid.conf;
 
 import com.google.inject.Inject;
+

Review Comment:
   We generally don't break between `import` blocks, you can remove this line.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/ConfigurationService.java:
##########
@@ -110,6 +120,66 @@ public class ConfigurationService {
 
     };
 
+    /**
+     * The token endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_TOKEN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-token-endpoint";
+        }
+    };
+
+    /**
+     * The reponse type of the OpenID service.
+     */
+    private static final EnumGuacamoleProperty<OpenIDResponseType> OPENID_RESPONSE_TYPE =
+            new EnumGuacamoleProperty<OpenIDResponseType>(OpenIDResponseType.class) {
+
+        @Override
+        public String getName() { return "openid-response-type"; }
+
+    };
+
+    /**
+     * OIDC client secret which should be submitted to the OIDC service when
+     * validating tokens with code flow
+     */
+    private static final StringGuacamoleProperty OPENID_CLIENT_SECRET =
+            new StringGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-client-secret";
+        }
+    };
+
+    /**
+     * True if "Proof Key for Code Exchange" (PKCE) must be used.
+     */
+    private static final BooleanGuacamoleProperty OPENID_PKCE_REQUIRED =
+            new BooleanGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-pkce-required";
+        }
+    };
+
+    /**
+     * The maximum amount of time to allow for an in-progress OpenID
+     * authentication attempt to be completed, in minutes. A user that takes
+     * longer than this amount of time to complete authentication with their
+     * identity provider will be redirected back to the identity provider to
+     * try again.
+     */
+    private static final IntegerGuacamoleProperty OPENID_AUTH_TIMEOUT =
+            new IntegerGuacamoleProperty() {
+        @Override
+        public String getName() { return "openid-auth-timeout"; }
+
+    };
+
+

Review Comment:
   This block of code needs to be consistent in its style, both internal (within this block) and also with established style throughout the code:
   * There are varying occurrences of blank lines before the `@Override` and after the functions.
   * Sometimes you put the braces and `return` statement on a single line, sometimes you used multiple lines.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);

Review Comment:
   This should be static.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/PKCEUtil.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+
+/**
+ * Utility class for generating PKCE parameters.
+ *
+ * Supports:
+ *   - code_verifier (random Base64URL)
+ *   - code_challenge (S256)
+ */
+public final class PKCEUtil {
+
+    private static final SecureRandom RANDOM = new SecureRandom();
+
+    private PKCEUtil() {}
+
+    /**
+     * Generates a high-entropy PKCE code_verifier.
+     */

Review Comment:
   Please complete the documentation for this method (at the very least needs an `@return` block).



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/PKCEUtil.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+
+/**
+ * Utility class for generating PKCE parameters.
+ *
+ * Supports:
+ *   - code_verifier (random Base64URL)
+ *   - code_challenge (S256)
+ */
+public final class PKCEUtil {
+
+    private static final SecureRandom RANDOM = new SecureRandom();
+
+    private PKCEUtil() {}
+
+    /**
+     * Generates a high-entropy PKCE code_verifier.
+     */
+    public static String generateCodeVerifier() {
+        byte[] bytes = new byte[64];
+        RANDOM.nextBytes(bytes);
+        return base64Url(bytes);
+    }
+
+    /**
+     * Computes the PKCE code_challenge = BASE64URL(SHA256(code_verifier)).
+     */
+    public static String generateCodeChallenge(String verifier) throws Exception {
+        MessageDigest sha = MessageDigest.getInstance("SHA-256");
+        byte[] hash = sha.digest(verifier.getBytes("US-ASCII"));
+        return base64Url(hash);
+    }
+
+    /**
+     * Base64URL encoding without padding.
+     */

Review Comment:
   Please complete documentation for this method.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {
+            throw new GuacamoleException("JsonUrlReader : Missing URL");
+        }
+        
+        try {
+            // Open connection, using HttpURLConnection
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+
+            conn.setRequestMethod(method);
+            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+
+            if (! method.equalsIgnoreCase("GET")) {

Review Comment:
   Do we really expect the case of the HTTP method to vary? I see it fairly consistently as "GET" (in capital letters) - are there situations where we think this won't be the case?



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {

Review Comment:
   What if the URL is an empty string?



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {

Review Comment:
   Please document this method.
   
   Also, if this is intended to be a more generic utility class, then maybe it should throw something other than a `GuacamoleException`?



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/PKCEUtil.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+
+/**
+ * Utility class for generating PKCE parameters.
+ *
+ * Supports:
+ *   - code_verifier (random Base64URL)
+ *   - code_challenge (S256)
+ */
+public final class PKCEUtil {
+
+    private static final SecureRandom RANDOM = new SecureRandom();

Review Comment:
   Please document this.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/OpenIDAuthenticationSession.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid;
+
+import org.apache.guacamole.net.auth.AuthenticationSession;
+
+/**
+ * Representation of an in-progress OpenID authentication attempt.
+ */
+public class OpenIDAuthenticationSession extends AuthenticationSession {
+    /**

Review Comment:
   Should be a blank line above this one.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    private JsonUrlReader() {}
+
+    public static Map<String,Object> fetch(String method, URL url, String body) throws GuacamoleException {
+        if (url == null) {
+            throw new GuacamoleException("JsonUrlReader : Missing URL");

Review Comment:
   If you are going to throw `GuacamoleException` types, it should probably be something more specific than just the generic `GuacamoleException`.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -131,6 +138,119 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
         return null;
     }
 
+    /**
+     * Validates the given ID token, using code flow, returning the JwtClaims
+     * contained therein. If the ID token is invalid, null is returned.
+     *
+     * @param code
+     *     The code to validate and receive the id_token.
+     *
+     * @param verifier
+     *     A PKCE verifier or null if not used.
+     *
+     * @return
+     *     The JWT claims contained within the given ID token if it passes tests,
+     *     or null if the token is not valid.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties could not be parsed.
+     */
+    public JwtClaims validateCode(String code, String verifier) throws GuacamoleException {
+        // Validating the token requires a JWKS key resolver
+        HttpsJwks jwks = new HttpsJwks(confService.getJWKSEndpoint().toString());
+        HttpsJwksVerificationKeyResolver resolver = new HttpsJwksVerificationKeyResolver(jwks);
+
+        /* Exchange code → token */
+        String token = exchangeCode(code, verifier);
+
+        // Create JWT consumer for validating received token
+        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
+                .setRequireExpirationTime()
+                .setMaxFutureValidityInMinutes(confService.getMaxTokenValidity())
+                .setAllowedClockSkewInSeconds(confService.getAllowedClockSkew())
+                .setRequireSubject()
+                .setExpectedIssuer(confService.getIssuer())
+                .setExpectedAudience(confService.getClientID())
+                .setVerificationKeyResolver(resolver)
+                .build();
+
+        try {
+            // Validate JWT
+            return jwtConsumer.processToClaims(token);
+        }
+        // Log any failures to validate/parse the JWT
+        catch (InvalidJwtException e) {
+            logger.info("Rejected invalid OpenID token: {}", e.getMessage(), e);
+        }
+
+        return null;
+    }
+    
+    /**
+     * URLEncodes a key/value pair
+     *
+     * @param key
+     *     The key to encode
+     *
+     * @param value
+     *     The value to encode
+     *
+     * @return
+     *     The urlencoded kay/value pair
+     */
+     private String urlencode(String key, String value) {
+         StringBuilder builder = new StringBuilder();
+         return builder.append(URLEncoder.encode(key, StandardCharsets.UTF_8))
+                       .append("=")
+                       .append(URLEncoder.encode(value, StandardCharsets.UTF_8))
+                       .toString();
+     }
+
+    /**
+     * Exchanges the authorization code for tokens.
+     *
+     * @param code
+     *     The authorization code received from the IdP.
+     * @param codeVerifier
+     *     The PKCE verifier (or null if PKCE is disabled).
+     *
+     * @return
+     *     The token string returned.
+     *
+     * @throws GuacamoleException
+     *     If a valid token is not returned.
+     */
+    private String exchangeCode(String code, String verifier) throws GuacamoleException {
+
+        try {
+            StringBuilder bodyBuilder = new StringBuilder();
+            bodyBuilder.append(urlencode("grant_type", "authorization_code")).append("&");
+            bodyBuilder.append(urlencode("code", code)).append("&");
+            bodyBuilder.append(urlencode("redirect_uri", confService.getRedirectURI().toString())).append("&");
+            bodyBuilder.append(urlencode("scope", confService.getScope())).append("&");
+            bodyBuilder.append(urlencode("client_id", confService.getClientID()));
+
+            String clientSecret = confService.getClientSecret();
+            if (clientSecret != null && !clientSecret.trim().isEmpty()) {
+                bodyBuilder.append("&").append(urlencode("client_secret", clientSecret));
+            }
+
+            if (confService.isPKCERequired()) {
+                bodyBuilder.append("&").append(urlencode("code_verifier", verifier));
+            }
+
+            Map<String,Object> json = 
+                    JsonUrlReader.fetch("POST", confService.getTokenEndpoint().toURL(),
+                                        bodyBuilder.toString());
+
+            return (String) json.get("id_token");
+
+        } catch (Exception e) {

Review Comment:
   Please don't cuddle the braces.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/PKCEUtil.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+
+/**
+ * Utility class for generating PKCE parameters.
+ *
+ * Supports:
+ *   - code_verifier (random Base64URL)
+ *   - code_challenge (S256)
+ */
+public final class PKCEUtil {
+
+    private static final SecureRandom RANDOM = new SecureRandom();
+
+    private PKCEUtil() {}

Review Comment:
   Please document this constructor.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/PKCEUtil.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+
+/**
+ * Utility class for generating PKCE parameters.
+ *
+ * Supports:
+ *   - code_verifier (random Base64URL)
+ *   - code_challenge (S256)
+ */
+public final class PKCEUtil {
+
+    private static final SecureRandom RANDOM = new SecureRandom();
+
+    private PKCEUtil() {}
+
+    /**
+     * Generates a high-entropy PKCE code_verifier.
+     */
+    public static String generateCodeVerifier() {
+        byte[] bytes = new byte[64];
+        RANDOM.nextBytes(bytes);
+        return base64Url(bytes);
+    }
+
+    /**
+     * Computes the PKCE code_challenge = BASE64URL(SHA256(code_verifier)).
+     */

Review Comment:
   Please complete documentation for this method.



##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {
+    /**

Review Comment:
   Please add a blank line above this line.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069571725


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+
+public final class JsonUrlReader {
+    /**
+     * Logger for this class.
+     */
+    private static final Logger logger = LoggerFactory.getLogger(JsonUrlReader.class);
+
+    /**
+     * Class to GET and POST to a URL and read the returned JSON. This class should
+     * not be instantiated.
+     */
+    private JsonUrlReader() {}
+
+    /**
+     * Method to POST or GET to a URL and recover the JSON in the form of a Map
+     *
+     * @param String method
+     *      The htpp method to use. Should be "GET", "POST" or "PATCH".
+     *
+     * @param URI uri
+     *      A URI value giving the address where to recover the JSON
+     *
+     * @param String body
+     *      A pre-encoded body string to be sent to the address if the method is
+     *      "POST" or "PATCH". Ignored if the method is "GET".
+     *
+     * @return
+     *      A Map<String,Object> containing the decoded json values.
+     */
+    public static Map<String, Object> fetch(String method, URI uri, String body) throws IOException {
+        if (uri == null || uri.toString().isEmpty()) {
+            throw new IOException("JsonUrlReader: Missing URL");
+        }
+
+        try {
+            HttpClient client = HttpClient.newHttpClient();
+            HttpRequest request = HttpRequest.newBuilder()
+                    .uri(uri)
+                    .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
+                    .method(method,

Review Comment:
   On my machine using "GET" here doesn't crash here with an IllegalArgumentException though the documentation makes me think it should. Should I protect this in a if/else block ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - don’t introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find any apache commons I/O function that treated both POST and GET. Using Jackson to deserialize to an Object seemed also to be overkill as I only
   needed a couple of values. 
   
   The slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the http post/get operations are one off each time. Though using org.apache.http.impl.client.HttpClient is an option that might be attractive as it supplies functions to more cleanly treat the posted form data. 
   
   I've updated the code using java.net.http.httpClient and included asynchronous operation to release control back to the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client, there is a plethora to choose from, then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regret is the right thing to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178879551


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -131,6 +150,73 @@ public JwtClaims validateToken(String token) throws GuacamoleException {
         return null;
     }
 
+    /**
+     * URLEncodes a key/value pair
+     *
+     * @param key
+     *     The key to encode
+     *
+     * @param value
+     *     The value to encode
+     *
+     * @return
+     *     The urlencoded kay/value pair
+     */
+     private String urlencode(String key, String value) {
+         StringBuilder builder = new StringBuilder();
+         return builder.append(URLEncoder.encode(key, StandardCharsets.UTF_8))
+                       .append("=")
+                       .append(URLEncoder.encode(value, StandardCharsets.UTF_8))
+                       .toString();
+     }
+
+    /**
+     * Exchanges the authorization code for tokens.
+     *
+     * @param code
+     *     The authorization code received from the IdP.
+     *
+     * @param codeVerifier
+     *     The PKCE verifier (or null if PKCE is disabled).
+     *
+     * @return
+     *     The token string returned.
+     *
+     * @throws GuacamoleException
+     *     If a valid token is not returned.
+     */
+    private String exchangeCode(String code, String verifier) throws GuacamoleException {
+
+        try {
+            StringBuilder bodyBuilder = new StringBuilder();
+            bodyBuilder.append(urlencode("grant_type", "authorization_code")).append("&");
+            bodyBuilder.append(urlencode("code", code)).append("&");
+            bodyBuilder.append(urlencode("redirect_uri", confService.getRedirectURI().toString())).append("&");
+            bodyBuilder.append(urlencode("scope", confService.getScope())).append("&");
+            bodyBuilder.append(urlencode("client_id", confService.getClientID()));
+
+            String clientSecret = confService.getClientSecret();
+            if (clientSecret != null && !clientSecret.trim().isEmpty()) {
+                bodyBuilder.append("&").append(urlencode("client_secret", clientSecret));
+            }
+
+            if (confService.isPKCERequired()) {
+                bodyBuilder.append("&").append(urlencode("code_verifier", verifier));
+            }
+
+            Map<String,Object> json = 
+                    JsonUrlReader.fetch("POST", confService.getTokenEndpoint(),
+                                        bodyBuilder.toString());
+
+            return (String) json.get("id_token");
+
+        }
+        catch (Exception e) {
+            logger.info("Rejected invalid OpenID code exchange: {}", e.getMessage(), e);
+        }

Review Comment:
   As Exception replace with IOException in the catch in the git, resolve this comment, leave only the JsonUrlreader comment open 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178868848


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -70,20 +73,26 @@ public class TokenValidationService {
     private NonceService nonceService;
 
     /**
-     * Validates the given ID token, returning the JwtClaims contained therein.
-     * If the ID token is invalid, null is returned.
+     * Validates the given ID token, using implicit flow. Also validates codes,
+     * exchanging them for id_tokens before validation. If the id_token or
+     * code is invalid, null is returned, otherwise the JwtClaims in the
+     * id_token are returned.
      *
      * @param token
-     *     The ID token to validate.
+     *     The ID token to validate if implicit flow or the code to exchange for
+     *     an id_token and then validate.
+     *
+     * @param verifier
+     *     A PKCE verifier or null if not used. Only used with code flow
      *
      * @return
-     *     The JWT claims contained within the given ID token if it passes tests,
-     *     or null if the token is not valid.
+     *     The JWT claims contained within the id_token if it passes tests,
+     *     or null if the id_token is not valid.

Review Comment:
   As it should always return null, rexolving this comment 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3182014588


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   Thinking of a half way solution where we keep Jose4j for the JWT claims but use springframework to read the json.. We coud get rid of JsonUrlReader in OpenBaoWellKnown.java like 
   
   ```
   import org.springframework.web.client.restTemplate;
   import java.util.Map;
   
   RestTemplate restTemplate = new RestTemplate();
   Map<String,Object> response = restTemplate.getForObject(configService.getWellKnownEndpoint().toString(), Map.Class);
   
   issuer = (String) response.getBody().get("issuer");
   authorization_endpoint =  (String) response.getBody().get("authorization_endpoint");
   token_endpoint =  (String) response.getBody().get("token_endpoint");
   jwks_uri =  (String) response.getBody().get("jwks_uri");
   ``` 
   and in TokenValidationServic.java like
   
   ```
   import org.springframework.http.HttpEntity;import org.springframework.http.HttpType;
   import org.springframework.util.LinkedMultiValueMap;
   import org.springframework.util.MultiValueMap;
   import org.springframework.web.client.RestTemplate;
   import org.springframework.http.HttpHeaders;
   import java.util.Map;
   
   RestTemplate restTemplate = new RestTemplate();
   MultiValueMap<String, String> body = new LinkedMultiValueMap<String, String>();
   body.add("grant_type", "authorization_code");
   body.add("code", code);
   body.add("redirect_uri", confService.getRedirectURI().toString());
   body.add("client_id", confService.getClientID());
   body.add("scope", confService.getScope());
   
   String clientSecret = confService.getClientSecret();
   if (clientSecret != null && !clientSecret.trim().isEmpty()) {
       body.add("client_secret", clientSecret);
   }
   if (confService.isPKCERequired()) {
       body.add("code_verifier, verifier);
   }
   
   HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
   HttpEntity<MultiValueMap<String, String>> request =
           new HttpEntity<MultiValueMap<String, String>>(body, headers);
   String response =  restTemplate.postForObject(tokenUri, request, String.class);
   
   return  (String) response.getBody().get("iid_token");
   ``` 
   
   Though Frankly it doesn't seem much simplier than what I already have
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4507954597

   > > Aren't all the commits warpped up into a single commit against the [guacamole-client](https://issues.apache.org/jira/browse/GUACAMOLE-client) repo when the PR is accepted with a seperate description ?
   > 
   > No - a merge commit is added, but each of your commits will still be there, and thus they need to be descriptive, not just to you, but to the entire community.
   
   Do you want me to recommit them against a clean guacamole-client tree with a single more descriptive commit message and the JIRA ticket in a new pull-request ?  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3062367026


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/conf/OpenIDWellKnown.java:
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.conf;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.Map;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.guacamole.auth.openid.util.JsonUrlReader;
+import org.apache.guacamole.GuacamoleException;
+import org.apache.guacamole.environment.Environment;
+import org.apache.guacamole.properties.URIGuacamoleProperty;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class for retrieving well-known endpoint data.
+ */
+@Singleton
+public class OpenIDWellKnown {
+
+    /**
+     * Logger for this class.
+     */
+    private final Logger logger = LoggerFactory.getLogger(OpenIDWellKnown.class);
+
+
+    /**
+     * The number of attempts to the well-known endpoint to get the values before giving up
+     */
+    private static final int MAX_ATTEMPTS = 24;
+
+    /**
+     * The delay between each attempt to well-known endpoint in seconds
+     */
+    private static final long DELAY_SECONDS = 5;
+
+    /**
+     * The detected issuer
+     */
+     private static String issuer = null;
+
+    /**
+     * The detected authorization edpoint
+     */
+     private static URI authorization_endpoint = null;
+
+    /**
+     * The detected token edpoint
+     */
+     private static URI token_endpoint = null;
+
+    /**
+     * The detected jwks_uri
+     */
+     private static URI jwks_uri = null;
+
+    /**
+     * The well-known endpoint (URI) of the OIDC service.
+     */
+    private static final URIGuacamoleProperty OPENID_WELL_KNOWN_ENDPOINT =
+            new URIGuacamoleProperty() {
+        @Override
+        public String getName() {
+            return "openid-well-known-endpoint";
+        }
+    };
+
+    /**
+     * Returns the well-known endpoint (URI) of the OIDC service as
+     * configured with guacamole.properties.
+     *
+     * @return
+     *     The well-known endpoint of the OIDC service, as configured with
+     *     guacamole.properties.
+     *
+     * @throws GuacamoleException
+     *     If guacamole.properties cannot be parsed, or if the authorization
+     *     endpoint property is missing.
+     */
+    public URI getWellKnownEndpoint() throws GuacamoleException {
+        return environment.getProperty(OPENID_WELL_KNOWN_ENDPOINT);
+    }
+
+    /**
+     * Returns the issuer to expect for all received ID tokens, as configured
+     * from the well_known endpoint.
+     *
+     * @return
+     *     The issuer to expect for all received ID tokens, as returned by the
+     *     well-known endpoint.
+     */
+    public String getIssuer() {
+        return issuer;
+    }
+
+    /**
+     * Returns the authorization endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The authorization endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getAuthorizationEndpoint() {
+        return authorization_endpoint;
+    }
+
+    /**
+     * Returns the token endpoint (URI) of the OpenID service as
+     * configured from the well_known endpoint.
+     *
+     * @return
+     *     The token endpoint of the OpenID service, as returned by the
+     *     well-known endpoint.
+     */
+    public URI getTokenEndpoint() {
+        return token_endpoint;
+    }
+
+    /**
+     * Returns the endpoint (URI) of the JWKS service which defines how
+     * received ID tokens (JWTs) shall be validated, as configured from
+     * the well-known endpoint.
+     *
+     * @return
+     *     The endpoint (URI) of the JWKS service which defines how received ID
+     *     tokens (JWTs) shall be validated, as configured from the
+     *     well-known endpoint.
+     */
+    public URI getJWKSEndpoint() {
+        return jwks_uri;
+    }
+
+    /**
+     * The Guacamole server environment.
+     */
+    @Inject
+    private Environment environment;
+
+    /*
+     * Creates an OpenIDWellKnown class that reads the json from an OIDC
+     * well-known endpoint and saves these values for later use. Use Guice
+     * to ensure environment exists before initializing.
+     */
+    public OpenIDWellKnown() {
+    }
+
+    @Inject
+    public void init() {
+        // Call to well-known endpoint might fail, so allow several tries before giving up
+        ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+        
+        Runnable task = new Runnable() {
+            int attempts = 0;
+
+            @Override
+            public void run() {
+                attempts++;
+
+                try {
+                    Map<String,Object> json = JsonUrlReader.fetch("GET", getWellKnownEndpoint().toURL(), "");

Review Comment:
   At the moment JsonUrlReader will be called 24 times failing each time and eventually stop. Yes I could have a fast return from init() if the well-known endpoint is missing 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3178522553


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/token/TokenValidationService.java:
##########
@@ -70,20 +73,26 @@ public class TokenValidationService {
     private NonceService nonceService;
 
     /**
-     * Validates the given ID token, returning the JwtClaims contained therein.
-     * If the ID token is invalid, null is returned.
+     * Validates the given ID token, using implicit flow. Also validates codes,
+     * exchanging them for id_tokens before validation. If the id_token or
+     * code is invalid, null is returned, otherwise the JwtClaims in the
+     * id_token are returned.
      *
      * @param token
-     *     The ID token to validate.
+     *     The ID token to validate if implicit flow or the code to exchange for
+     *     an id_token and then validate.
+     *
+     * @param verifier
+     *     A PKCE verifier or null if not used. Only used with code flow
      *
      * @return
-     *     The JWT claims contained within the given ID token if it passes tests,
-     *     or null if the token is not valid.
+     *     The JWT claims contained within the id_token if it passes tests,
+     *     or null if the id_token is not valid.

Review Comment:
   If the JsonUrlReader is replaced with "org.springframework.security.oauth2" this function should be replaced as well 
   
   Though your question is independent of this. This function is called from authenticateUser, where a null value results in the username being set to null. authenticateUser itself then throws the GuacamoleInvalidCredentialsException. So in this case I think the return value still remain null



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3180465502


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   Ok, a "mvn dependency:tree" ahow me that the version 3.0.5 of springframework core referenced in doc/licenses is not in fact used anywhere. However, looking further the springframework OAuth2 package needs at least springframework core version 6 and both need Java17+.  I'd thought that Guacamole was still trying to keep Java11 compatibility, so this change would mean that at leaset Java17 would be needed for this module 
   
    



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 closed pull request #1198: GUACAMOLE-2258 : OpenID code flow, client secret and PKCE
URL: https://github.com/apache/guacamole-client/pull/1198


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4517021012

   > to recommit them
   
   @necouchman Ok I reworked all of the commit messages and force pushed them to my repo 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4207214631

   I've figured out how to use a SessionManager directly in getLoginURI to store the PKCE verifier. The local REST redirect and callback for the session are no longer needed and have be removed. Making the implementation cleaner


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on code in PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#discussion_r3069545652


##########
extensions/guacamole-auth-sso/modules/guacamole-auth-sso-openid/src/main/java/org/apache/guacamole/auth/openid/util/JsonUrlReader.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.guacamole.auth.openid.util;
+
+import java.io.BufferedReader;
+import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import org.apache.guacamole.GuacamoleException;
+import org.jose4j.json.JsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Utility class to open a http connection to a URL, send a body
+ * and receive a response in the form of a parsed JSON
+ */
+public final class JsonUrlReader {

Review Comment:
   I'd written a huge amount of comments in my deleted self review for this point. Basically thinking out loud. So here you'll get the condensed version.
   
   Basically doing something like
   
   ```
   $ find . -name "*.java" -exec grep -H "httpClient" {} \;
   ```
   
   and all other possible httpclients I could think of, I found no example of an outboud HTTP connexion from guacamole. So as far as I can see we are free to implement this how we want. However it needs to
   
   - No introduce any new large dependencies to guacamole
   - treat both POST and GET requests
   - Be relatively clean
   
   java.nat.httpUrlConnection is a bit old and ugly, but I couldn't find and the slightly more modern java.net.http.httpClient will make the code cleaner. Don't see the point of using org.apache.http.impl.client.CloseableHttpClient as the htpp post/get operations are one off each time.
   
   I've updated the code using httpClient and included asynchronous operation to release control back the the Tomcat Servlet so as not to impact the rest of guacamole if the operation takes some time.
   
   If you prefer a different http client then sure I'll change it. Now is the time to complain as this is the first outbound connection in guacamole, so getting it right before introducing code we might regrets is the right time to do. :-)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4222611734

   Ok, I've treated all of your comments. Thinking about it, I still have one issue. Guacamole displays the data returned by keycloak in the navigation bar, including the "code" field for code flow... If the user refreshs the page, as they often do if there is a problem, authenticateUser will be called again with the stale code and this will be posted to the identity provider. The identity provider detects this as a code "reuse" and probably an attack. This is bad
   
   An idea would be in authenticateUser we do a redirect to the guacamole root instead of returning authenticateUser. Though this currently breaks things. The only other choice I see is the use of code like
   
   ```javascript
   (function guacOpenIDTransformToken() {
       if (window.history && history.replaceState)
           history.replaceState(null, "", window.location.pathname + window.location.hash);
       if (/^#(?![?\/])(.*&)?id_token=/.test(location.hash))
           location.hash = '/?' + location.hash.substring(1);
   })();
   ```
   
   client side in transformToken.js to hide the non URL fragment query parameters returned by the identity provider from the user.. Still needs testing, so I'll submit another patch soon 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4236686159

   > @necouchman anticipating that you’ll want a patch to the manual, I started think what is needed but ran into a question. At the moment the configuration is split into required and optional configuration options. However, with the proposed changes only openid-client-id and openid-redirect-uri remain required. The other existing « required » options can either remain required or be replaced with openid-well-known-endpoint.
   > 
   > To me the split required/optional make less sense now. What I propose is a discussion implicit flow versus code flow and another section on the well-known endpoint and the fact it can replace up to 4 (3 with implicit flow) other required configuration options. I then propose to combine the existing required and optional sections into a single section.
   > 
   > How do you want this addressed ?
   
   I went ahead and implemented a possible change to the manual in a seperate pull request


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GUACAMOLE-2258 : OpenID code flow, client secret and PKCE [guacamole-client]

Posted by "adb014 (via GitHub)" <gi...@apache.org>.
adb014 commented on PR #1198:
URL: https://github.com/apache/guacamole-client/pull/1198#issuecomment-4630149239

   > > From what I understand in my other PR this should be rebased against staging/1.6.1. However, I didn't create a personal branch for these change and so as far as I can see any forced push is going to mess up this PR...
   > > @necouchman can to resolve any outsatnding issues you have with this PR, I'll correct for the requested changes and after rebase against staging/1.6.1 and generate a new PR
   > 
   > I believe this should stay based against the `main` branch - it's enough of a "feature" change, and a pretty large one at that, that I think it should be in the 1.7.0 release and not in a patch release.
   
   After reading, https://cwiki.apache.org/confluence/display/GUAC/Version+Numbering+and+Branching+Scheme, and particularly the phrase 
   
   ```
   Changes that require substantial updates to the documentation are never part of patch releases, ...
   ```
   
   and this PR definitely does require major documentation updates.. Need to re-rebase #1216 as well ;-)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org