Skip to content

Fix onesignalid is local when identity verification off #2242

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

Open
wants to merge 24 commits into
base: identity_verification_beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3caffc9
Infrastructure change around JWT: models, model stores
jinliu9508 Aug 13, 2024
c588498
Public API impl for JWT, User Manager, and callbacks
jinliu9508 Aug 13, 2024
bf759d2
Add JWT to HttpClient, backend services, and operations
jinliu9508 Aug 13, 2024
f29d0df
Add UNAUTHORIZED handling to OperationRepo and operation executors
jinliu9508 Aug 13, 2024
f8abc51
Add and adjust some test units for JWT related change
jinliu9508 Aug 13, 2024
9e13707
Add UI element to DemoApp to manually test JWT impl
jinliu9508 Aug 13, 2024
eb525f4
Manually test with a specific app in staging
jinliu9508 Aug 13, 2024
76b95d0
OperationRepo: when identity verification is on, do not process opera…
jinliu9508 Aug 22, 2024
034e9c9
Disable operations that are not allowed when identity verification is on
jinliu9508 Aug 26, 2024
af3ba8a
use new name from remote params
jinliu9508 Aug 26, 2024
3b26b66
Init behavior change based on identity verification
jinliu9508 Sep 9, 2024
3083eae
Add deviceAuthToken to subscription requests
jinliu9508 Sep 13, 2024
db78c39
calling logout disable push subscription
jinliu9508 Sep 26, 2024
48f4c9a
fixup: identity verification improvement
jinliu9508 Nov 14, 2024
b029886
Merge pull request #2196 from OneSignal/identity-verification-impleme…
jinliu9508 Nov 22, 2024
280b0af
Release 5.2.0-beta-01
jinliu9508 Nov 22, 2024
b470b49
Merge pull request #2216 from OneSignal/rel/5.2.0-beta-01
jinliu9508 Nov 22, 2024
736bcfa
Release 5.2.0
jinliu9508 Nov 22, 2024
00f6977
Merge pull request #2217 from OneSignal/rel/5.2.0
jinliu9508 Nov 22, 2024
a9442ab
Fix a typo in addUserJwtInvalidatedListener
jinliu9508 Nov 22, 2024
9c0b6b5
Merge pull request #2218 from OneSignal/typo_jwt_listener
jinliu9508 Nov 22, 2024
e40d1e3
Release 5.2.0-beta-02
jinliu9508 Nov 22, 2024
f4a9356
Merge pull request #2219 from OneSignal/rel/5.2.0-beta-02
jinliu9508 Nov 22, 2024
b968181
Fix: bug that causes onesignalId to be local when setting alias while…
jinliu9508 Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Examples/OneSignalDemo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'

/** START - Google Play Builds **/
gmsImplementation('com.onesignal:OneSignal:5.1.25')
gmsImplementation('com.onesignal:OneSignal:5.2.0-beta-02')
/** END - Google Play Builds **/

/** START - Huawei Builds **/
// Omit Google / Firebase libraries for Huawei builds.
huaweiImplementation('com.onesignal:OneSignal:5.1.25') {
huaweiImplementation('com.onesignal:OneSignal:5.2.0-beta-02') {
exclude group: 'com.google.android.gms', module: 'play-services-gcm'
exclude group: 'com.google.android.gms', module: 'play-services-analytics'
exclude group: 'com.google.android.gms', module: 'play-services-location'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,6 +141,13 @@ public void onUserStateChange(@NonNull UserChangedState state) {
}
});

OneSignal.addUserJwtInvalidatedListener(new IUserJwtInvalidatedListener() {
@Override
public void onUserJwtInvalidated(@NonNull UserJwtInvalidatedEvent event) {
Log.v(Tag.LOG_TAG, "onUserJwtInvalidated fired with ID:" + event.getExternalId());
}
});

OneSignal.getInAppMessages().setPaused(true);
OneSignal.getLocation().setShared(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -422,6 +430,7 @@ public void onFailure() {
}

private void setupUserLayout() {
setupJWTLayout();
setupAliasLayout();
setupEmailLayout();
setupSMSLayout();
Expand All @@ -430,6 +439,28 @@ 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);
refreshState();
}
}

@Override
public void onFailure() {

}
});
});
}

private void setupAliasLayout() {
setupAliasesRecyclerView();
addAliasButton.setOnClickListener(v -> dialog.createAddPairAlertDialog("Add Alias", ProfileUtil.FieldType.ALIAS, new AddPairAlertDialogCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum FieldType {
ALIAS("Alias"),
EMAIL("Email"),
SMS("SMS"),
JWT("JWT"),
EXTERNAL_USER_ID("External User Id"),

TAG("Tags"),
Expand Down Expand Up @@ -97,6 +98,10 @@ public static boolean isSMSValid(TextInputLayout smsTextInputLayout) {
return true;
}

private static boolean isJWTValid(TextInputLayout jwtTextInputLayout) {
return !jwtTextInputLayout.getEditText().toString().isEmpty();
}

private static boolean isExternalUserIdValid(TextInputLayout externalUserIdTextInputLayout) {
externalUserIdTextInputLayout.setErrorEnabled(false);
if (externalUserIdTextInputLayout.getEditText() != null) {
Expand Down Expand Up @@ -137,6 +142,8 @@ static boolean isContentValid(FieldType field, TextInputLayout alertDialogTextIn
return isEmailValid(alertDialogTextInputLayout);
case SMS:
return isSMSValid(alertDialogTextInputLayout);
case JWT:
return isJWTValid(alertDialogTextInputLayout);
case EXTERNAL_USER_ID:
return isExternalUserIdValid(alertDialogTextInputLayout);
case TAG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:gravity="start|center_vertical"
android:layout_marginBottom="4dp"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="4dp"
android:gravity="start|center_vertical"
android:text="@string/app"
android:textColor="@color/colorDarkText" />

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
app:cardCornerRadius="6dp"
app:cardElevation="4dp">

Expand Down Expand Up @@ -226,23 +226,23 @@
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
android:orientation="vertical"
android:background="@color/colorPrimary">
android:background="@color/colorPrimary"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/main_activity_app_revoke_consent_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/revoke_consent"
android:textSize="19sp"
android:textColor="@android:color/white"
android:background="@drawable/ripple_selector_white_red"
android:visibility="visible"/>
android:textSize="19sp"
android:visibility="visible" />

</LinearLayout>

Expand All @@ -263,11 +263,11 @@
android:id="@+id/main_activity_login_user_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/login_user"
android:textSize="19sp"
android:textColor="@android:color/white"
android:background="@drawable/ripple_selector_white_red"
android:visibility="visible"/>
android:textSize="19sp"
android:visibility="visible" />

</LinearLayout>

Expand All @@ -288,14 +288,97 @@
android:id="@+id/main_activity_logout_user_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/logout_user"
android:textSize="19sp"
android:textColor="@android:color/white"
android:background="@drawable/ripple_selector_white_red"
android:visibility="visible"/>
android:textSize="19sp"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:id="@+id/main_activity_jwt_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical">

<TextView
android:id="@+id/main_activity_jwt_title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="4dp"
android:gravity="start|center_vertical"
android:text="@string/JWT"
android:textColor="@color/colorDarkText" />

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
app:cardCornerRadius="6dp"
app:cardElevation="4dp">

<LinearLayout
android:id="@+id/main_activity_jwt_details_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:background="@color/colorPrimary"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/main_activity_invalidate_jwt_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/invalidate_JWT"
android:textColor="@android:color/white"
android:textSize="19sp"
android:visibility="visible" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:background="@color/colorPrimary"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/main_activity_update_jwt_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/update_JWT"
android:textColor="@android:color/white"
android:textSize="19sp"
android:visibility="visible" />
</LinearLayout>

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>

<!-- Aliases -->
<LinearLayout
android:id="@+id/main_activity_aliases_linear_layout"
Expand Down
5 changes: 5 additions & 0 deletions Examples/OneSignalDemo/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<string name="login_user">Login User</string>
<string name="logout_user">Logout User</string>

<string name="JWT">JWT</string>
<string name="invalidate_JWT">Invalidate JWT</string>
<string name="update_JWT">Update JWT</string>
<string name="no_jwt_added">No JWT Added</string>

<string name="aliases">Aliases</string>
<string name="external_user_id_colon">EUID:</string>
<string name="no_aliases_added">No Aliases Added</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,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

/**
* Implement this interface and provide an instance to [OneSignal.addUserJwtInvalidatedListener]
* 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/identity-verification)
*/
interface IUserJwtInvalidatedListener {
/**
* Called when the JWT is invalidated
*
* @param event The user JWT that expired.
*/
fun onUserJwtInvalidated(event: UserJwtInvalidatedEvent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,24 @@ object OneSignal {
@JvmStatic
fun logout() = oneSignal.logout()

@JvmStatic
fun updateUserJwt(
externalId: String,
token: String,
) {
oneSignal.updateUserJwt(externalId, token)
}

@JvmStatic
fun addUserJwtInvalidatedListener(listener: IUserJwtInvalidatedListener) {
oneSignal.addUserJwtInvalidatedListener(listener)
}

@JvmStatic
fun removeUserJwtInvalidatedListener(listener: IUserJwtInvalidatedListener) {
oneSignal.removeUserJwtInvalidatedListener(listener)
}

private val oneSignal: IOneSignal by lazy {
OneSignalImp()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.onesignal

/**
* The event passed into [IUserJwtInvalidatedListener.onUserJwtInvalidated], it provides access
* to the external ID whose JWT has just been invalidated.
*
* For more information https://documentation.onesignal.com/docs/identity-verification#4-handle-jwt-lifecycle-events
*/
class UserJwtInvalidatedEvent(
val externalId: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object OneSignalUtils {
/**
* The version of this SDK.
*/
const val SDK_VERSION: String = "050125"
const val SDK_VERSION: String = "050200"

fun isValidEmail(email: String): Boolean {
if (email.isEmpty()) {
Expand Down
Loading
Loading