-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Object ref not set to instance" from AuthServices/Acs with idp-initiated request #319
Comments
What Authservices-version are you running? |
Looks like v0.13.0 -- should I upgrade first then try it again? |
I don't expect it to make any difference, but we won't try to fix anything that can't be reproduced in the latest version. |
I'll try doing this tomorrow at the latest. Thanks for the reply. |
It could be something missing in the SAML2 response. You can check with https://addons.mozilla.org/sv-se/firefox/addon/saml-tracer/ to see if you get any assertions. |
I think I've got some good info for you -- hoping it helps us track this down, at any rate. With the PDB's, I was able to get a more detailed error -- it's an Object Ref problem on line 27 of AuthenticationHandler.cs.
I'm not sure if it was result or result.Location that's the null ref, but it's one of those two almost certainly. I also grabbed a saml trace using the saml-tracer you suggested. (I had to just choose an image for this since I couldn't upload a text file -- the SAML tab looks like it's got good stuff in it, but I'm less familiar about what to look for here -- if there's something specific you want to see, let me know). Any thoughts based on this new info? Thanks a ton - |
Thanks @dahlsailrunner for your detailed error description. Looks like this might be the same as #248, but I'm not sure. Something is obviously not quite right with the Owin ReturnUrl handling. |
Hmmm. I was looking at the code a bit, and discovered that in the AcsCommand file the returned CommandResult can set the location to the SPOptions.ReturnUrl, which I can configure inside my Startup.cs within my IdSrv implementation. Maybe I should set that to something? Ultimately, I need to POST an id_token to my application's login page which will send the user on their way -- but the id_token needs to include custom claims that my UserService will retrieve, so I think my redirectUrl would have to be someplace in my identity server where I can take the Okta identity that you've authenticated and then do my thing with it -- basically my UserService's AuthenticateExternalAsync. Does this sound like it might keep us moving? Any new thoughts or is it still something needing further review? Maybe I need to create some kind of custom endpoint in IdServer? |
I got something working! If you have a sec, I'd really appreciate you telling me if this is appropriate or not - I fear something like the nonce or state might not be correct. If the user is initiating a login request FROM THEIR IdP, they must be already logged in to it. Knowing that, I made IdSrv a "client" and constructed an Oauth2 client url that uses the okta idp. So when Kentor redirects to THAT url, it attempts to sign the user in from okta -- which they are already logged into, so it gets back into the Id Server and my custom user service and they get redirected to my application site. The code below does work, but I'm wondering since that is in Startup -- if I'm getting a more persistent nonce and state than I would really like. Any thoughts on this? Once I get something squared away, I can update the documentation as I did before. This code is in the Startup.cs for my IdentityServer3.
|
Yes, when doing unsolicited authn responses (i.e. idp initiatied), the SPOptions.ReturnUrl must be set, as that is where the user is redirected after successful authentication. I think that the flow is working and that you've overcome most obstacles, but the concern that the nonce and state is reused is valid. I think it opens up for a XSRF attack. If you haven't seen it, you might also want to look IdentityServer/IdentityServer3#833 and see what they have done. |
- Better exception that describes what to do, instead of getting a NullReferenceException further downstream. - Made returnUrl in the configuration non-required. If using only SP-initiated login, it is not used. - Inspired by discussion in #319.
I think I've got the right answer now - thanks to your help and the other post you referred me to. I had seen that before but not really put two and two together until this morning. Woo hoo! |
@AndersAbel excellent work with the improved error message in ef5c5a6 |
@albinsunnanbo I think that more error messages could benefit from a rewrite. I read a blog post some time ago that said that exception messages should be written for a developer - not for an end user. So see this as one of my first attempts to use that approach. |
Hi Anders and Albin - I just created a PR for updated documentation to get this all working. I also have a diagram that I could include if you think it's worth it. For now, though maybe just the text and code I thought. Let me know what you think. |
Hi,
And in IdP_InitiatedRedirect.aspx.cs
I do see Kentor. cookie hence till Id3->signInMessage.IdP.IsPresent() is fine but context.Authentication.GetAuthenticationTypes() does not giving KentorAuthServices; not able to understand how to change to "KentorAuthServices". pls help. |
It might be in your client configuration within id server. can you provide Clients.cs code here? You might have limited the idp's to idsrv or something. Your code above looks fine to me but obviously is not wrking for some reason. A fiddler trace might help point you in the right direction to -- namely where the issue might be rooted. |
thanks for reply; my client.cs |
If you're still having trouble, I suggest getting the identity server logs going so that you can review in more detail what it's complaining about -- namely which identity provider is it saying has not been configured? A fiddler or f12 network trace would also likely help -- to see what url and query string are being passed into identity server when it fails. And have you been able to sign in via Okta using a non-idp-initiated flow? I'm no saml expert here but I think the error is more related to the open-id connect handshakes that are trying to take place. |
Thanks for reply Dahls; Yes I am still facing the same issue; i already mentioned in my prev comment about the missing Idp as "context.Authentication.GetAuthenticationTypes() does not giving KentorAuthServices"; so I went inside and found that the IdP_InitiatedRedirect.aspx does not create unsolicitated response for okta; the request goes as below::: Id3RequireSSLMiddleWare->ConfigureRequestId->Configure Id3 BaseUrl->ConfigureIdentityServerIssuer->ConfigureRenderLoggedOutPage->UseAutofacMiddleware->ConfigureCookieAuthentication->ConfigureSignOutMessageCookie --->AuthorizeEndPoint Get->ProcessRequestAsync->ValidateAsync->Login->Found KentorAuthServices as signInMessage.IdP.IsPresent()->LoginExternal() and here context.Authentication.GetAuthenticationTypes() gives idsrv, idsrv.external, idsrv.partial in list; also I can see 3(sometimes 4) cookies now as SignInMessage.xxxxxxxx-> and then RenderError "UnExpected error occured" Hence I am sure I am doing basic mistake as ApplyResponseChallenge(302) in kentor should be called as 401 then only saml response would get generated. it is aspnetidentity stuff (to make a aspx page as authorize) which I am missing. For Okta I didnot try non-idp flow (which SP flow); bcoz first the response itself should get generated and yes you are correct in "error is more related to the open-id connect handshakes"; becoz I am also trying Id3 Mvc Auth sample for Idp flow (just Kentor stub as Idp) and there it reaches till Id3 Login and then it finds var authResult = preAuthContext.AuthenticateResult as somer user info and then RenderLoginPage() ; so I see Id3 Login page with my Kentor as external auth; if you have some pointer pls share. Thanks |
Hi - I'm trying to get an IdP-initiated request to work with Okta and IdentityServer3, and overcame the error where "unsolicited requests" were not supported with the following code:
Now I have okta set to send the request here to the AuthServices/Acs endpoint, but I get the following error:
I've included an image below of some of the config within Okta -- I'm wondering if I need a different endpoint configured for the DestinationUrl or something (based on the Okta docs, it doesn't seem like this should be different)? Ultimately I want to get into my custom IdentityServer3 UserService so that I can do my claims transformation and redirect the user to the real destination page (the "home" page of my real site -- not within id server), but it gets stuck in the AuthServices endpoint. Can you give me any guidance that might help move me along? Maybe I need some additional code in a callback somewhere?
By the way, I'll be happy to update the documentation with anything that I discover to get this working. :)
Thanks in advance -
Erik
The text was updated successfully, but these errors were encountered: