使用angularjs routeprovider的护照facebook认证

Har*_*dha 3 javascript authentication facebook node.js angularjs

我有一个angularjs和node,expressjs应用程序.我在哪里尝试实施facebook登录(护照).但这里的问题是我试过的时候 -

app.get('/auth/facebook',passport.authenticate('facebook'));
    app.get('/auth/facebook/callback',passport.authenticate('facebook',
        {
            successRedirect: '/profile',
            failureRedirect: '/'
        }));
Run Code Online (Sandbox Code Playgroud)

配置如下 -

passport.use(new FacebookStrategy({
            clientID: 'xxxx',
            clientSecret: 'xxxx',
            callbackURL:'http://campustop.in/auth/facebook/callback'
        },
        function(accessToken,refreshToken,profile,done){
            console.log(profile);
        }
    ));
Run Code Online (Sandbox Code Playgroud)

所以,这里的问题是在我的客户端,如果我尝试 -

<a href="/auth/facebook">Login with Facebook</a>
Run Code Online (Sandbox Code Playgroud)

然后angularjs $ routeProvider首先捕获此路由并显示空白布局,因为没有使用此URL指定模板或控制器.所以,这个链接永远不会到达我在服务器中的快速路由配置中的路由功能.但是,当我直接在浏览器中打开此URL时,它会到达服务器,但之后它不会被重定向到任何页面.它只是停留在那里,网络选项卡中显示以下响应 -

Request URL:https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%3A%2F%2Fcampustop.in%2Fauth%2Ffacebook%2Fcallback&client_id=1440645942863962
Status Code:302 forced.302
Run Code Online (Sandbox Code Playgroud)

和网络选项卡中的一些响应标头.您可以访问http://campustop.in/auth/facebook查看它们

小智 9

我通过将target ="_ self"添加到链接标签来解决这个问题.

<a href="/auth/google" target="_self">Sign in with Google</a>
Run Code Online (Sandbox Code Playgroud)

执行此操作时,角度路由提供程序会忽略它并允许请求命中您的服务器.