Closed simon-a11y closed 2 years ago
Hi @simon-a11y
This indeed looks like a bug, thanks for investigating it already! I'll do my best to fix this in the next release.
The fix for this will be part of the next release. If you are interested, here is the patch:
commit e4104e4c9d6871e285556ac37bdd501dc37dd058
Date: Fri Jun 25 14:27:40 2021 +0200
Fix #25725: error when authenticating with token in Authorization header
diff --git a/src/main/java/eu/openanalytics/containerproxy/auth/impl/KeycloakAuthenticationBackend.java b/src/main/java/eu/openanalytics/containerproxy/auth/impl/KeycloakAuthenticationBackend.java
index c97809f..b45414f 100644
--- a/src/main/java/eu/openanalytics/containerproxy/auth/impl/KeycloakAuthenticationBackend.java
+++ b/src/main/java/eu/openanalytics/containerproxy/auth/impl/KeycloakAuthenticationBackend.java
@@ -239,6 +239,12 @@ public class KeycloakAuthenticationBackend implements IAuthenticationBackend {
@Override
public String getName() {
IDToken token = getAccount().getKeycloakSecurityContext().getIdToken();
+ if (token == null) {
+ // when ContainerProxy is accessed directly using the Access Token as Bearer value in the Authorization
+ // header, no ID Token is present. The AccessTokens provided by Keycloak are in fact ID tokens, so we
+ // can safely fall back to them.
+ token = getAccount().getKeycloakSecurityContext().getToken();
+ }
switch (nameAttribute) {
case IDToken.PREFERRED_USERNAME: return token.getPreferredUsername();
case IDToken.NICKNAME: return token.getNickName();
We tested the patch and it works just fine. Thank you.
This is now part of ShinyProxy 2.6.0 (ContainerProxy 0.8.10).
Thank you for the suggestion!
We are using shinyproxy with Keycloak as authentication. Accessing the REST-endpoints of shinyproxy/containerproxy from the browser works just fine. As far as I understand, shinyproxy recognizes the user by the jsessionid-token, set in the browser after the successful keycloak login (redirecting back to shinyproxy). It would be lovely, to be able to access containerproxy endpoints via access tokens. For example from curl, postman or a backend application (Java/Spring Boot). However, doing so results in a nullpointer-exception:
If
proxy.keycloak.name-attribute: preferred_username
is set inapplication.yml
:The Problem is that
getAccount().getKeycloakSecurityContext().getIdToken()
returnsnull
(KeycloakAuthenticationBackend.java:232).I inspected the token to check that
preferred_username
is set and shinyproxy is also able to verify it. When commenting out thegetName()
method inKeycloakAuthenticationBackend.java
, which caused the exception, using access tokens works:Towards the middle of
KeycloakAuthenticationBackend.java
, there are comments, saying:So perhaps the solution is as easy as implementing the mentioned
RequestMatcher
for access tokens. I would prefer to not modify the code of containerproxy (i.e. commenting outKeycloakAuthenticationToken2.getName()
). Unfortunately my understanding of Spring Security, Keycloak and containerproxy's code is insufficient to come up with a correct solution and a pull request. Any insight into the problem is appreciated.