Skip to content
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

Automatic device authentication when refresh token is expired #325

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

adombeck
Copy link
Contributor

@adombeck adombeck commented Jan 17, 2025

⚠️ This is based on #349, please review and merge that first

When refreshing the token fails because the refresh token is expired, we should automatically start device authentication.

Closes ubuntu/authd#575
UDENG-4911

@adombeck adombeck force-pushed the 575-automatic-device-auth-on-expired-refresh-token branch from 5f4c4c8 to f346403 Compare January 17, 2025 16:31
@adombeck adombeck force-pushed the 575-automatic-device-auth-on-expired-refresh-token branch 2 times, most recently from 8b1f19c to d7dc1a8 Compare January 29, 2025 15:45
@adombeck
Copy link
Contributor Author

adombeck commented Feb 3, 2025

I tested this by applying this patch:

commit 49c9c3aeb2d58d7b68cebd816ebb887befb080ca (HEAD -> 575-automatic-device-auth-on-expired-refresh-token)
Author: Adrian Dombeck <[email protected]>
Date:   Mon Feb 3 15:36:36 2025 +0100

    XXX: Test expired refresh token

diff --git a/internal/broker/broker.go b/internal/broker/broker.go
index 93d0d82..193e2c8 100644
--- a/internal/broker/broker.go
+++ b/internal/broker/broker.go
@@ -810,6 +810,9 @@ func (b *Broker) updateSession(sessionID string, session session) error {
 func (b *Broker) refreshToken(ctx context.Context, oauth2Config oauth2.Config, oldToken token.AuthCachedInfo) (token.AuthCachedInfo, error) {
        timeoutCtx, cancel := context.WithTimeout(ctx, maxRequestDuration)
        defer cancel()
+
+       return token.AuthCachedInfo{}, &oauth2.RetrieveError{ErrorCode: "invalid_grant", ErrorDescription: "AADSTS50173: Refresh token is expired"}
+
        // set cached token expiry time to one hour in the past
        // this makes sure the token is refreshed even if it has not 'actually' expired
        oldToken.Token.Expiry = time.Now().Add(-time.Hour)

@adombeck
Copy link
Contributor Author

adombeck commented Feb 3, 2025

I created ubuntu/authd#774 to track the "show a message" part.

@adombeck adombeck force-pushed the 575-automatic-device-auth-on-expired-refresh-token branch from d7dc1a8 to fdb7f96 Compare February 3, 2025 15:04
@adombeck adombeck marked this pull request as ready for review February 3, 2025 15:10
@adombeck adombeck requested a review from a team as a code owner February 3, 2025 15:10
@adombeck adombeck force-pushed the 575-automatic-device-auth-on-expired-refresh-token branch from fdb7f96 to a3a8712 Compare February 4, 2025 10:09
Copy link
Member

@denisonbarbosa denisonbarbosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some considerations, but nothing big...

internal/broker/broker_test.go Outdated Show resolved Hide resolved
internal/broker/broker_test.go Show resolved Hide resolved
The firstSelectedMode was set but never used.
The decision which authentication modes are offered is (currently) not
provider-specific. Lets make the interface simpler until we actually
have a need to make it provider-specific.
In preparation for supporting device authentication as the next auth
mode.
For consistency
@adombeck adombeck force-pushed the 575-automatic-device-auth-on-expired-refresh-token branch from a3a8712 to 6cd19a6 Compare February 5, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants