-
Notifications
You must be signed in to change notification settings - Fork 198
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
Feature: Identity Verification iOS Implementation #1038
Open
jennantilla
wants to merge
10
commits into
main
Choose a base branch
from
feat/ios_jwt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−25
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9cd7257
Add JWT and event listener to wrapper
jennantilla 266bf60
Add iOS implementation
jennantilla 4c04a09
Update example project to test identity verification
jennantilla 4a6ac89
Make jwt token optional
jennantilla 55f5ba9
Make externalId nonoptional for UserJwtInvalidatedEvent
jennantilla 020a9c8
Add inline documentation
jennantilla 8077f02
Change parameter name to match native implementation
jennantilla 087222a
Update iOS header
jennantilla 7ad3788
Merge branch 'main' into feat/jwt
jennantilla f29cdd5
Merge branch 'main' into feat/jwt
jennantilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,10 @@ import LiveActivities from "./LiveActivitiesNamespace"; | |
// Suppress TS warnings about window.cordova | ||
declare let window: any; // turn off type checking | ||
|
||
export interface UserJwtInvalidatedEvent { | ||
externalId: string; | ||
} | ||
|
||
export class OneSignalPlugin { | ||
User: User = new User(); | ||
Debug: Debug = new Debug(); | ||
|
@@ -47,6 +51,14 @@ export class OneSignalPlugin { | |
|
||
private _appID = ""; | ||
|
||
private _userJwtInvalidatedEventListenerList: ((event:UserJwtInvalidatedEvent)=>void)[] = []; | ||
|
||
private _processFunctionList(array: ((event:any)=>void)[], param: any): void { | ||
for (let i = 0; i < array.length; i++) { | ||
array[i](param); | ||
} | ||
} | ||
|
||
/** | ||
* Initializes the OneSignal SDK. This should be called during startup of the application. | ||
* @param {string} appId | ||
|
@@ -64,23 +76,59 @@ export class OneSignalPlugin { | |
}; | ||
|
||
/** | ||
* Login to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user. | ||
* @param {string} externalId | ||
* Log in to OneSignal under the user identified by the [externalId] provided. The act of logging a user into the OneSignal SDK will switch the [user] context to that specific user. | ||
* @param {string} externalId | ||
* @param {string} jwtToken - Optional | ||
* @returns void | ||
*/ | ||
login(externalId: string): void { | ||
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "login", [externalId]); | ||
login(externalId: string, jwtToken?: string): void { | ||
// if no jwt token, pass null | ||
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.
Is this comment accurate? |
||
const args = jwtToken ? [externalId, jwtToken] : [externalId]; | ||
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "login", args); | ||
} | ||
|
||
/** | ||
* Logout the user previously logged in via [login]. The [user] property now references a new device-scoped user. | ||
* @param {string} externalId | ||
* Log out the user previously logged in via [login]. The [user] property now references a new device-scoped user. | ||
* @returns void | ||
*/ | ||
logout(): void { | ||
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "logout"); | ||
} | ||
|
||
/** | ||
* Update the JWT token for a user. | ||
* @param {string} externalId | ||
* @param {string} token | ||
*/ | ||
updateUserJwt(externalId: string, token: string): void { | ||
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "updateUserJwt", [externalId, token]); | ||
} | ||
|
||
/** | ||
* Add a callback that fires when the user's JWT is invalidated. | ||
* @param event | ||
* @param listener | ||
*/ | ||
addEventListener(event: "userJwtInvalidated", listener: (event: UserJwtInvalidatedEvent) => void) { | ||
this._userJwtInvalidatedEventListenerList.push(listener as (event: UserJwtInvalidatedEvent) => void); | ||
const userJwtInvalidatedCallBackProcessor = (event: UserJwtInvalidatedEvent) => { | ||
this._processFunctionList(this._userJwtInvalidatedEventListenerList, event); | ||
}; | ||
window.cordova.exec(userJwtInvalidatedCallBackProcessor, function(){}, "OneSignalPush", "addUserJwtInvalidatedListener", []); | ||
} | ||
|
||
/** | ||
* Remove a UserJwtInvalidated Listener that has been previously added. | ||
* @param event | ||
* @param listener | ||
*/ | ||
removeEventListener(event: "userJwtInvalidated", listener: (event: UserJwtInvalidatedEvent) => void) { | ||
let index = this._userJwtInvalidatedEventListenerList.indexOf(listener); | ||
if (index !== -1) { | ||
this._userJwtInvalidatedEventListenerList.splice(index, 1); | ||
} | ||
} | ||
|
||
/** | ||
* Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to true prior to the invocation of initialization to ensure compliance. | ||
* @param {boolean} required | ||
|
Oops, something went wrong.
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.
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 don't see
(void)onUserJwtInvalidatedWithEvent
in this PR. Were you able to test the invalidated callback firing?