passport icon indicating copy to clipboard operation
passport copied to clipboard

Can I use passort JS with React Native ?

Open ajai-jayakumar opened this issue 6 years ago • 6 comments

Hi, I am currently using Angular Fullstack Generator for my web application, now I am planning to create a mobile application using React Native. Since my current application uses the passport for authentication. Is it possible to use for react native as well?

ajai-jayakumar avatar Feb 12 '18 07:02 ajai-jayakumar

I think you can. Your mobile app would probably be talking to the same back-end server, which uses passport.

jtonneyck avatar Mar 08 '18 23:03 jtonneyck

passport requires ‘http’ and ‘crypto’ packages but these packages are deprecated in npm. These packages only contains a single Readme file. When you don’t install the packages RN throws ‘package not found’ exception. When you install RN throws ‘package found but index file not found’ exception. There is a reverse engineering workaround but I couldn’t apply the method successfully. I will try again in a few days, I will share the result.

http: https://www.npmjs.com/package/http

crypto: https://www.npmjs.com/package/crypto

suphero avatar Jun 09 '18 19:06 suphero

Any update on this @suphero ?

erikrahm avatar Apr 08 '19 02:04 erikrahm

im facing the same issue, did you figure it out @suphero

dhope21 avatar Oct 05 '22 07:10 dhope21

TL;DR: Maybe you can but you shouldn't use it.

It's been a long time since my answer and I obviously couldn't keep my word. I don't remember what I had in mind when I said "reverse engineering workaround".

I've rechecked the case, and it didn't work as before. The issue is: The package at "node_modules/passport/lib/middleware/authenticate.js" attempted to import the Node standard library module "http". It failed because the native React runtime does not include the Node standard library.

I checked the authenticate.js file, It doesn't look like it needs the http module much because it only uses http.STATUS_CODES. One may use passport.js with React Native by removing the http reference and updating the usage (it may be the workaround).

Coming to the original question, maybe there is a way to use but you shouldn't use passport with React Native because:

  • Still no documentation about React or React Native (Passport is authentication middleware for Node.js.).
  • Still no workaround solution.
  • Your secure tokens will be published on the client side. It creates a security risk.
  • You can't change security tokens easily because of the same reason. It may be fixed via CodePush. But still, this risk should not be taken.

suphero avatar Oct 07 '22 20:10 suphero

https://laramo.medium.com/oauth-with-facebook-and-google-for-reactnative-using-passport-js-ffe0e63f86cb

redbar0n avatar Jan 23 '23 07:01 redbar0n