# Configure OAuth2RestTemplate if AcessToken is already Available

**URL:** <https://community.bloomreach.com/t/configure-oauth2resttemplate-if-acesstoken-is-already-available/494>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [October 15, 2018, 4:22pm UTC](https://community.bloomreach.com/t/configure-oauth2resttemplate-if-acesstoken-is-already-available/494 "2018-10-15T16:22:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinivas\_Jasti](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@Srinivas\_Jasti](https://community.bloomreach.com/u/Srinivas_Jasti)\
**Post date:** [October 15, 2018, 4:22pm UTC](https://community.bloomreach.com/t/configure-oauth2resttemplate-if-acesstoken-is-already-available/494/1 "2018-10-15T16:22:30Z")

</div>

Hi,  
I am using CRISP on 11.x(Hippo CMS),  
1.How to configure OAuth2RestTemplate if AcessToken is already Available and avoid calling for AcessToken  
at bootstrap/configuration/src/main/resources/configuration/modules/crispregistry/moduleconfig/resourceresolvercontainer.  
2. Can I programmatically .set the AcessToken from the component if so How…?

Many Thanks  
Srinivas Jasti

---

<div class="post-metadata">

**Author:** ![woonsanko](https://avatars.discourse-cdn.com/v4/letter/w/b5a626/32.png) [@woonsanko](https://community.bloomreach.com/u/woonsanko)\
**Post date:** [October 15, 2018, 8:06pm UTC](https://community.bloomreach.com/t/configure-oauth2resttemplate-if-acesstoken-is-already-available/494/2 "2018-10-15T20:06:56Z")

</div>

Your question is really spring-security-oauth2 specific, not Hippo CMS specific.  
As CRISP API and configuration simply assembles spring and spring-security and spring-security-oauth2 beans in XML, you should figure out whether it’s possible in those libraries and how.

Anyway, `OAuth2RestTemplate` has another constructor you can possibly try with:

```
public OAuth2RestTemplate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext context) {
   // ...
}

```

Unless you specify it, `context` is a `DefaultOAuth2ClientContext` by default.

`OAuth2RestTemplate` invokes its own `#getAccessToken()` which calls on `context.getAccessToken()`.

Therefore, it seems technically possible to pass a new `DefaultOAuth2ClientContext(OAuth2AccessToken)`–where you pass an `OAuth2AccessToken` somehow–instance when creating a `DefaultOAuth2ClientContext` for your `OAuth2RestTemplate` bean configuration.

Woonsan
