-
Notifications
You must be signed in to change notification settings - Fork 264
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
Fire jwt invalidated callback when receiving 401 errors #1478
Merged
nan-li
merged 34 commits into
identity_verification_get_iams
from
identity_verification_callback
Oct 4, 2024
Merged
Fire jwt invalidated callback when receiving 401 errors #1478
nan-li
merged 34 commits into
identity_verification_get_iams
from
identity_verification_callback
Oct 4, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This uses the callback in the UserExecutor only
Also adds tests for the property executor and refactors some testing code that can be shared with other executor tests
Includes tests Currently delete and update requests don't have an identity model attached. This may need to be changed for JWT
Includes tests
This will always fire it for 401 even if JWT is not required, so validate the JWT config in the user manager before firing the callback
This PR adds a pendingAuthRequests dictionary that stores the requests that are waiting for an updated JWT keyed on externalId. When a requests fails with a 401 due to JWT or fails when preparing for execution we remove the request from the request queue and add it to the pending dictionary. Once we get the onJWTUpdated callback for that externalId we requeue the pending requests and try again. Also update tests to account for the callback object change and add tests for the new case
emawby
force-pushed
the
identity_verification_callback
branch
from
September 11, 2024 21:19
10f6adc
to
f3cb3d8
Compare
When a requests fails with a 401 due to JWT or fails when preparing for execution we remove the request from the request queue and add it to the pending dictionary. Once we get the onJWTUpdated callback for that externalId we requeue the pending requests and try again. fixup property operations
When a requests fails with a 401 due to JWT or fails when preparing for execution we remove the request from the request queue and add it to the pending dictionary. Once we get the onJWTUpdated callback for that externalId we requeue the pending requests and try again.
emawby
force-pushed
the
identity_verification_callback
branch
from
September 11, 2024 23:10
6ebfcfc
to
1ae0deb
Compare
adds handling for pending unauthorized subscription executor requests. Doesn't yet handle prepare for execution properly No unit tests yet
nan-li
reviewed
Sep 24, 2024
iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift
Outdated
Show resolved
Hide resolved
iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift
Show resolved
Hide resolved
iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift
Outdated
Show resolved
Hide resolved
iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift
Outdated
Show resolved
Hide resolved
iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift
Outdated
Show resolved
Hide resolved
Run swiftlint and make a log more helpful
nan-li
force-pushed
the
identity_verification_callback
branch
6 times, most recently
from
September 26, 2024 04:55
8b95d0c
to
da4adcb
Compare
* Uncaching now involves more queues, can be refactored when op repo is refactored * Some executors added a helper to remove requests from the active queue and cache the queue after removal.
* Use a string constant `OS_JWT_TOKEN_INVALID` for a jwt token when we internally invalidated it, instead of setting to `nil`. * OSIdentityModelRepo will not notify user manager when a token has been set to `OS_JWT_TOKEN_INVALID`. The user manager will already be notified of invalidation by executors.
* The delete subscription request now has identity model, similar to the Create subscription request * The update subscription request is used only for the push sub, and it does not use User JWT, only a push token header * The "Device-Auth-Push-Token" header has to be base 64 encoded * Move some auth helpers into the JWT extension, and move execute request methods into an extension to address swiflint type_body_length violation
* OneSignalUserManagerImpl.swift violated the 1000 line file limit of Swiftlint * Options include modifing the rule but let's pull out 2 public protocols. * Additionally add more folders to organize the top-level files: MODELING for models and listeners, PUBLIC for publicly accessed objects and protocols
* Remove test on Update Subscription with JWT; it does not use User JWT * Make some changes to existing tests
nan-li
force-pushed
the
identity_verification_callback
branch
from
September 26, 2024 17:36
da4adcb
to
74e4ef7
Compare
* Remote params returns `jwt_required` as the key to use
* If logging into an external ID that already exists in the SDK, re-use that one to keep the same model.
* If multiple create user requests are enqueued for the same external ID, only keep the most recent one, and remove the previous. * These requests should all have the same identity model since they share external IDs, so only keeping the latest is adequate. * This prevents multiple Create User requests with the same external ID from being executed simultaneously, which is possible when JWT is on, as we allow future logins to be sent before past user's login succeeds. * An example of this is login(a) > login(b) > login(a) > login(b) but user A has an expired token. Once the token is updated for userA, potentially both logins could be executed if we don't prevent duplicates.
* Remove the push subscription if not current user; we don't want to transfer the push sub. * This detail is meant to handle JWT on, and previous failed user creates can be sent even though the user has changed successfully. * However, don't remove the push sub if the user is anonymous or else the create will fail. Also, when JWT is off and anonymous users can be created, this will block requests until it succeeds so there is no risk of accidentally transferring the push sub to an old user.
* Update the API for the listener, add and removal function names, event name * The listener API is OSUserJwtInvalidatedListener * The event is OSUserJwtInvalidatedEvent
* Usually, on logout, the user observer will fire once the anonymous user is created to the backend and returns with an OSID. However, when Identity Verification is on, that will not happen, so fire the observer early with `nil` values to represent there is no user in the SDK currently. * Firing the observer will save the state and necessary to know when the user logs back in. This is used by the messaging controller to fetch IAM appropriately. On a new session, it will not fetch IAM if logged out, but as the user observer, it will fetch once a user logs in.
emawby
changed the title
[WiP] Fire jwt invalidated callback when receiving 401 errors
Fire jwt invalidated callback when receiving 401 errors
Oct 3, 2024
nan-li
approved these changes
Oct 3, 2024
* Revert back to prod servers * Add app clips back
[JWT] Handle logout when Identity verification is on
…e_users [JWT] Improve management of multiple users + finalize API
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the executors don't pause trying to execute their requests, but they aren't sent because they are stopped in prepareForExecution. We can optimize to have them wait until the token has been updated.
There is also no protection against firing the invalidated callback multiple times on the same token.
Description
One Line Summary
REQUIRED - Very short description that summaries the changes in this PR.
Details
Motivation
REQUIRED - Why is this code change being made? Or what is the goal of this PR? Examples: Fixes a specific bug, provides additional logging to debug future issues, feature to allow X.
Scope
RECOMMEND - OPTIONAL - What is intended to be effected. What is known not to change. Example: Notifications are grouped when parameter X is set, not enabled by default.
OPTIONAL - Other
OPTIONAL - Feel free to add any other sections or sub-sections that can explain your PR better.
Testing
Unit testing
OPTIONAL - Explain unit tests added, if not clear in the code.
Manual testing
RECOMMEND - OPTIONAL - Explain what scenarios were tested and the environment.
Example: Tested opening a notification while the app was foregrounded, app build with Android Studio 2020.3 with a fresh install of the OneSignal example app on a Pixel 6 with Android 12.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is