Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

ACS problem restoring authentication using AccessToken after restart app

$
0
0

While working with the 3-Legged authentication I succeeded in using secureCreate and secureLogin. The user is created and I receive an AccessToken. After that I could create Posts. So far so good.

I read in the Cloud documentation that I can restore authentication in a new run of the app, by setting

Cloud.accessToken = saved_token
and after that I would be able to call the cloud API, in my case the code to create a Post. But this generarated a 'User not Authenticated' error. The saved_token has the correct string value.

I tried to use the Cloud.setAccessToken(saved_token) instead, but that function seems to be undefined.

I might be missing something, but I can't find other examples.

Anyone got restoring the authentication working after restart? I'm running latest Titanium (3.1.3) creating an Iphone app. Android version not tested yet.

Nico de Groot

[Docs] (http://docs.appcelerator.com/cloud/latest/#!/guide/titanium)

After a successful login, the OAuth access token is available in Cloud.accessToken. If desired, you can persist this value in a secure method and restore it when the application restarts. For example:

// Method for storing token is application-specific
var token = getMyStoredAccessToken();
if (token) {
    // restore access token
    Cloud.accessToken = token;
    // make more Cloud API calls.
    doMyCloudStuff();
} else {
    // need to log in.
    Cloud.Users.secureLogin({
        title : "Log in to NiftyApp",
    }, function(e) {
        if (e.success) {
            setMyStoredAccessToken(Cloud.accessToken, Cloud.expiresIn);
            doMyCloudStuff();
        } else {
            // handle error 
        }
    });
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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