passport
passport copied to clipboard
Can I use passort JS with React Native ?
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?
I think you can. Your mobile app would probably be talking to the same back-end server, which uses passport.
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
Any update on this @suphero ?
im facing the same issue, did you figure it out @suphero
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.
https://laramo.medium.com/oauth-with-facebook-and-google-for-reactnative-using-passport-js-ffe0e63f86cb