ubuntu / authd

Authentication daemon for external Brokers
GNU Lesser General Public License v3.0
112 stars 10 forks source link

Also refresh non-expired token during login (when not in offline mode) #614

Open adombeck opened 1 week ago

adombeck commented 1 week ago

As explained in this code comment, we should ideally always refresh the token during login when online, not only when the token is expired. We didn't see a way to do that with the golang.org/x/oauth2 package, but I found one now:

We can set the token expiry date to a date in the past before calling oauth2.Config.TokenSource:

cachedInfo.Token.Expiry = time.Now().Add(-time.Hour)
tok, err := session.authCfg.oauth.TokenSource(timeoutCtx, cachedInfo.Token).Token()
shiv-tyagi commented 5 days ago

Hi @adombeck! Can you please assign this to me? I am new here and I really want to contribute to the project. This issue seems to be a good issue to start with.

Thanks in advance!

adombeck commented 5 days ago

@shiv-tyagi Sure, thanks for taking the initiative! :)

shiv-tyagi commented 5 days ago

@adombeck Thanks! Just a small question! I read the docs to setup the development environment. I could not figure out how to get a ms entra id test environment for development. How do you do the testing? Is there any work around for that?

adombeck commented 5 days ago

You need a Microsoft Entra tenant. I found this documentation on how to set up a free Microsoft Entra tenant for development, but I didn't try it out.

shiv-tyagi commented 4 days ago

I managed to get an Entra tenant. Thanks for your help. I have created a PR. Please let me know the steps ahead. Really happy to submit my first PR involving functional changes to authd. 🤩