-
Notifications
You must be signed in to change notification settings - Fork 369
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
[WIP] Feature - Identity verification implementation #2196
base: main
Are you sure you want to change the base?
Conversation
a6e4349
to
ff50c7d
Compare
95c6162
to
8931712
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of my feedback was added inline, but I have one additional comment that wasn't clear if it is TODO yet or not. Is the new JWT endpoint to remove email and SMS by token still TODO in this PR, or did I miss it?
OneSignal.getNotifications().requestPermission(true, Continue.none()); | ||
//OneSignal.getNotifications().requestPermission(true, Continue.none()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert before merging.
// !!! For manual testing only | ||
String jwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMTM5YmQ2Zi00NTFmLTQzOGMtODg4Ni00ZTBmMGZlM2EwODUiLCJleHAiOjE3MjczNjkyMjIsImlkZW50aXR5Ijp7ImV4dGVybmFsX2lkIjoiamluIn0sInN1YnNjcmlwdGlvbnMiOlt7InR5cGUiOiJFbWFpbCIsInRva2VuIjoidGVzdEBkb21haW4uY29tIn0seyJ0eXBlIjoiU01TIiwidG9rZW4iOiIrMTIzNDU2NzgifSx7InR5cGUiOiJBbmRyb2lkUHVzaCIsImlkIjoiMTIzZTQ1NjctZTg5Yi0xMmQzLWE0NTYtNDI2NjE0MTc0MDAwIn1dfQ.6XF7wRF4lLOvKr5Gd3MHv9j7U151hcBjmqSyk6nI6JVYUgt6q0YRp2j1aSJcg8VmaejzP1DouN1DpWUT_JTRXA"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove manual testing before merging.
if (update != null && !update.isEmpty()) { | ||
OneSignal.updateUserJwt(OneSignal.getUser().getExternalId(), update); | ||
//String jwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxNjg4ZDhmMi1kYTdmLTQ4MTUtOGVlMy05ZDEzNzg4NDgyYzgiLCJpYXQiOjE3MTQwODA4MTMsImlkZW50aXR5Ijp7ImV4dGVybmFsX2lkIjoiMjAyNDA0MjUtYWxleDQyIn0sInN1YnNjcmlwdGlvbiI6W3sidHlwZSI6IiIsImlkIjoiMmRlZGU3MzItMTEyNi00MTlkLTk5M2UtNDIzYWQyYTZiZGU5In1dfQ.rzZ-HaDm1EwxbMxd8937bWzPhPSQDDSqSzaASgZZc5A5v8g6ZQHizN9CljOmoQ4lTLm7noD6rOmR07tlZdrI5w"; | ||
//OneSignal.login(update, jwt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented out code
return getSharedPreference(context).getString(OS_APP_ID_SHARED_PREF, "77e32082-ea27-42e3-a898-c72e141824ef"); | ||
return getSharedPreference(context).getString(OS_APP_ID_SHARED_PREF, "0139bd6f-451f-438c-8886-4e0f0fe3a085"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert app_id change
@@ -0,0 +1,16 @@ | |||
package com.onesignal | |||
|
|||
/** TODO: complete the comment part for this listener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address TODO
var jwtToken: String? | ||
get() = getOptStringProperty(IdentityConstants.JWT_TOKEN) | ||
set(value) { | ||
setOptStringProperty(IdentityConstants.JWT_TOKEN, value, ModelChangeTags.NO_PROPOGATE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we want to propagate?
) | ||
) { | ||
fun invalidateJwt() { | ||
model.jwtToken = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The jwtToken has two invalidate states; blank string and null. Can we set this to null
here so we don't have to worry about a blank string state?
@@ -42,10 +42,12 @@ internal class LoginUserFromSubscriptionOperationExecutor( | |||
|
|||
private suspend fun loginUser(loginUserOp: LoginUserFromSubscriptionOperation): ExecutionResponse { | |||
try { | |||
// Not allowed when identity verification is on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this whole class is not used when identity verification is on, so we should move and rework it to fit that.
@@ -82,8 +84,10 @@ internal class LoginUserFromSubscriptionOperationExecutor( | |||
return when (responseType) { | |||
NetworkUtils.ResponseStatusType.RETRYABLE -> | |||
ExecutionResponse(ExecutionResult.FAIL_RETRY) | |||
NetworkUtils.ResponseStatusType.UNAUTHORIZED -> | |||
NetworkUtils.ResponseStatusType.UNAUTHORIZED -> { | |||
_identityModelStore.invalidateJwt() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we call this _identityModelStore.invalidateJwt()
in every executor, do you think it would work out to have the OperationRepo process ExecutionResult.FAIL_UNAUTHORIZED
so it is the only one calling invalidateJwt()
?
@@ -160,7 +164,18 @@ internal class LoginUserOperationExecutor( | |||
|
|||
try { | |||
val subscriptionList = subscriptions.toList() | |||
val response = _userBackend.createUser(createUserOperation.appId, identities, subscriptionList.map { it.second }, properties) | |||
val pushSubscription = subscriptions.values.find { it.type == SubscriptionObjectType.ANDROID_PUSH } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This SDK supports fireOS and Huawei push so you will need a more complete check. However, since this looks like it is for Device Auth then we can remove it.
- That is, once we have 100% committed to that path, so hold on addressing this comment until then.
8931712
to
ffa634a
Compare
…tions that have no valid JWT
ffa634a
to
db78c39
Compare
Description
One Line Summary
Implement identity verification functionality to our Android SDK with JWT (JSON Web Token) that manage a specific User, their Subscriptions, and Identities, if enabled using OneSignal dashboard.
Details
Motivation
OneSignal Identity Verification feature only exists today for the Player model and we want to bring this feature to the User Model and gives us an opportunity to switch to a more standard client security model, JWT (JSON Web Token).
For Developers
If identity verification is enabled, all operations requiring identity or authorization must be accompanied by a correct JWT. Developers can use OneSignal.login(external_id, jwt) to set a JWT for a specific user identified by their external ID, or OneSignal.updateUserJwt(external_id, jwt) to update the JWT for that user. Additionally, developers can add a JWTInvalidatedListener by calling OneSignal.addUserJwtInvalidatedListener, allowing them to listen for a JWTInvalidatedEvent triggered when a JWT is invalidated by any operation, and subsequently update the JWT as necessary.
To Help With Review
This PR contains a some major structural changes working around identity verification.
Testing
Unit testing
I have include a testing case that simulate a UNAUTHROIZED error (401, 403) and ensure that the jwt for the specific user is invalidated and the JWTInvalidatedEvent is fired.
Manual testing
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is