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

Add support for auth API v2 #5305

Merged
merged 30 commits into from
Nov 27, 2024
Merged

Add support for auth API v2 #5305

merged 30 commits into from
Nov 27, 2024

Conversation

lmac012
Copy link
Contributor

@lmac012 lmac012 commented Nov 21, 2024

Task/Issue URL: https://app.asana.com/0/1205648422731273/1208821656071388/f

Description

This PR adds support for new version of the authentication API that uses OAuth 2.0 with PKCE extension. Usage of the new API is controlled via a feature flag which is currently disabled.

Steps to test this PR

See task.

No UI changes

Copy link
Contributor Author

lmac012 commented Nov 21, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@lmac012 lmac012 force-pushed the feature/lukasz/auth-v2 branch 3 times, most recently from 976f3fc to 8fb36d2 Compare November 22, 2024 11:00
@lmac012 lmac012 marked this pull request as ready for review November 22, 2024 11:01
@lmac012 lmac012 requested a review from karlenDimla November 22, 2024 11:02
@lmac012 lmac012 force-pushed the feature/lukasz/auth-v2 branch from ada3fa9 to 8f89042 Compare November 25, 2024 19:37
@@ -277,10 +327,16 @@ class RealSubscriptionsManager @Inject constructor(
}

override suspend fun signOut() {
authRepository.getAccessTokenV2()?.run {
coroutineScope.launch { authClient.tryLogout(accessTokenV2 = jwt) }
Copy link
Contributor

@karlenDimla karlenDimla Nov 26, 2024

Choose a reason for hiding this comment

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

Why are we doing coroutineScope.launch {} here? Can’t we put everything in this function in withContext(dispatcher.io()) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no need to specify io dispatcher anywhere in this method since there are no thread-blocking operations here. Calling /logout endpoint is launched in a separate coroutine just because this is a side-effect that the caller of signOut() shouldn't care for and wait for. This matters e.g., when the user taps "Remove subscription from device" in settings and we want the repository transition to the signed out state ASAP, so that the UI can be updated accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

How is the Entitlement here different from Entitlement in AuthRepository?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not different, just avoiding having a dependency between AuthRepository and AuthJwtValidator, since the latter has nothing to do with storage. Now that both of those classes live in the same module, we could extract Entitlement from AuthRepository/AuthJwtValidator and unify - I'll look into it.

val workManager: WorkManager,
) : BackgroundTokenRefresh {
override fun schedule() {
val workRequest = PeriodicWorkRequestBuilder<TokenRefreshWorker>(repeatInterval = Duration.ofDays(7))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we scheduling this work to repeat every 7 days? Access token expires every 4 hours and refresh tokens expire every month?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a compromise between the overhead of running it to often and the risk of missing the 1-month deadline to refresh. 7 days gives us a healthy buffer even if the device happens to be offline for a week or two.

Copy link
Contributor

@karlenDimla karlenDimla left a comment

Choose a reason for hiding this comment

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

Test cases passed. Also test a few more VPN scenarios and everything seemed to work as expected. Just a few comments and questions - since the PR is actually quite big.

@lmac012 lmac012 force-pushed the feature/lukasz/auth-v2 branch from 8f89042 to 414b2bd Compare November 27, 2024 15:20
@lmac012 lmac012 merged commit dcebb5b into develop Nov 27, 2024
6 checks passed
@lmac012 lmac012 deleted the feature/lukasz/auth-v2 branch November 27, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants