NodeJs使用passportJS OAuth2配置并运行良好,但需求是角应该调用节点api,两者都运行在不同端口的中,从调用所有nodeJS的rest,使用proxy.conf.json运行良好,而从角度获取错误响应调用/googleauth/redirect。
答复:
Failed to load https://accounts.google.com/o/oauth2/v2/auth?response_type=code... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Google设置:
限制
授权的JavaScript来源:
http://localhost:4200
http://localhost:8088授权重定向城市信息系统:
http://localhost:4200/api/googleauth/redirect
http://localhost:8088/api/googleauth/redirect更新1: CORS到app.js (新的):但没有更改。
var cors = require('cors');
var app = express();
app.use(cors());
app.options('*', cors());
app.use('/api',cors(),require('./routes/api'));更新2: api.js
router.get('/google', passport.authenticate('google', { scope: ['profile','email'] }));护照设置
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20');
const userModel = require('../model/user');
passport.serializeUser((user,done)=>{
done(null,user.id);
});
passport.deserializeUser((id,done)=>{
userModel.findById(id).then((user)=>{
done(null,user);
})
});
passport.use(
new GoogleStrategy({
callbackURL:'/api/googleauth/redirect',
clientID:'',
clientSecret:''
},(accessToken,refreshToken,profile,done) =>{
console.log("call back function fired");
//console.log(accessToken);
userModel.findOne({email:profile.emails[0].value,authType:'google'},function(err,user){
if(user){
done(null,user);
}else{
done(null,user);
}
});
}))发布于 2018-02-07 20:41:18
只是缺少细节..。在从‘@ BrowserXhr /http’导入{CustExtBrowserXhr}的行旁边,从‘./app/path- to /cust-ext-browser-xhr’导入{CustExtBrowserXhr};您应该从‘@LocationStrategy/公用’中添加导入{ LocationStrategy,HashLocationStrategy };
https://stackoverflow.com/questions/48616610
复制相似问题