Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70803

oauth2 API calls and refreshing tokens (chaining observables?)

$
0
0

@bholub1 wrote:

I'm writing an OAuth2 API client. Before making an API call I want to check the age of the access token and, if expired, get a new token with a refresh token. So, some code:

page calls something like (WAC is api client):

this.WAC.call('getDailyData', {
date: '2016-02-01',
gid: 3824
})
.subscribe(
response => {
console.log("DO STUFF WITH RESPONSE");
},
err => {
console.log("FAILED TO GET DAILY DATA: ", err);
}
);

wac.ts

call(method, params) {
...
return this.http.post(url, body, options)
.map(res => res.json());
}

The above works just great if the access_token is still valid. However, if it's no longer valid I need to make another http request to refresh the token. What's the best way to do this? Is there a way to "interrupt" the process, go refresh the token, and then continue with the call() method to make the API call. Or do I need to return the observable from the refresh_token request and check the response on the subscribe method to determine if the token was just refreshed so then I can re-request the API call? I hope that makes sense.

Thanks,
Brian

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70803

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>