我正在尝试使用我的应用程序进行Facebook身份验证.但到目前为止,我的尝试都没有成功.我是Node的新手.
当用户单击该fb登录按钮时,该请求需要被带到/ auth/facebook路由,在那里它们将被传递到Passport策略.他们将被发送到Facebook进行身份验证.但它永远不会发生.Facebook认证窗口永远不会显示出来.看起来重定向不起作用.我做了几个小时的搜索,但没有得到解决方案.

以下是我认为对此上下文很重要的代码部分
我把我的App ID和App Secret放在config/auth.js中
module.exports = {
'facebookAuth' : {
'clientID' : 'my-AppID-here',
'clientSecret' : 'my-App-secret-here',
'callbackURL' : 'http://localhost:8080/auth/facebook/callback'
}
};
Run Code Online (Sandbox Code Playgroud)
使用Facebook进行身份验证并处理回调的策略在config/passport.js中进行
var LocalStrategy = require('passport-local').Strategy;
var FacebookStrategy = require('passport-facebook').Strategy;
// load up the user model and auth variables
var User = require('../app/models/user');
var configAuth = require('./auth');
module.exports = function(passport) {
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
// Facebook Strategy
passport.use(new FacebookStrategy({
// pull …Run Code Online (Sandbox Code Playgroud) 编程时可重用性非常重要,我们可以采取的任何措施来减少代码重复,这将有助于我们解决问题.
我必须使用Modal弹出窗口向Angular 2项目中的许多地方的用户显示信息.我正在使用ng-bootstrap,并且所有这些Modals都具有相同的页眉和页脚,但在许多情况下更改了正文.有时候身体只是想要替换一个占位符,有时候它有一些复杂性来准备动态内容.这些由不同的组件触发或管理.
ng-bootstrap允许我们以两种方式将内容传递给Modal.
<ng-template></ng-template>使用第一种方法,我必须每个模态重复写标题,正文和页脚.
使用第二种方法,我可以将HTML包装在组件中,但需要放置占位符以使其动态化.所以我可以按如下方式传递值
open() {
const modalRef = this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name = 'World';
}
Run Code Online (Sandbox Code Playgroud)
但灵活性仍然有限.
所以,在我的Common Modal的主体中看起来如下.我把它<ng-content></ng-content>作为Modal身体的一个插槽.
@Component({
selector: 'common-modal',
template: `
<!-- Modal -->
<div class="modal fade" id="common-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{{title}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<ng-content></ng-content>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div> …Run Code Online (Sandbox Code Playgroud) 我试图通过调用一个成功提供JWT令牌的快速api来验证来自Angular 2应用程序的用户.我有一个疑问要清楚.
我们是否要求快递设置cookie,或者是使用令牌设置cookie的Angular作业
loginUser(email: string, password: string) {
let headers = new Headers({ 'Content-Type': 'application/json'});
let options = new RequestOptions({headers: headers});
let loginInfo = { email: email, password: password };
return this.http.post('/auth/login', JSON.stringify(loginInfo), options)
.do(resp => {
// Do I need to set the cookie from here or it from the backend?
}).catch(error => {
return Observable.of(false);
})
}
Run Code Online (Sandbox Code Playgroud) angular ×2
cookies ×1
express ×1
facebook ×1
javascript ×1
ng-bootstrap ×1
node.js ×1
passport.js ×1