Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Error: No state in response #780

Closed
wurst0815 opened this issue Feb 25, 2019 · 11 comments
Closed

Error: No state in response #780

wurst0815 opened this issue Feb 25, 2019 · 11 comments

Comments

@wurst0815
Copy link

Hi,

maybe this is a stupid question, but I am currently not able to get oidc-client running with Azure Active Directory. To me it seems to be fine as the callback happens and has all parameters, but in my callback.html I constantly get the error no state in response.

I am using implicit flow, so my config looks like this:
var config = { authority: "https://login.microsoftonline.com/v2.0", client_id: "anyid", redirect_uri: "http://localhost:5003/callback.html", response_type: "id_token", scope: "openid profile", post_logout_redirect_uri: "http://localhost:5003/index.html" };

And my callback.html looks like this (taken from Identity Server JS Client example).
new Oidc.UserManager({response_mode:"query"}).signinRedirectCallback().then(function() { window.location = "index.html"; }).catch(function(e) { console.error(e); });

I don't know if the response_mode 'query' is necessary or if not, or if I have to use another response_mode. The callback looks like this
callback.html#id_token=verylongtoken&state=554e511e3972439e8355bffc52370a0f&session_state=37cd64fe-789f-4dda-a675-00530138ba36

Thanks

@pedro-pedrosa
Copy link

Also getting "No state in response" error. This is probably related to the signinRedirectCallback() promise being resolved before the state is parsed from the URL.

I'm using react router, which modifies the URL instead of requesting another page to be loaded.

This code:

const mgr = new UserManager({
    response_mode: 'query',
});
mgr.signinRedirectCallback()
    .then(user => {
        console.log(user);
    })
    .catch(error => {
        console.error(error);
    });

triggers the error after the user object is logged to the console, which suggests that the promise is resolved before all work is finished.

This, however, doesn't trigger an error (which is similar to the quickstarts code):

const mgr = new UserManager({
    response_mode: 'query',
});
mgr.signinRedirectCallback()
    .then(user => {
        console.log(user);
        window.location.href = 'http://localhost:3000';
    })
    .catch(error => {
        console.error(error);
    });

@nyghtrocker
Copy link

Hi, also getting this error only if I will use {response_mode:"query"}.
I'm using vanilla javascript and here is working code:
new Oidc.UserManager().signinRedirectCallback().then(function (user) {
if (user == null) {
document.getElementById("waiting").style.display = "none";
document.getElementById("error").innerText = "No sign-in.";
}
else {
window.location = "/Indicator/Indicators";
}
}).catch(function (e) {
console.error(e);
document.getElementById("waiting").style.display = "none";
document.getElementById("error").innerText = e.message;

    });

@brockallen
Copy link
Member

If you're using code flow and the call back is on a different page than your normal UserManage config, then you need to explicitly add {response_mode:"query"} on the options on the callback page.

If the UserManager on the calmlback page has the response_mode set then it will know the right place to look for the response params.

@wurst0815
Copy link
Author

No I am using Implicit Flow but with a specific callback page (different than the originator).
So there is no response_mode necessary on the UserManager on the callback page?
But it doesn't work either with response_mode set or not.

@pedro-pedrosa
Copy link

@brockallen note that in both my snippets I'm using the same configuration on the same page, the first throws the No state in response error after console.log(user); which suggests something is wrong with the code base.

The second snippet doesn't throw an error for some reason? Is the state variable not being checked at all before the redirect which eats up the error?

@brockallen
Copy link
Member

If the config is the same on the 2 pages, then there's an issue in your hosting perhaps? A common issue is that you're mixing http and https. If it's not that, then you will have to debug into it more.

@brockallen
Copy link
Member

Closing. If you still have issues, feel free to reopen.

@Manimall
Copy link

If you're using code flow and the call back is on a different page than your normal UserManage config, then you need to explicitly add {response_mode:"query"} on the options on the callback page.

If the UserManager on the calmlback page has the response_mode set then it will know the right place to look for the response params.

not works for me(

@EricHerlitz
Copy link

EricHerlitz commented Mar 4, 2020

@Manimall In my case removing response_mode: 'query' on the callback-page actually solved the issue

@wzup
Copy link

wzup commented Mar 31, 2020

@Manimall Your solution solved the issue

What is that response_mode: 'query'anyway? There is no even info about it in their docs!
My question about this piece of misapprehension #1078

@Manimall
Copy link

Manimall commented Apr 2, 2020

@EricHerlitz lucky you are!)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

7 participants