IdentityModel / oidc-client-js

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Apache License 2.0
2.43k stars 842 forks source link

Cookies deleted but the tokens are still in Local Storage #1384

Open deepdesai003 opened 3 years ago

deepdesai003 commented 3 years ago

Hello, this is a question.

I am using oidc client for authenticating a JS client with identity server. I have a callback html and this callback html is throwing an error every time the app is mounted and callback.html is called. ErrorResponse: login_required

This happens only when a cookies is deleted, and the local storage still contains a an unexpired token. My token is not expired, my code handles log out for token expiry.

What is the best practice, should I just suppress error? Where can I see the logs, to pinpoint the reason for the message?

Deep

callback.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script src="dist/oidc-client.min.js"></script>
    <script>
        var config = {
            response_mode: "query"
        }

        new Oidc.UserManager(config).signinRedirectCallback().then(function () {
            window.location = "/#/account-search";

        }).catch(function (e) {
            console.error(e);
        });
    </script>
</body>
</html>
brockallen commented 3 years ago

It's not clear to me the context in which you get "login_required" (silent login, automatic silent login, query session status?), but what it means is that you made a request to the authorize endpoint, the user does not have a session so they must login, and so the response failed and that error code let you know why it failed.

deepdesai003 commented 3 years ago

Even, I am not able to understand the context. Are there any logs to where I can see a more clear reason? When a user reloads the app, the callback.html is also reloaded and the script runs on it own. signinRedirectCallback() throws the error when the tokens are in local storage but cookies are somehow deleted for the site

brockallen commented 3 years ago

signinRedirectCallback() throws the error when the tokens are in local storage but cookies are somehow deleted for the site

But the error is "login_required"?

deepdesai003 commented 3 years ago

Yes, from the callback.html