-
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?
Changes from all commits
3caffc9
c588498
bf759d2
f29d0df
f8abc51
9e13707
eb525f4
76b95d0
034e9c9
af3ba8a
3b26b66
3083eae
db78c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ | |
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.multidex.MultiDexApplication; | ||
|
||
import com.onesignal.Continue; | ||
import com.onesignal.IUserJwtInvalidatedListener; | ||
import com.onesignal.OneSignal; | ||
import com.onesignal.UserJwtInvalidatedEvent; | ||
import com.onesignal.inAppMessages.IInAppMessageClickListener; | ||
import com.onesignal.inAppMessages.IInAppMessageClickEvent; | ||
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent; | ||
|
@@ -65,7 +66,7 @@ public void onCreate() { | |
// This will reproduce result similar to Kotlin CouroutineScope.launch{}, which may potentially crash the app | ||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
@SuppressLint({"NewApi", "LocalSuppress"}) CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { | ||
OneSignal.getNotifications().requestPermission(true, Continue.none()); | ||
//OneSignal.getNotifications().requestPermission(true, Continue.none()); | ||
}, executor); | ||
future.join(); // Waits for the task to complete | ||
executor.shutdown(); | ||
|
@@ -140,6 +141,16 @@ public void onUserStateChange(@NonNull UserChangedState state) { | |
} | ||
}); | ||
|
||
OneSignal.addUserJwtInvalidatedListner(new IUserJwtInvalidatedListener() { | ||
@Override | ||
public void onUserJwtInvalidated(@NonNull UserJwtInvalidatedEvent event) { | ||
// !!! For manual testing only | ||
String jwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIwMTM5YmQ2Zi00NTFmLTQzOGMtODg4Ni00ZTBmMGZlM2EwODUiLCJleHAiOjE3MjczNjkyMjIsImlkZW50aXR5Ijp7ImV4dGVybmFsX2lkIjoiamluIn0sInN1YnNjcmlwdGlvbnMiOlt7InR5cGUiOiJFbWFpbCIsInRva2VuIjoidGVzdEBkb21haW4uY29tIn0seyJ0eXBlIjoiU01TIiwidG9rZW4iOiIrMTIzNDU2NzgifSx7InR5cGUiOiJBbmRyb2lkUHVzaCIsImlkIjoiMTIzZTQ1NjctZTg5Yi0xMmQzLWE0NTYtNDI2NjE0MTc0MDAwIn1dfQ.6XF7wRF4lLOvKr5Gd3MHv9j7U151hcBjmqSyk6nI6JVYUgt6q0YRp2j1aSJcg8VmaejzP1DouN1DpWUT_JTRXA"; | ||
Comment on lines
+147
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove manual testing before merging. |
||
OneSignal.updateUserJwt(event.getExternalId(), jwt); | ||
Log.v(Tag.LOG_TAG, "onUserJwtInvalidated fired with ID:" + event.getExternalId()); | ||
} | ||
}); | ||
|
||
OneSignal.getInAppMessages().setPaused(true); | ||
OneSignal.getLocation().setShared(false); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import android.view.View; | ||
import android.view.ViewTreeObserver; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.LinearLayout; | ||
import android.widget.RelativeLayout; | ||
import android.widget.Switch; | ||
|
@@ -83,6 +84,10 @@ public class MainActivityViewModel implements ActivityViewModel, IPushSubscripti | |
private Button loginUserButton; | ||
private Button logoutUserButton; | ||
|
||
// JWT | ||
private Button invalidateJwtButton; | ||
private Button updateJwtButton; | ||
|
||
// Alias | ||
private TextView aliasTitleTextView; | ||
private RecyclerView aliasesRecyclerView; | ||
|
@@ -211,6 +216,9 @@ public ActivityViewModel onActivityCreated(Context context) { | |
loginUserButton = getActivity().findViewById(R.id.main_activity_login_user_button); | ||
logoutUserButton = getActivity().findViewById(R.id.main_activity_logout_user_button); | ||
|
||
invalidateJwtButton = getActivity().findViewById(R.id.main_activity_invalidate_jwt_button); | ||
updateJwtButton = getActivity().findViewById(R.id.main_activity_update_jwt_button); | ||
|
||
aliasTitleTextView = getActivity().findViewById(R.id.main_activity_aliases_title_text_view); | ||
noAliasesTextView = getActivity().findViewById(R.id.main_activity_aliases_no_aliases_text_view); | ||
addAliasButton = getActivity().findViewById(R.id.main_activity_add_alias_button); | ||
|
@@ -403,7 +411,8 @@ private void setupAppLayout() { | |
@Override | ||
public void onSuccess(String update) { | ||
if (update != null && !update.isEmpty()) { | ||
OneSignal.login(update); | ||
String jwt = "InitialJWT"; | ||
OneSignal.login(update, jwt); | ||
refreshState(); | ||
} | ||
} | ||
|
@@ -422,6 +431,7 @@ public void onFailure() { | |
} | ||
|
||
private void setupUserLayout() { | ||
setupJWTLayout(); | ||
setupAliasLayout(); | ||
setupEmailLayout(); | ||
setupSMSLayout(); | ||
|
@@ -430,6 +440,30 @@ private void setupUserLayout() { | |
setupTriggersLayout(); | ||
} | ||
|
||
private void setupJWTLayout() { | ||
invalidateJwtButton.setOnClickListener(v -> { | ||
OneSignal.updateUserJwt(OneSignal.getUser().getExternalId(), ""); | ||
}); | ||
updateJwtButton.setOnClickListener(v -> { | ||
dialog.createUpdateAlertDialog("", Dialog.DialogAction.UPDATE, ProfileUtil.FieldType.JWT, new UpdateAlertDialogCallback() { | ||
@Override | ||
public void onSuccess(String update) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented out code |
||
refreshState(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure() { | ||
|
||
} | ||
}); | ||
}); | ||
} | ||
|
||
private void setupAliasLayout() { | ||
setupAliasesRecyclerView(); | ||
addAliasButton.setOnClickListener(v -> dialog.createAddPairAlertDialog("Add Alias", ProfileUtil.FieldType.ALIAS, new AddPairAlertDialogCallback() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ public static boolean exists(Context context, String key) { | |
} | ||
|
||
public static String getOneSignalAppId(Context context) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Revert app_id change |
||
} | ||
|
||
public static boolean getUserPrivacyConsent(Context context) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,11 @@ interface IOneSignal { | |
*/ | ||
val isInitialized: Boolean | ||
|
||
/** | ||
* Whether the security feature to authenticate your external user ids is enabled | ||
*/ | ||
val useIdentityVerification: Boolean | ||
|
||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this on the public API. |
||
/** | ||
* The user manager for accessing user-scoped | ||
* management. | ||
|
@@ -123,4 +128,16 @@ interface IOneSignal { | |
* data is not cleared. | ||
*/ | ||
fun logout() | ||
|
||
/** | ||
* Update JWT token for a user | ||
*/ | ||
fun updateUserJwt( | ||
externalId: String, | ||
token: String, | ||
) | ||
|
||
fun addUserJwtInvalidatedListener(listener: IUserJwtInvalidatedListener) | ||
|
||
fun removeUserJwtInvalidatedListener(listener: IUserJwtInvalidatedListener) | ||
} |
Original file line number | Diff line number | Diff line 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 commentThe reason will be displayed to describe this comment to others. Learn more. Address TODO |
||
* Implement this interface and provide an instance to [OneSignal.addUserJwtInvalidatedListner] | ||
* in order to receive control when the JWT for the current user is invalidated. | ||
* | ||
* @see [User JWT Invalidated Event | OneSignal Docs](https://documentation.onesignal.com/docs/) | ||
*/ | ||
interface IUserJwtInvalidatedListener { | ||
/** | ||
* Called when the JWT is invalidated | ||
* | ||
* @param event The user JWT that expired. | ||
*/ | ||
fun onUserJwtInvalidated(event: UserJwtInvalidatedEvent) | ||
} |
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.