OAuth2RestTemplate - Client Side Caching
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
add a comment |
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
add a comment |
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
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
java spring spring-boot
edited Nov 21 '18 at 19:11
Punter Vicky
asked Nov 21 '18 at 19:02
Punter VickyPunter Vicky
3,9582179146
3,9582179146
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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