This is a migrated thread and some comments may be shown as answers.

How to save the Authentication Token

2 Answers 162 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Daniel
Top achievements
Rank 1
Daniel asked on 10 Dec 2014, 11:32 PM
HI,

I am working on a web app connected to the back end. Authentication is fine when logging in but as this is not a single page app when a new page loads the authentication is lost, obviously down to scripts reloading.

If I save the access token as a cookie, is there a way to tell the api to reuse that token?

The only other thing I can think of is using ajax to load the other pages into view so the instance is kept alive.

Any ideas would be great.

Thanks,
Daniel

2 Answers, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 11 Dec 2014, 08:41 AM
Hi Daniel,

If you are using the JavaScript SDK of Backend Services you can set the token as the value of the token parameter in the Everlive constructor:
var el = new Everlive({
    apiKey: 'YOUR_API_KEY',
    scheme: 'https',
    token: 'ACCESS_TOKEN_HERE'
});

In order to handle the user session management completely, use the el.Users.currentUser() method to verify if the user is still logged-in.

If you need to use the REST API with AJAX calls, send the following header with the request
Authorization: Bearer ACCESS_TOKEN_HERE

and retrieve the current user as explained here.

Let me know if this helps and if you have further questions.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Daniel
Top achievements
Rank 1
answered on 11 Dec 2014, 11:17 AM
Ah, works perfect!

Thanks Anton,

Daniel
Tags
JavaScript SDK
Asked by
Daniel
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or