【发布时间】:2016-08-15 21:57:18
【问题描述】:
我正在将我的 iOS 应用从 Cordova 迁移到 React-Native。我有一个 App Engine 后端并在应用程序中使用 Google 身份验证。使用cordova,用户只需使用webview登录他们的谷歌账户,这将删除一个cookie,然后他们可以访问他们的数据,如下所示:
function getSomeResource(callback_method)
{
$.ajax({
type: "GET",
url: 'https://myapp.appspot.com' + '/endpoint',
dataType: "jsonp",
cache: true,
xhrFields: {
withCredentials: true
},
success: function(result)
{
callback_method(result);
},
error: function(fail)
{
console.log(fail)
}
});
}
对于 React-Native,我使用的是 https://github.com/apptailor/react-native-google-signin 插件。身份验证的工作原理如下:
- 用户使用 google 链接点击身份验证
- Safari 打开
- 用户验证
- 返回我的应用程序
当调用以下函数时
const user = GoogleSignin.currentUser();
提供了一个用户对象。
但是,当使用以下 RN 网络请求时,似乎没有存储任何身份验证 cookie,因此对 App Engine 后端的后续请求无法识别用户已登录
fetch('https://myapp.appspot.com' + '/endpoint', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Credentials' : 'true'
}
})
.then((response) => response.text())
.then((responseText) => {
var responseObject = JSON.parse(responseText);
console.log(responseObject);
});
问题是我是否有任何方法可以获取 cookie(就像我们使用 Cordova 所做的那样),以便我可以使用它来针对 GAE 后端对用户进行身份验证?
【问题讨论】:
标签: ios google-app-engine react-native google-oauth google-authentication