6

I am developing an hybrid local app. When the access token expires I must handle the re-login process (actually, I would like to refresh the token just before it expires).

in the auth.js I've seen a quick look at how it "could" work but I didn't find any documentation about this. In particular: creds should be an object with all the credential for the oAuth process. With creds I should then call some method to refresh the tokens. For instance in auth.js to initialize the login process there is something like:

var creds = cordova.require("salesforce/plugin/oauth").getAuthCredentials();
Force.init(creds, null, null, cordova.require("salesforce/plugin/oauth").forcetkRefresh);

What is the call to refresh the token using the forcetk JS library? I've downloaded all the documentation I could find but there no "javadoc" in what I found, could you point me to one?

Thanks T.

3
+25

This document explains how sessions should be managed when using Mobile SDK (I found section "REST APIs (Including Apex2REST)" most useful).

As I don't have a working setup to run/test the code, I tried to find some trustworthy code samples for you to try out and I came across following sample app. It doesn't really tell you what the call to refresh the token is, but it seems to suggest that it is done for you elsewhere and an event is signalled when this happens, so all you need to do is handle the results by updating your forceTK configuration. Have a look at onDeviceReady() method and following 2 lines in particular:

cordova.require("salesforce/plugin/oauth").getAuthCredentials(salesforceSessionRefreshed, getAuthCredentialsError);

//register to receive notifications when autoRefreshOnForeground refreshes the sfdc session
document.addEventListener("salesforceSessionRefresh",salesforceSessionRefreshed,false);

Hope it helps.

| improve this answer | |
  • Thanks for the answer, I will look into it in detail, it looks very close to what I'm looking for:)! – T. Rossi Apr 29 '14 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.