OAuth2RestTemplate - Client Side Caching












1















I see the below restTemplate being used for fetching OAuth token. I don't see any explicit call to cache the token in my application. However I see the same token value being returned by this template. Does OAuth2RestTemplate inherently implement client side caching? If so , does it make an explicit call to the OAuth2 endpoint when the token expires?



@Qualifier("oauth")
@Bean
public OAuth2RestTemplate restTemplate(@Qualifier("resourceDetails") ClientCredentialsResourceDetails resourceDetails) {
return new OAuth2RestTemplate(resourceDetails);
}


I saw the below in the documentation -




getAccessToken public OAuth2AccessToken getAccessToken()
throws UserRedirectRequiredException



Acquire or renew an access token for the current context if necessary.
This method will be called automatically when a request is executed
(and the result is cached), but can also be called as a standalone
method to pre-populate the token.











share|improve this question





























    1















    I see the below restTemplate being used for fetching OAuth token. I don't see any explicit call to cache the token in my application. However I see the same token value being returned by this template. Does OAuth2RestTemplate inherently implement client side caching? If so , does it make an explicit call to the OAuth2 endpoint when the token expires?



    @Qualifier("oauth")
    @Bean
    public OAuth2RestTemplate restTemplate(@Qualifier("resourceDetails") ClientCredentialsResourceDetails resourceDetails) {
    return new OAuth2RestTemplate(resourceDetails);
    }


    I saw the below in the documentation -




    getAccessToken public OAuth2AccessToken getAccessToken()
    throws UserRedirectRequiredException



    Acquire or renew an access token for the current context if necessary.
    This method will be called automatically when a request is executed
    (and the result is cached), but can also be called as a standalone
    method to pre-populate the token.











    share|improve this question



























      1












      1








      1








      I see the below restTemplate being used for fetching OAuth token. I don't see any explicit call to cache the token in my application. However I see the same token value being returned by this template. Does OAuth2RestTemplate inherently implement client side caching? If so , does it make an explicit call to the OAuth2 endpoint when the token expires?



      @Qualifier("oauth")
      @Bean
      public OAuth2RestTemplate restTemplate(@Qualifier("resourceDetails") ClientCredentialsResourceDetails resourceDetails) {
      return new OAuth2RestTemplate(resourceDetails);
      }


      I saw the below in the documentation -




      getAccessToken public OAuth2AccessToken getAccessToken()
      throws UserRedirectRequiredException



      Acquire or renew an access token for the current context if necessary.
      This method will be called automatically when a request is executed
      (and the result is cached), but can also be called as a standalone
      method to pre-populate the token.











      share|improve this question
















      I see the below restTemplate being used for fetching OAuth token. I don't see any explicit call to cache the token in my application. However I see the same token value being returned by this template. Does OAuth2RestTemplate inherently implement client side caching? If so , does it make an explicit call to the OAuth2 endpoint when the token expires?



      @Qualifier("oauth")
      @Bean
      public OAuth2RestTemplate restTemplate(@Qualifier("resourceDetails") ClientCredentialsResourceDetails resourceDetails) {
      return new OAuth2RestTemplate(resourceDetails);
      }


      I saw the below in the documentation -




      getAccessToken public OAuth2AccessToken getAccessToken()
      throws UserRedirectRequiredException



      Acquire or renew an access token for the current context if necessary.
      This method will be called automatically when a request is executed
      (and the result is cached), but can also be called as a standalone
      method to pre-populate the token.








      java spring spring-boot






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 19:11







      Punter Vicky

















      asked Nov 21 '18 at 19:02









      Punter VickyPunter Vicky

      3,9582179146




      3,9582179146
























          1 Answer
          1






          active

          oldest

          votes


















          2














          it's clearly said that the token is cached in the context (DefaultOAuth2ClientContext object) created when defining a resource. however, the token is managed by calling getAccessToken(). here is what the Docs says about getAccessToken():




          Acquire or renew an access token for the current context if necessary.
          This method will be called automatically * when a request is
          executed (and the result is cached), but can also be called as a
          standalone method to * pre-populate the token.




          the token is cached until it's Expired, then it will be renewed automatically. this snippet of code from getAccessToken() describes it:



          if (accessToken == null || accessToken.isExpired()) {
          try {
          accessToken = acquireAccessToken(context);
          }


          About Caching mechanism, By default spring provides an in-memory caching




          DefaultOAuth2ClientContext




          but you can provide your own implementation of




          OAuth2ClientContext







          share|improve this answer


























          • Thanks @slimane , that's what I saw in the documentation as mentioned in my question. Do you know how long it is cached , when it is refreshed and what happens when token expires?

            – Punter Vicky
            Nov 21 '18 at 19:52











          • @PunterVicky edited the answer

            – stacker
            Nov 21 '18 at 20:01











          • Thanks @slimane , does it cache in memory of the app.

            – Punter Vicky
            Nov 21 '18 at 20:03











          • @PunterVicky I included that in my answer ;)

            – stacker
            Nov 21 '18 at 20:11











          • Thanks @slimane

            – Punter Vicky
            Nov 21 '18 at 20:20











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418928%2foauth2resttemplate-client-side-caching%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          it's clearly said that the token is cached in the context (DefaultOAuth2ClientContext object) created when defining a resource. however, the token is managed by calling getAccessToken(). here is what the Docs says about getAccessToken():




          Acquire or renew an access token for the current context if necessary.
          This method will be called automatically * when a request is
          executed (and the result is cached), but can also be called as a
          standalone method to * pre-populate the token.




          the token is cached until it's Expired, then it will be renewed automatically. this snippet of code from getAccessToken() describes it:



          if (accessToken == null || accessToken.isExpired()) {
          try {
          accessToken = acquireAccessToken(context);
          }


          About Caching mechanism, By default spring provides an in-memory caching




          DefaultOAuth2ClientContext




          but you can provide your own implementation of




          OAuth2ClientContext







          share|improve this answer


























          • Thanks @slimane , that's what I saw in the documentation as mentioned in my question. Do you know how long it is cached , when it is refreshed and what happens when token expires?

            – Punter Vicky
            Nov 21 '18 at 19:52











          • @PunterVicky edited the answer

            – stacker
            Nov 21 '18 at 20:01











          • Thanks @slimane , does it cache in memory of the app.

            – Punter Vicky
            Nov 21 '18 at 20:03











          • @PunterVicky I included that in my answer ;)

            – stacker
            Nov 21 '18 at 20:11











          • Thanks @slimane

            – Punter Vicky
            Nov 21 '18 at 20:20
















          2














          it's clearly said that the token is cached in the context (DefaultOAuth2ClientContext object) created when defining a resource. however, the token is managed by calling getAccessToken(). here is what the Docs says about getAccessToken():




          Acquire or renew an access token for the current context if necessary.
          This method will be called automatically * when a request is
          executed (and the result is cached), but can also be called as a
          standalone method to * pre-populate the token.




          the token is cached until it's Expired, then it will be renewed automatically. this snippet of code from getAccessToken() describes it:



          if (accessToken == null || accessToken.isExpired()) {
          try {
          accessToken = acquireAccessToken(context);
          }


          About Caching mechanism, By default spring provides an in-memory caching




          DefaultOAuth2ClientContext




          but you can provide your own implementation of




          OAuth2ClientContext







          share|improve this answer


























          • Thanks @slimane , that's what I saw in the documentation as mentioned in my question. Do you know how long it is cached , when it is refreshed and what happens when token expires?

            – Punter Vicky
            Nov 21 '18 at 19:52











          • @PunterVicky edited the answer

            – stacker
            Nov 21 '18 at 20:01











          • Thanks @slimane , does it cache in memory of the app.

            – Punter Vicky
            Nov 21 '18 at 20:03











          • @PunterVicky I included that in my answer ;)

            – stacker
            Nov 21 '18 at 20:11











          • Thanks @slimane

            – Punter Vicky
            Nov 21 '18 at 20:20














          2












          2








          2







          it's clearly said that the token is cached in the context (DefaultOAuth2ClientContext object) created when defining a resource. however, the token is managed by calling getAccessToken(). here is what the Docs says about getAccessToken():




          Acquire or renew an access token for the current context if necessary.
          This method will be called automatically * when a request is
          executed (and the result is cached), but can also be called as a
          standalone method to * pre-populate the token.




          the token is cached until it's Expired, then it will be renewed automatically. this snippet of code from getAccessToken() describes it:



          if (accessToken == null || accessToken.isExpired()) {
          try {
          accessToken = acquireAccessToken(context);
          }


          About Caching mechanism, By default spring provides an in-memory caching




          DefaultOAuth2ClientContext




          but you can provide your own implementation of




          OAuth2ClientContext







          share|improve this answer















          it's clearly said that the token is cached in the context (DefaultOAuth2ClientContext object) created when defining a resource. however, the token is managed by calling getAccessToken(). here is what the Docs says about getAccessToken():




          Acquire or renew an access token for the current context if necessary.
          This method will be called automatically * when a request is
          executed (and the result is cached), but can also be called as a
          standalone method to * pre-populate the token.




          the token is cached until it's Expired, then it will be renewed automatically. this snippet of code from getAccessToken() describes it:



          if (accessToken == null || accessToken.isExpired()) {
          try {
          accessToken = acquireAccessToken(context);
          }


          About Caching mechanism, By default spring provides an in-memory caching




          DefaultOAuth2ClientContext




          but you can provide your own implementation of




          OAuth2ClientContext








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 20:10

























          answered Nov 21 '18 at 19:49









          stackerstacker

          1,841229




          1,841229













          • Thanks @slimane , that's what I saw in the documentation as mentioned in my question. Do you know how long it is cached , when it is refreshed and what happens when token expires?

            – Punter Vicky
            Nov 21 '18 at 19:52











          • @PunterVicky edited the answer

            – stacker
            Nov 21 '18 at 20:01











          • Thanks @slimane , does it cache in memory of the app.

            – Punter Vicky
            Nov 21 '18 at 20:03











          • @PunterVicky I included that in my answer ;)

            – stacker
            Nov 21 '18 at 20:11











          • Thanks @slimane

            – Punter Vicky
            Nov 21 '18 at 20:20



















          • Thanks @slimane , that's what I saw in the documentation as mentioned in my question. Do you know how long it is cached , when it is refreshed and what happens when token expires?

            – Punter Vicky
            Nov 21 '18 at 19:52











          • @PunterVicky edited the answer

            – stacker
            Nov 21 '18 at 20:01











          • Thanks @slimane , does it cache in memory of the app.

            – Punter Vicky
            Nov 21 '18 at 20:03











          • @PunterVicky I included that in my answer ;)

            – stacker
            Nov 21 '18 at 20:11











          • Thanks @slimane

            – Punter Vicky
            Nov 21 '18 at 20:20

















          Thanks @slimane , that's what I saw in the documentation as mentioned in my question. Do you know how long it is cached , when it is refreshed and what happens when token expires?

          – Punter Vicky
          Nov 21 '18 at 19:52





          Thanks @slimane , that's what I saw in the documentation as mentioned in my question. Do you know how long it is cached , when it is refreshed and what happens when token expires?

          – Punter Vicky
          Nov 21 '18 at 19:52













          @PunterVicky edited the answer

          – stacker
          Nov 21 '18 at 20:01





          @PunterVicky edited the answer

          – stacker
          Nov 21 '18 at 20:01













          Thanks @slimane , does it cache in memory of the app.

          – Punter Vicky
          Nov 21 '18 at 20:03





          Thanks @slimane , does it cache in memory of the app.

          – Punter Vicky
          Nov 21 '18 at 20:03













          @PunterVicky I included that in my answer ;)

          – stacker
          Nov 21 '18 at 20:11





          @PunterVicky I included that in my answer ;)

          – stacker
          Nov 21 '18 at 20:11













          Thanks @slimane

          – Punter Vicky
          Nov 21 '18 at 20:20





          Thanks @slimane

          – Punter Vicky
          Nov 21 '18 at 20:20




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418928%2foauth2resttemplate-client-side-caching%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?