Code Monkey home page Code Monkey logo

Comments (6)

mark-szabo avatar mark-szabo commented on August 27, 2024

@Mrcl1450 sorry for not getting back to you earlier!
Let me understand your problem!

When you restart the running app (restart the webserver, restart your computer, etc.) the server's working memory gets deleted. The users' authentication tokens are stored in this memory. If the user's browser thinks he is still logged in (the token in the user's browser is not yet expired) it won't want to re-authenticate as it thinks the token cache still contains the user's token (but it doesn't as it was cleared when the app was restarted). That's when this error gets throwed. AFAIK I have implemented that when the app gets this error, it'll automatically redirect you to the login page and re-authenticate.

What do you mean by this:

Since yesterday I can only login 1 time after restart the computer.

Mark

from aspnetcore-connect-sample.

Mrcl1450 avatar Mrcl1450 commented on August 27, 2024

Hey, thanks for answering.
That's exacly what happens but it doesn't redirect to the login page, this occur only on debug even disabling the exceptions.

Basically I mean what you said, only redirects after restart, after stopping debugging/start again it throws the error.
The only change I've done in your code was
options.Authority = $"{_azureOptions.Instance}{_azureOptions.TenantId}/v2.0";

Maybe I'm missing here something simple, I'll test in a fresh project as soon as I can.

from aspnetcore-connect-sample.

mark-szabo avatar mark-szabo commented on August 27, 2024

Ok, I'll have a look on this on the weekend. What you need to know is, that 1. this server restarting thing should not happen in production, so this is more like a dev-only problem and 2. It's recommended to use some kind of persistent storage for storing the auth tokens (like an SQL server).

from aspnetcore-connect-sample.

timmynz avatar timmynz commented on August 27, 2024

Hi Mark,

I am also experiencing the same issue and it is something that would like to resolve. I understand the cause of the issue and how it is more likely to happen in development but wouldn't it also happen after a publish to azure?

I would be happy if it would just redirect to login again when the error happens. Is it this line that is meant to be responsible for this?

await httpContext.ChallengeAsync();

I guess persisting the auth tokens would be another solution. Are there any examples for this? I have not been able to find any.

cheers

from aspnetcore-connect-sample.

mark-szabo avatar mark-szabo commented on August 27, 2024

Hi @timmynz
I've just re-checked and I was right, this was fixed in 41e6cfe
It should catch this exception and re-authenticate (redirect to login page).

case "TokenNotFound":
   await httpContext.ChallengeAsync();
   break; 

You can use an SQL server or basically any other database as a persistent storage. Just store the tokens in a new table (or collection if you are using some kind of NoSQL).

I'll close this now, but please reopen if you need more assistance from our end! :)

from aspnetcore-connect-sample.

Samywamy10 avatar Samywamy10 commented on August 27, 2024

Hi @mark-szabo , when I challenge the user they get stuck in a loop. I am thinking the authentication thinks the cookies the user has are valid so it is just redirecting them back, but the cookies aren't in the cache so then it challenges the user again etc. Any ideas?

from aspnetcore-connect-sample.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.