node.js - Angular 和 Node js Twitter 登录
问题描述
我正在尝试使用 Angular 和节点 js 进行 twitter 身份验证,但它不起作用。我有这个角度:
signInWithTwitter() {
this.http.get(`http://localhost:3000/twitter`, { withCredentials: true }).subscribe((results) =>
{
// The url is -> https://api.twitter.com/oauth/authenticate?oauth_token=xxxx
window.location.href = results["url"];
});
}
我正在发送 window.location.href 因为我无法从 angular 调用任何外部链接,并且在节点 js 上我有:
var _requestSecret;
app.get("/twitter", (req, res) => {
tw.login((err, tokenSecret, url) => {
if (err) {
// Handle the error your way
}
// Save the OAuth token secret for use in your /twitter/callback route
_requestSecret = tokenSecret;
res.json({ url: url });
});
});
节点js上的回调函数是:
app.get("/twitter/callback", (req, res) => { tw.callback({
oauth_token: req.query.oauth_token,
oauth_verifier: req.query.oauth_verifier,
},
_requestSecret,
(err, user) => {
if (err) {
// Handle the error your way
}
// Redirect to whatever route that can handle your new Twitter login user details!
res.redirect("http://localhost:4200/");
}
);
});
我在 twitter/callback 上有用户,但我需要一种将用户发送到 Angular 的方法。
解决方案
推荐阅读
- android - 如何通过dataBinding访问fragment中activity的父视图
- asp.net-core - 如何在 ASP.NET Core 中禁用响应解压?
- javascript - 检查 localStorage 中的值是否以字符串和 console.log() 值名称开头
- tensorflow - Why Spark ML perceptron classifier has high F1-score while the same model on TensorFlow performs very badly?
- devexpress - 无法将用户可控参数链接到查询:DevExpress Report and Dashboard Server
- maven - Tomcat 8 战争部署 LifecycleException:无法启动组件
- c++ - c ++神经网络路径查找不动
- typescript - 使用它来测试 vuejs/typescript 组件时的笑话错误
- performance - 矛盾的 VTune Amplifier 微架构探索结果
- scala - 如何在火花中将 RDD[Result] 转换为 RDD[Row]?