# Get upstream token via mapper (JS/Java)

**URL:** <https://forum.keycloak.org/t/get-upstream-token-via-mapper-js-java/20507>\
**Category:** Extending the server\
**Tags:** adapter-java, adapter-javascript\
**Created:** [February 27, 2023, 7:05am UTC](https://forum.keycloak.org/t/get-upstream-token-via-mapper-js-java/20507 "2023-02-27T07:05:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris11](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/chris11/32/7797_2.png) [@chris11](https://forum.keycloak.org/u/chris11)\
**Post date:** [February 27, 2023, 7:05am UTC](https://forum.keycloak.org/t/get-upstream-token-via-mapper-js-java/20507/1 "2023-02-27T07:05:39Z")

</div>

In a mapper (specifially: a Javascript- Mapper), I would like to grab the users upstream access-token (if available - otherwise the actual access- token provided), and authenticate an API with that.  
Kindof like this [forum post](http://forum.keycloak.org/t/unable-to-retrieve-upstream-identity-providers-original-token/2267/2).  
So far, I didn’t seem to have found the correct way or method to do so (found [this](https://www.keycloak.org/docs-api/20.0.1/javadocs/org/keycloak/authentication/authenticators/broker/util/SerializedBrokeredIdentityContext.html), but whatever ID I give it it will give me back “null” as a value - whether it is “getUsername” or “getToken”.

Can anyone pass me a hint? Java- Examples are welcome, too 🙂
