-
Is there a way to manually verify and get SecurityIdentity, UserInfo and JsonWebToken? I know that there's a one time token way to match the rest and the websocket like the issue below. But I'd like to know whether there's a direct way to get SecurityIdenity, UserInfo and JsonWebToken by bearer token? Because I'd like to pass the bearer token directly by websocket message. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
/cc @sberyozkin (security) |
Beta Was this translation helpful? Give feedback.
-
It seems that there's a workaround here. var request = new TokenAuthenticationRequest(new AccessTokenCredential(accessToken));
HttpSecurityUtils.setRoutingContextAttribute(request, new DummyRoutingContext());
identityProviderManager
.authenticate(request)
.subscribe()
.with(securityIdentity1 -> {
logger.info(securityIdentity1.getPrincipal());
logger.info(((JsonWebToken) securityIdentity1.getPrincipal()).getRawToken());
for (String role : securityIdentity1.getRoles()) {
logger.info(securityIdentity1.getRoles());
}
}, (error) -> {
logger.warn("Failed to validate token", error);
}); This issue is reported. But it seems there's no update for the injectable service. OK. I can get UserInfo like this. But it uses reflection and it's a bit ugly. And also, it doesn't solve the multiple tenant problem. var field = TenantConfigContext.class.getDeclaredField("provider");
field.setAccessible(true);
((OidcProvider) field.get(defaultTenantConfigResolver.getTenantConfigBean().getDefaultTenant())).
getUserInfo(accessToken).subscribe().with(userInfo1 -> logger.info(userInfo1.getUserInfoString())); |
Beta Was this translation helpful? Give feedback.
-
@SetoKaiba, smallrye-jwt and JWT parser can help with simple manual verification returning JsonWebToken: https://quarkus.io/guides/security-jwt#jwt-parser But with |
Beta Was this translation helpful? Give feedback.
-
Thank you. I'm using the workaround from #27754 to get the JWT now. It does meet my need currently. |
Beta Was this translation helpful? Give feedback.
Thank you. I'm using the workaround from #27754 to get the JWT now. It does meet my need currently.