PassportJS を使用して、ブラウザーとモバイル クライアントの両方の FB 認証を処理しています。Web ユーザーの場合、Passport FacebookStrategy を使用していますが、これは意図したとおりに機能しています。また、モバイル クライアントが API にアクセスできるようにしたいと考えています。これを容易にするために Passport FacebookTokenStrategy を使用しようとしています。これは、1つの小さな問題で機能しているようです。モバイル クライアントがサーバーに対して GET 要求を行うと、FacebookTokenStrategy が使用され、verify コールバック関数が呼び出されます。検証機能では、ユーザー プロファイルが使用可能であるため、認証が成功したことがわかります。ただし、モバイル クライアントへの応答で 404 の HTTP ステータスが返されます。これを適切に構成する方法がわかりません。これは私が現在試していることです:
// Web based auth
passport.use(new FacebookStrategy({
clientID: Config.facebook.clientID,
clientSecret: Config.facebook.clientSecret,
callbackURL: "http://localhost/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate(profile, function(err, user){
done(err, user);
});
}
));
// Mobile client auth
passport.use(new FacebookTokenStrategy({
clientID: Config.facebook.clientID,
clientSecret: Config.facebook.clientID
},
function(accessToken, refreshToken, profile, done) {
console.log(profile);
User.findOrCreate(profile, function(err, user){
done(err, user);
});
}
));
// Redirect the user to Facebook for authentication. When complete,
// Facebook will redirect the user back to the application at
// /auth/facebook/callback
exports.fb_auth = passport.authenticate('facebook',{ scope: 'email' });
// Facebook will redirect the user to this URL after approval. Finish the
// authentication process by attempting to obtain an access token. If
// access was granted, the user will be logged in. Otherwise,
// authentication has failed.
exports.fb_callback = passport.authenticate('facebook', { successRedirect: '/',
failureRedirect: '/login' });
// Mobile Authentication
exports.mobile_fb_auth = passport.authenticate('facebook-token');
Passport.authenticate('facebook-token'); を提供する必要がありますか? 追加の「onsuccess」コールバックを使用しますか? これは Web クライアントのコンテキストでは理にかなっていますが、facebook-token 戦略を使用してこれをどのように処理する必要があるかはわかりません。