asp.net-web-apioauthaccess-token

Is is safe to store access token in session storage of client browser?


I am using Token based authentication in web API to authenticate a user.I am using clients browser session storage to store access token.Is it safe to do so? Where should i store it make it safer.

$('#btnLogin').click(function() {
    $.ajax({
        // Post username, password & the grant type to /token
        url: '/token',
        method: 'POST',
        contentType: 'application/json',
        data:
            {
            username: $('#txtUsername').val(),
            password: $('#txtPassword').val(),
            grant_type: 'password'
        },
        //response(Access Token) stores inside session storage of Client browser.
        success: function(response) {
                sessionStorage.setItem("accessToken", response.access_token);

Solution

  • It is perfectly safe to use localStorage or sessionStorage to store client tokens to perform subsequent authenticated requests to your api, this, as long as you have taken good meassures in your api in place to manage that token and keep it safe:

    -

    Local or session storage storage is just as safe as a cookie, see it this way. If the client's device is compromised, cookie or local storage, the whole thing is compromised. So it won't make much of a difference at that point.