node.js - 将 passport-google-oauth 与 react-native 结合使用

标签 node.js oauth npm reactjs react-native

我正在尝试使用 passport-google-oauth在我的 native react 应用程序中。当我运行该应用程序时,它会抛出错误:requiring unknown module util。我已经使用 npm install .. 安装了这个包,我也尝试过 npm install ... --save

应用/组件/Login.js

'use strict';

var React = require('react-native');
var GoogleStrategy = require('passport-google-oauth').OAuthStrategy;
...

package.json

{
  "name": "NativeApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node_modules/react-native/packager/packager.sh"
  },
  "dependencies": {
    "passport": ">= 0.0.0",
    "passport-google-oauth": "^0.2.0",
    "react-native": "^0.4.4"
  },
  "devDependencies": {}
}

index.ios.js

'use strict';

var React = require('react-native');
var Login = require('./App/Components/login');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  NavigatorIOS,
} = React;

class AppStoreIOS extends React.Component{
  render() {
    return (
      <NavigatorIOS
        titleTextColor = '#0073A0'
        // barTintColor = '#183E63'
        initialRoute={{
          component: Login,
          title: 'AppStore v2.0',
          passProps: { myProp: 'foo' },
        }}
      />
    );
  }
};

最佳答案

不要认为这对您有用。 Passport 预计将在 node.js(基于 express)环境中运行,并且至少需要一些工作才能将其移植到使用 Webview 进行 Oauth 流程,实际上这将是很多工作。

看看https://medium.com/@jtremback/oauth-2-with-react-native-c3c7c64cbb6d有关如何在 react-native 中支持 oauth 的示例。我没试过这个,但它看起来很简单。

关于node.js - 将 passport-google-oauth 与 react-native 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30420056/

相关文章:

javascript - 如何从node.js中的模块导出函数

android - 来自 linkedin 的 Android 应用程序访问 token

ios - 使用 xAuth 登录 vimeo

php - 获取登录用户的电子邮件 ID yahoo oauth php

docker - 如何在 Docker 中自动部署 Node-RED 实例(包括额外的节点)?

node.js - webpack --watch && http-server ./dist -p 8080 --cors -o 不起作用

sql - 连接到 SQL Server : Connection Error: Failed to connect to servername\instancename in 15000ms 时出现超时错误

node.js - 从 Express 服务器响应中获取/读取 res.status() 值

node.js - 断言流

node.js - Angular 导入 Node 包