# EJB to API call

**URL:** <https://forum.keycloak.org/t/ejb-to-api-call/2125>\
**Category:** Securing applications\
**Created:** [April 13, 2020, 5:30pm UTC](https://forum.keycloak.org/t/ejb-to-api-call/2125 "2020-04-13T17:30:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![claudioweiler](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/claudioweiler/32/1295_2.png) [@claudioweiler](https://forum.keycloak.org/u/claudioweiler)\
**Post date:** [April 13, 2020, 5:30pm UTC](https://forum.keycloak.org/t/ejb-to-api-call/2125/1 "2020-04-13T17:30:35Z")

</div>

Hi,

I want to call a rest endpoint with current authenticated user in EJB context.

What I have:

- Keycloak 8.0.2
- Wildfly 17.0.1 + Keycloak Adapter
- 2 JavaEE 8 with JSF applications configured in Keycloak (Client A, Client B)
- Clients A and B can authenticate user, get roles, SSO working, etc…
- I managed to get Access Token and Id Token of current user using keycloakPrincipal

What I want:

An user authenticated in Client B uses a functionality that call REST API on Client A, and Client A needs to know what user is requesting its endpoint.

From what I googled this should be simpler, but I failing miserably, can you help me?

---

<div class="post-metadata">

**Author:** ![claudioweiler](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/claudioweiler/32/1295_2.png) [@claudioweiler](https://forum.keycloak.org/u/claudioweiler)\
**Post date:** [April 28, 2020, 8:32pm UTC](https://forum.keycloak.org/t/ejb-to-api-call/2125/3 "2020-04-28T20:32:50Z")

</div>

So far, I succesfully get userinfo openid address (protocol/openid-connect/userinfo) using current logged user access token, but for rest endpoint, always 401.

Debug infos:  
[org.keycloak.adapters.BearerTokenRequestAuthenticator] (default task-2) Failed to verify token  
[org.keycloak.adapters.RequestAuthenticator] (default task-2) Bearer FAILED
