我正在尝试让一个示例 Web 应用程序使用 OAuth 2 来确保接受 IOS 客户端的安全性,但遇到了一些麻烦。
浏览器客户端
使用来自我的node.js/passport示例代码添加了我的 google 客户端 ID + 密码 (https://code.google.com/apis/console)。效果很好——我所要做的就是将重定向 URI 指向我的服务器的授权回调。
IOS客户端
使用与上面相同的服务器端代码,以及用于 IOS 的 gtm-oauth2 库,我遇到了一些麻烦。我按照谷歌的说明为已安装的应用程序创建了一个客户端 ID,并修改了服务器以使用它们并将它们添加到 ios 应用程序中。该应用程序能够访问 google 登录页面,但在重定向时会出现错误(这是有道理的,因为我没有更改重定向 uri)。
Google 为我提供了两个重定向 URI 选项:
- 瓮瓮
- 本地主机
服务器需要某种排序或重定向,但 IOS 重定向 URI 中的子转换不起作用,并且看起来他们不应该考虑到服务器需要有一个特定的 URI 来进行验证:
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://127.0.0.1:3000/auth/google/callback"
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// To keep the example simple, the user's Google profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the Google account with a user record in your database,
// and return that user instead.
return done(null, profile);
});
}
));
...
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
app.get('/logout', function(req, res){
req.logout();
res.redirect('/');
});
我得到两个不同的错误:
- 使用适用于浏览器客户端的重定向,以及已安装的/ios 应用程序客户端 ID + 机密 - 重定向错误
- 使用 ios 客户端 ID + secret + ios + redirect (urn) - 客户端错误
我是否需要将 IOS 重定向 URI 添加到 IOS 客户端,或者在 node.js 服务器中放入某种重定向参数来告诉它有关客户端的信息?还是我缺少一些基本的东西?