Skip to content
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

feat: Add a config plugin for Expo (iOS & Android) #915

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aurelien-iapp
Copy link

@aurelien-iapp aurelien-iapp commented Oct 19, 2023

Fixes N/A

Description

This patch adds a new plugin directory with an Expo config plugin.

This plugin will automatically patch the iOS Objective-C code to perform the different steps described in the README:

  • it adds protocol conformance to RNAppAuthAuthorizationFlowManager to the AppDelegate
  • it creates a new authorizationFlowManagerDelegate property
  • it patches application:openURL:options: to handle the custom-scheme based redirects
  • it patches application:continueUserActivity:restorationHandler: to handle the deep (universal) link redirects

⚠️ to patch the AppDelegate.h it leverages withDangerousMod and the "codeMod" API, which are not stable (but everybody uses them and we don't really have a choice here...)

Steps to verify

  1. create a new Expo project (any template will do)
  2. add react-native-app-auth to the project: you can point to my branch for testing purposes:
    "dependencies": {
        "react-native-app-auth": "aurelien-iapp/react-native-app-auth#expo-config-plugin",
        ...
  3. add the plugin to your app.json's "plugins" section:
    "plugins": [
        "react-native-app-auth/plugin"
        ...
  4. Generate the iOS/Android projects using npx expo prebuild and check the contents of AppDelegate.mm and AppDelegate.h. Changes will be visible as follows:

AppDelegate h@2x
20231019 XcodeLeJeuduTao — AppDelegate mm@2x

@aurelien-iapp aurelien-iapp force-pushed the expo-config-plugin branch 5 times, most recently from e7bdbed to f04fe97 Compare October 23, 2023 15:11
@merijnhofsteenge
Copy link

Hello,

Thanks for making this plugin. My team is planning on using it. Do you have any information on whether this will be merged into the repo at some point?

@zibs
Copy link
Contributor

zibs commented Feb 21, 2024

Hey @merijnhofsteenge and @aurelien-iapp -- just trying to get a sense of your use case here? Why would you be wanting to use this library as opposed to Expo's AuthSession library if you're already using Expo?

@merijnhofsteenge
Copy link

merijnhofsteenge commented Feb 23, 2024

Hey @zibs. My company also has native apps connecting to the same OAuth client. The native developers recommended using AppAuth. It seems however that Expo's AuthSession can do the same, so we will explore this route now. Thank you for your question!

@Off2Race
Copy link

Off2Race commented Aug 29, 2024

Hi, @zibs – I'm curious about the status of this PR. Will it be merged at some point? If so, I'd love to use the capability.

Regarding your question about the use case, we have an existing app that uses react-native-app-auth, mostly with the Google provider, but we've experimented with others, particularly Strava. The functionality works great. The app has been in production for 3 years now. Originally, our app didn't use Expo but we've recently tried to add it, including the use of Continuous Native Generation (CNG), where the expo prebuild command is used to generate everything in the ios and android folders. We like this concept but ran into an issue with cases like this library which requires manually updates to the native files. Expo's solution to that issue is the development of a plug-in, which is addressed by this PR. It's certainly possible that we could use Expo's AuthSession to provide the same functionality but we'd prefer to not make the switch as the current functionality works great.

Until I found this PR, we were considering developing our own plug-in but I'm pleased to see that someone already did the work. Many thanks to the library maintainers for such a great package. @zibs, let me know your thoughts on the merge.

@carbonrobot
Copy link
Contributor

@aurelien-iapp @Off2Race
We will set an internal meeting next week to discuss the implications of merging and maintaining this plugin.

@aurelien-iapp
Copy link
Author

Hey guys,
I'm quite surprised to see activity on such an old PR 😃

@Off2Race I used this plugin to setup a custom OAUTH sign-in for a client project about a year ago, and didn't have much feedback at the time so I deduced it was not a priority for the team.

About your remarks:

  • I made the code for the android app: it's on a private repo but I can definitely publish this part if you're interested
  • I recently upgraded the aforementioned project to the latest Expo SDK and had no issue with the plugin code, so apart form the dependencies it should work as-of

Tell me if you are still interested and I will prepare the patch for Android.

Regards !

@carbonrobot
Copy link
Contributor

@aurelien-iapp Appreciate the contribution, we would love to see the android code as well. We had some maintainers leave and our native libraries were harder to maintain without community support, but we have been able to dedicate some more resources to this one recently.

@carbonrobot
Copy link
Contributor

@aurelien-iapp Thanks for the update, we will merge this and restructure the code so we can publish it on NPM. Could you fix the merge conflicts on your side? I would really like to keep your username as the original contributor on the commits so your work is captured here.

@aurelien-iapp
Copy link
Author

@aurelien-iapp Could you fix the merge conflicts on your side?

Hello guys 👋
Yes I will rebase and add the Android files today, I didn't have a minute for myself this week sorry 🙏

This patch adds an Expo config-plugin to easily embed the library into
an Expo project.

This plugin with insert the code changes described in the README each
time the "prebuild" phase in run.
Copy link

changeset-bot bot commented Sep 6, 2024

⚠️ No Changeset found

Latest commit: a35f8f1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Sep 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-app-auth ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2024 0:38am

@aurelien-iapp aurelien-iapp changed the title feat: Add a config plugin for Expo (iOS) feat: Add a config plugin for Expo (iOS & Android) Sep 6, 2024
@aurelien-iapp
Copy link
Author

aurelien-iapp commented Sep 6, 2024

I did rebase de branch, move the plugin dir into packages/react-native-app-auth/plugin and did some minor changes (see the commits for details).
Right now the plugin:

For iOS:

which makes the complete setup for RN>=0.68 as per the docs

on Android:

  • it adds the appAuthRedirectScheme declaration to app/build.gradle

IMPORTANT NOTES:

  • this plugin cannot "guess" the scheme needed to generate the Android modifications and will crash – with a message – unless provided with an authScheme parameter: this means it must be declared as follows in the app.json at the root of the Expo project:
     {
       "expo": {
          ...
          "plugins": [
            [ "react-native-app-auth/plugin", { "authScheme": "my.redirect.scheme.goes.here" }],
            ...
          ]
  • on iOS declaring the scheme in app.json will suffice (not on Android since Expo does it differently...)
  • as of now the Android part of the plugin (and only this one) is not re-entrant: you cannot "prebuild" again without cleaning. I could definitely improve this when I have the time but as of today this is good enough for my use cases
  • the docs have completely changed and I don't really know where to detail all these steps... so if someone knowledgeable could put a word about it somewhere it would be great 😄

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

Successfully merging this pull request may close these issues.

5 participants