Code Monkey home page Code Monkey logo

Comments (6)

alexjolig avatar alexjolig commented on June 19, 2024 2

Thanks again for your kind reply :)

from fastapi-azure-auth.

JonasKs avatar JonasKs commented on June 19, 2024 1

After authenticating the user for the first time, it won't connect to Azure AD to authenticate user for the next 24 hours

Correct.

It will keep the the public key in user's machine for 24 hours and then refresh it with a new one.

Correct, if you refer the user's machine as the machine where the backend API is hosted.

During the next 24 hours, while calling the APIs, no request would be sent to Azure AD

Correct.

😊

from fastapi-azure-auth.

JonasKs avatar JonasKs commented on June 19, 2024 1

Hi!

  1. The public key(s) can be found at the url given in the response under the jwks key. See line 86.

  2. Expiry is checked using the python-jose library. It is configured to fail for expired tokens. The behavior is also tested here. You either have disabled auth (misconfiguration), or your token is actually not expired.

  3. No, the backend only cares about access tokens. Refreshing etc. should be done by the client.

from fastapi-azure-auth.

JonasKs avatar JonasKs commented on June 19, 2024

Hi!

Thank you for the feature request. How ever, I think there's some misconceptions on how this works, so I'll try to explain it:

The configuration essentially is public keys from Azure. The JWT tokens are signed, and we can verify the JWT by using these public keys.
So, when a user does an API call to the backend, Azure is no longer involved. We only use the keys we have, and verify the JWT. In other words:

  • User does a request to backend
  • Backend use public key which is already fetched from Azure (and cached for 24 hours)
  • Backend validates JWT and decodes it, but does not talk to Azure or any other system

So to give a TL;DR:

  • We do not need to cache already authorized requests, as that would create more overhead. The decoding of token is very quick, and require no interaction with other systems.

Closing the issue, but please do not hesitate to comment or ask questions if something was unclear. 😊

from fastapi-azure-auth.

alexjolig avatar alexjolig commented on June 19, 2024

Thank you for the explanation. So for my better understanding:

  • After authenticating the user for the first time, it won't connect to Azure AD to authenticate user for the next 24 hours
  • It will keep the the public key in user's machine for 24 hours and then refresh it with a new one.
  • During the next 24 hours, while calling the APIs, no request would be sent to Azure AD

Are those correct?

from fastapi-azure-auth.

alexjolig avatar alexjolig commented on June 19, 2024

Hi @JonasKs I have a few more questions about this and I'll be thankful if you take time and answer them:

  1. I debugged this line, but couldn't find where the public key in that JSON. So how can I check it?

  2. How does this library check the expiry date of access token? I think JWT always checks it before decoding the token, but if I just keep the swagger open and try an API (which just returns the token claims) after the expiry of the token, I can see that expiry is the past but API is still return the user without throwing any error. How does that work?

  3. Is refresh token is also involved in SingleTenantAzureAuthorizationCodeBearer method and if yes, where do we keep it and when will it be used?

Thank you in advance.

from fastapi-azure-auth.

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.