How to save the Authentication Token

3 posts, 0 answers
  1. Daniel
    Daniel avatar
    9 posts
    Member since:
    Dec 2014

    Posted 10 Dec 2014 Link to this post

    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. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 11 Dec 2014 Link to this post

    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.
     
  3. Daniel
    Daniel avatar
    9 posts
    Member since:
    Dec 2014

    Posted 11 Dec 2014 in reply to Anton Dobrev Link to this post

    Ah, works perfect!

    Thanks Anton,

    Daniel
Back to Top