I need to call my partner API which is OAuth enabled. Before calling the actual service,
I need to call the token generation service and with that access_token, I have to call the original service. My question is how to reuse the access_token, which is having 1 day of expiry in time. and how to check the validity of the token and where can I save the token? If the token is valid, I don't want to call the token service, if not I have to call the token service. Please suggest.
What I understand is that when you say "I have to call the original service", you mean to imply that you will configure Apigee Edge to call the original service. In other words Apigee Edge will act as the client to the IDP and to the original service.
If so, then Yes, this is a common pattern. Here is what I recommend:
The flow will be something like this:
@Dino - Thanks for your reply. Currently my api is working with every time calling the external IDP to get the token using Service callout. I am clear to use the populate cache to store the access key and Lookup cache to retrieve/assign the cache value to a variable. But I am not sure about the Route Rule, If the cache key is not available to call the service Callout otherwise call the Endpoint proxy service? Please Suggest.
I think you want to use the ServiceCallout as a normal policy. There is no special RouteRule required. The target is always the same, so you should be able to use one RouteRule with no Condition. The only thing that varies is the set of policies that runs BEFORE the target gets invoked. In the case where the token is in cache, then ... the flow will not invoke ServiceCallout. In the opposite case, then the flow will invoke ServiceCallout (and the other policies I mentioned above).
Mohana - you can put a <Condition> that evaluates the cachehit variable after the LookupCache poilcy is called or simply check for the value of the variable you are using to retrieve the cached token. If the cachehit = false, then implement the steps above to make the ServiceCallout JS, PopulateCache,... else if true called the target backend service with the token found in the cache.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |