-
Notifications
You must be signed in to change notification settings - Fork 39
[MOB-9064] JWT #740
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
Draft
Parent:
[SDK-82] New Architecture
lposen
wants to merge
110
commits into
new-arch/master
Choose a base branch
from
jwt/master
base: new-arch/master
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.
Draft
[MOB-9064] JWT #740
Changes from all commits
Commits
Show all changes
110 commits
Select commit
Hold shift + click to select a range
bd32975
feat: add authentication failure and retry policy enums and types
lposen 50ef0e6
chore: update eslint-config-prettier and add prettier-eslint dependency
lposen af0065e
feat: export new authentication and retry policy types in index files
lposen 762f333
feat: enhance IterableConfig with JWT error handling and retry policy…
lposen cfe1de2
feat: add onAuthFailure and pauseAuthRetries methods to Iterable class
lposen 7fde4e7
feat: implement retry policy and JWT error handling in IterableAppPro…
lposen 8975ac1
chore: update Iterable API dependency version to 3.6.1
lposen ab8efaa
feat: implement onAuthFailure handling and pauseAuthRetries method in…
lposen 1972fbb
feat: fix nullpointerexception on com.iterable.iterableapi.IterableIn…
lposen 2cd8253
refactor: remove commented-out encryptionEnforced code from Serializa…
lposen 5810a0a
feat: improve JWT error handling and enhance IterableConfig with addi…
lposen fd74351
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen ef86b15
refactor: fix onAuthFailure call
lposen e85d660
refactor: remove onAuthFailure method and update event handler setup …
lposen 372df66
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen c32447f
chore: remove unused index.ts file from hooks directory
lposen a7804e5
refactor: simplify authHandler type and standardize IterableAuthFailu…
lposen 21ca59d
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen 6d8c45a
refactor: simplify authHandler type and standardize IterableAuthFailu…
lposen 18cba09
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen 050ad22
feat: enhance JWT error handling with detailed alerts for auth failures
lposen a63b9dc
refactor: remove onJWTErrorPresent flag from IterableConfig to stream…
lposen 60bc88e
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen 38f2791
chore: update Iterable-iOS-SDK dependency to version 6.6.1 in podspec
lposen e36be70
chore: remove tempfix and update Embed Pods Frameworks build phase in…
lposen 356e767
feat: implement user notification handling and remote notification re…
lposen 04cb0d1
feat: add pauseAuthRetries method and enhance auth failure handling i…
lposen 47cdab3
chore: update Xcode project configuration and enable authHandler in I…
lposen b22b9ea
refactor: delegate event sending for auth failure handling in ReactIt…
lposen 16c2c9a
fix: improve JWT error logging and alert messaging for auth failures
lposen 492c3b6
chore: update dependencies and improve code formatting
lposen 786a079
Merge branch 'jwt/master' into jwt/MOB-10946-task-2-authfailure-and-r…
lposen f1d10cb
chore: update yarn.lock
lposen 5fbb9c9
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen 78e4914
Merge branch 'jwt/MOB-10947-task-3-android-retrypolicy-config-at-andr…
lposen edfa70f
refactor: remove unnecessary NSLog statements from AppDelegate.swift
lposen 65cb551
feat: add authentication manager to Iterable class
lposen 5bbb5fc
refactor: remove pauseAuthRetries method from Iterable class
lposen 92fbff1
chore: disable TSDoc syntax rule for IterableRetryBackoff enum
lposen e94100f
feat: add pauseAuthRetries method to authentication manager and enhan…
lposen 5e4e579
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen 836ad6c
Merge branch 'jwt/MOB-10947-task-3-android-retrypolicy-config-at-andr…
lposen 3737d57
fix: improve null safety in IterableInAppMessage.fromViewToken method
lposen 20cd031
Merge branch 'jwt/MOB-10947-task-3-android-retrypolicy-config-at-andr…
lposen 361897f
feat: implement IterableApi class for calls to native layer
lposen 4ee7bdf
docs: add documentation comment for IterableApi class
lposen f2cf388
refactor: replace RNIterableAPI calls with IterableApi methods in Ite…
lposen 4da6aa0
refactor: update IterableApi method signatures to accept destructured…
lposen 9be2327
refactor: streamline logging in Iterable class and enhance IterableLo…
lposen de4db13
refactor: remove IterableLogger instantiation from tests and clean up…
lposen efb72a6
refactor: replace RNIterableAPI references with IterableApi
lposen 3990876
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen cbd2799
refactor: enable logging in IterableApi methods by removing commented…
lposen 2025291
test: add comprehensive unit tests for IterableLogger functionality
lposen cf76e09
Merge branch 'new-arch/master' into jwt/master
lposen 841f63f
Merge branch 'jwt/master' into jwt/MOB-10946-task-2-authfailure-and-r…
lposen 7b8fdb1
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen 3870dc3
Merge branch 'jwt/MOB-10947-task-3-android-retrypolicy-config-at-andr…
lposen 39f07d0
Merge branch 'jwt/MOB-11032-task-4-ios-bridge-retrypolicy-and-authfai…
lposen 307326e
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen fb4b801
refactor: simplify inAppManager initialization to avoid circular depe…
lposen 800bb0b
feat: add IterableApi and IterableAuthManager exports to core classes
lposen 0af6532
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen 67a806d
fix: removed comment description that no longer applies
lposen d9a7b82
test: prettify Iterable test file
lposen 1dbd4e2
Merge branch 'jwt/master' into jwt/MOB-10946-task-2-authfailure-and-r…
lposen 71ac5c4
docs: add better comments to IterableAuthManager
lposen d95ae90
fix: standardize authentication failure reason representation across …
lposen b31ffd7
Merge branch 'jwt/MOB-10946-task-2-authfailure-and-retrypolicy-ts-cla…
lposen 0587649
Merge branch 'jwt/MOB-10947-task-3-android-retrypolicy-config-at-andr…
lposen 9883a21
Merge branch 'new-arch/master' into jwt/master
lposen 0eedca5
Merge pull request #726 from Iterable/jwt/MOB-10946-task-2-authfailur…
lposen ed20041
Merge branch 'jwt/master' into jwt/MOB-10947-task-3-android-retrypoli…
lposen 0191b7b
chore: removed onTokenRegistrationFailed method as per PR comment
lposen 70fa36a
feat: implement retry policy configuration in IterableConfig for iOS
lposen 52d5ac4
Merge branch 'jwt/MOB-11032-task-4-ios-bridge-retrypolicy-and-authfai…
lposen 2fa18f8
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen 5fa3361
Merge pull request #727 from Iterable/jwt/MOB-10947-task-3-android-re…
lposen db24c40
Merge branch 'jwt/master' into jwt/MOB-11032-task-4-ios-bridge-retryp…
lposen e579386
Merge pull request #728 from Iterable/jwt/MOB-11032-task-4-ios-bridge…
lposen c9fefd7
Merge branch 'jwt/master' into jwt/MOB-12231-create-an-iterableapi-cl…
lposen 23d719a
test: add tests to IterableApi
lposen 644c510
Merge branch 'jwt/MOB-12231-create-an-iterableapi-class-for-api-calls…
lposen a693494
docs: enhance IterableLogger documentation with descriptions and exa…
lposen 54f4626
Merge branch 'jwt/MOB-12298-new-improve-logger' of github.com:Iterabl…
lposen 5517bf7
Update src/inApp/classes/IterableInAppManager.ts
lposen a2e5177
Merge pull request #737 from Iterable/jwt/MOB-12231-create-an-iterabl…
lposen 42669ff
Merge branch 'new-arch/master' into jwt/master
lposen a4bd708
Merge branch 'jwt/master' into jwt/MOB-12298-new-improve-logger
lposen c0a2c20
docs: removed a TODO and enhanced documentation for IterableLogger
lposen 1eb3069
Merge branch 'new-arch/master' into jwt/master
lposen e06edab
Merge branch 'jwt/master' into jwt/MOB-12298-new-improve-logger
lposen 6828a7a
fix: change default log level from info to debug in IterableConfig
lposen e2c6148
refactor: update default log level to debug in IterableLogger and rel…
lposen d695a8b
Merge pull request #739 from Iterable/jwt/MOB-12298-new-improve-logger
lposen 2dcb969
chore: update yarn.lock and enhance example configuration documentation
lposen 1bfa9d5
chore: add .env.local to .gitignore and update example configuration …
lposen d471800
refactor: small updates to ReactIterable.swift
lposen 6a9972a
feat: implement JWT generation module for React Native in example
lposen ad48782
chore: remove unused crypto-js and @types/crypto-js dependencies from…
lposen 5df923f
feat: add IterableJwtGenerator and JwtTokenModule for JWT token gener…
lposen 40c4bad
fix: ensure login is called during initialization and improve error h…
lposen fea6232
refactor: remove commented-out code from IterableJwtGenerator.swift t…
lposen fd76f08
refactor: remove unnecessary login calls and clean up error handling …
lposen b663dce
refactor: remove console log statements to streamline IterableAppProv…
lposen a58be2a
feat: introduce NativeJwtTokenModule for JWT token generation and rem…
lposen 13012d9
refactor: enhance JWT generation methods and update .env.example comm…
lposen 9038579
Merge pull request #767 from Iterable/jwt/SDK-136-new-jwt-token-gener…
lposen d7f81c0
chore: update package version to 2.2.0-alpha.0 in package.json and it…
lposen e7deb3d
chore: update CHANGELOG.md for 2.2.0-alpha.0 release
lposen 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 hidden or 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 |
|---|---|---|
|
|
@@ -85,6 +85,7 @@ ios/generated | |
| android/generated | ||
|
|
||
| # Iterable | ||
| .env.local | ||
| .env | ||
| .xcode.env.local | ||
| coverage/ | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
106 changes: 106 additions & 0 deletions
106
example/android/app/src/main/java/iterable/reactnativesdk/example/IterableJwtGenerator.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package com.iterable; | ||
|
|
||
| import javax.crypto.Mac; | ||
| import javax.crypto.spec.SecretKeySpec; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.Duration; | ||
| import java.util.Base64; | ||
| import java.util.Base64.Encoder; | ||
|
|
||
| /** | ||
| * Utility class to generate JWTs for use with the Iterable API | ||
| * | ||
| * @author engineering@iterable.com | ||
| */ | ||
| public class IterableJwtGenerator { | ||
| static Encoder encoder = Base64.getUrlEncoder().withoutPadding(); | ||
|
|
||
| private static final String algorithm = "HmacSHA256"; | ||
|
|
||
| // Iterable enforces a 1-year maximum token lifetime | ||
| private static final Duration maxTokenLifetime = Duration.ofDays(365); | ||
|
|
||
| private static long millisToSeconds(long millis) { | ||
| return millis / 1000; | ||
| } | ||
|
|
||
| private static final String encodedHeader = encoder.encodeToString( | ||
| "{\"alg\":\"HS256\",\"typ\":\"JWT\"}".getBytes(StandardCharsets.UTF_8) | ||
| ); | ||
|
|
||
| /** | ||
| * Generates a JWT from the provided secret, header, and payload. Does not | ||
| * validate the header or payload. | ||
| * | ||
| * @param secret Your organization's shared secret with Iterable | ||
| * @param payload The JSON payload | ||
| * | ||
| * @return a signed JWT | ||
| */ | ||
| public static String generateToken(String secret, String payload) { | ||
| try { | ||
| String encodedPayload = encoder.encodeToString( | ||
| payload.getBytes(StandardCharsets.UTF_8) | ||
| ); | ||
| String encodedHeaderAndPayload = encodedHeader + "." + encodedPayload; | ||
|
|
||
| // HMAC setup | ||
| Mac hmac = Mac.getInstance(algorithm); | ||
| SecretKeySpec keySpec = new SecretKeySpec( | ||
| secret.getBytes(StandardCharsets.UTF_8), algorithm | ||
| ); | ||
| hmac.init(keySpec); | ||
|
|
||
| String signature = encoder.encodeToString( | ||
| hmac.doFinal( | ||
| encodedHeaderAndPayload.getBytes(StandardCharsets.UTF_8) | ||
| ) | ||
| ); | ||
|
|
||
| return encodedHeaderAndPayload + "." + signature; | ||
|
|
||
| } catch (Exception e) { | ||
| throw new RuntimeException(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Generates a JWT (issued now, expires after the provided duration). | ||
| * | ||
| * @param secret Your organization's shared secret with Iterable. | ||
| * @param duration The token's expiration time. Up to one year. | ||
| * @param email The email to included in the token, or null. | ||
| * @param userId The userId to include in the token, or null. | ||
| * | ||
| * @return A JWT string | ||
| */ | ||
| public static String generateToken( | ||
| String secret, Duration duration, String email, String userId) { | ||
|
|
||
| if (duration.compareTo(maxTokenLifetime) > 0) | ||
| throw new IllegalArgumentException( | ||
| "Duration must be one year or less." | ||
| ); | ||
|
|
||
| if ((userId != null && email != null) || (userId == null && email == null)) | ||
| throw new IllegalArgumentException( | ||
| "The token must include a userId or email, but not both." | ||
| ); | ||
|
|
||
| long now = millisToSeconds(System.currentTimeMillis()); | ||
|
|
||
| String payload; | ||
| if (userId != null) | ||
| payload = String.format( | ||
| "{ \"userId\": \"%s\", \"iat\": %d, \"exp\": %d }", | ||
| userId, now, now + millisToSeconds(duration.toMillis()) | ||
| ); | ||
| else | ||
| payload = String.format( | ||
| "{ \"email\": \"%s\", \"iat\": %d, \"exp\": %d }", | ||
| email, now, now + millisToSeconds(duration.toMillis()) | ||
| ); | ||
|
|
||
| return generateToken(secret, payload); | ||
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+77
to
+104
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. |
||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.