Skip to content

Implement JWT authentication for Intercom in React Native #298

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

Conversation

refactorer-bot
Copy link

Closes: https://github.com/intercom/intercom/issues/413021

This pull request introduces JWT (JSON Web Token) authentication support for Intercom in our React Native application. The change is necessary to enhance security and align with Intercom's latest recommended practices for user authentication.

JWT offers several advantages over the previous HMAC-based approach, including enhanced security, more flexible token management, and better integration with modern authentication systems. By implementing JWT support, we're ensuring our app stays up-to-date with the latest security standards and can leverage the full capabilities of Intercom's user authentication system.

The changes include:

  1. Updating the Intercom SDK versions for both iOS (19.0.0) and Android (17.0.+) to support JWT.
  2. Implementing a new setUserJWT method in the React Native bridge for both iOS and Android platforms.
  3. Adding comprehensive test coverage for the new JWT functionality, including various edge cases and error scenarios.
  4. Updating the TypeScript interface to include the new setUserJWT method with proper documentation.
  5. Ensuring backward compatibility with the existing HMAC-based setUserHash method.

These changes provide a more secure and flexible authentication mechanism for our Intercom integration, while maintaining compatibility with existing code. The implementation follows best practices, includes extensive error handling, and is thoroughly tested to ensure reliability across different scenarios.

@refactorer-bot refactorer-bot marked this pull request as ready for review July 1, 2025 14:14
@trousev
Copy link
Contributor

trousev commented Jul 1, 2025

I am getting this from CI:

[!] CocoaPods could not find compatible versions for pod "Intercom":
  In snapshot (Podfile.lock):
    Intercom (= 18.6.1, ~> 18.6.1)

  In Podfile:
    intercom-react-native (from `../..`) was resolved to 8.5.0, which depends on
      Intercom (~> 19.0.0)


You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * changed the constraints of dependency `Intercom` inside your development pod `intercom-react-native`.
   You should run `pod update Intercom` to apply changes you've made.

[!] [Codegen] warn: using experimental new codegen integration

Please, fix

@trousev
Copy link
Contributor

trousev commented Jul 1, 2025

@refactorer-bot

@kilian-tennyson
Copy link
Contributor

kilian-tennyson commented Jul 2, 2025

@refactorer-bot Theres a conflict between the podfile and the podspec. Add a step in the circle-ci config to remove the podFile from the ios directory before running pod install

@kilian-tennyson
Copy link
Contributor

@refactorer-bot

@refactorer-bot
Copy link
Author

refactorer-bot commented Jul 2, 2025

🔧 Refactorer Status - Followup Complete ✅ (logs)

Followup and polish completed successfully for PR intercom/intercom-react-native/298. All requested changes have been implemented and quality checks are passing.

Outcome

Perfect! I've successfully addressed the CI issue by adding a step to remove the Podfile.lock before running pod install in the CircleCI configuration. This resolves the version conflict between:

  • Podfile.lock: Had Intercom (18.6.1) locked
  • Podspec: Now requires Intercom (~> 19.0.0) for JWT support

The fix adds a new step at .circleci/config.yml:179-182 that removes the outdated Podfile.lock file before installing pods, allowing CocoaPods to resolve dependencies based on the updated podspec requirements rather than being constrained by the old lock file.

This ensures the iOS e2e tests will use the correct Intercom SDK version (19.0.0) that supports JWT authentication, fixing the CI build failure.

@refactorer-bot
Copy link
Author

🤖 ✔️ I completed addressing the PR comments successfully. You should see a new commit with the requested changes. For any debugging the task ARN was arn:aws:ecs:us-east-1:123456789012:task/intercom-code-bot/bf483b70925d46cf838484bd248aa2e9.

@kilian-tennyson
Copy link
Contributor

kilian-tennyson commented Jul 2, 2025

@refactorer-bot method is setUserJwt, not setUserJWT. Change it to reflect this

@refactorer-bot
Copy link
Author

refactorer-bot commented Jul 2, 2025

🔧 Refactorer Status - Followup Complete ✅ (logs)

Followup and polish completed successfully for PR intercom/intercom-react-native/298. All requested changes have been implemented and quality checks are passing.

Outcome

Perfect! I have successfully addressed the feedback from the code review. Here's a summary of the changes made:

Changes Made

I updated the method name from setUserJWT to setUserJwt throughout the entire codebase:

Files Updated:

  1. src/index.tsx - Updated TypeScript interface and implementation
  2. android/src/main/java/com/intercom/reactnative/IntercomModule.java - Updated Android bridge method and native SDK call
  3. ios/IntercomModule.m - Updated iOS bridge method and native SDK call
  4. __tests__/intercom-jwt.test.js - Updated all test references
  5. __tests__/setupTests.js - Updated mock method name

Specific Changes:

  • Method signature: setUserJWT(jwt: string)setUserJwt(jwt: string)
  • Bridge implementation: setUserJWT: (jwt) => IntercomModule.setUserJWT(jwt)setUserJwt: (jwt) => IntercomModule.setUserJwt(jwt)
  • Android method: public void setUserJWT(...)public void setUserJwt(...)
  • iOS method: RCT_EXPORT_METHOD(setUserJWT:...)RCT_EXPORT_METHOD(setUserJwt:...)
  • Native SDK calls: Intercom.client().setUserJWT(jwt)Intercom.client().setUserJwt(jwt) and [Intercom setUserJWT:jwt][Intercom setUserJwt:jwt]
  • All test references and mock implementations

The method name now follows standard camelCase convention (setUserJwt) instead of the previous naming (setUserJWT). All references have been updated consistently across TypeScript interfaces, native bridge implementations, SDK calls, and test files.

@refactorer-bot
Copy link
Author

🤖 ✔️ I completed addressing the PR comments successfully. You should see a new commit with the requested changes. For any debugging the task ARN was arn:aws:ecs:us-east-1:123456789012:task/intercom-code-bot/78390cb519184970bbcd3dd06ac6ae87.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants