我已经使用 看到了许多针对此的 JavaScript 修复window.location,但对于 Node.js 没有任何修复。
我正在使用 OAuth 将用户连接到 Facebook。获得授权后,Facebook 会重定向到您的回调 URL 并在其后附加“# = ”。问题出在我的回调路由中,我重定向到另一个 URL,但 URL 片段(哈希)正在被转移。
这是我的 Facebook 回调路线:
exports.facebook_signin_complete = function(req, res)
{
res.redirect('/profile');
};
Run Code Online (Sandbox Code Playgroud)
如果我删除重定向,则 URL 为/auth/facebook/callback#_=_,如果我保留重定向,则 URL 为/profile#_=_。为什么哈希被结转?这是一个页面特定的锚点标记,所以如果这是它应该做的,我会感到非常惊讶。
Facebook 和 Google 是否有任何独特且不变的代币可供我使用?
一旦我从 Oauth 登录中获取令牌和用户信息,我就可以在我的数据库中搜索具有该电子邮件的用户并创建一个帐户(如果它不存在)。
问题是,即使 oauth 令牌和电子邮件是真实的,我仍然希望在查找用户时在数据库查询中使用第二个令牌。
当我创建用户以帮助确保登录过程的安全性时,Google 和 Facebook 是否有任何唯一的 ID 字段可以与电子邮件捆绑在一起?
ps 如果有任何已知的验证或令牌生成包可能对我有帮助,我正在使用 Mean 堆栈和passportjs。
谢谢。
我有一个可行的解决方案,但我想知道这是否是正确的方法。这是我到目前为止所得到的。
我将 ASP.Net Core 1.1.2 与 ASP.NET Core Identity 1.1.2 一起使用。
Startup.cs 中的重要部分如下所示:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...
app.UseFacebookAuthentication(new FacebookOptions
{
AuthenticationScheme = "Facebook",
AppId = Configuration["ExternalLoginProviders:Facebook:AppId"],
AppSecret = Configuration["ExternalLoginProviders:Facebook:AppSecret"]
});
}
Run Code Online (Sandbox Code Playgroud)
FacebookOptions 附带 Microsoft.AspNetCore.Authentication.Facebook nuget 包。
AccountController.cs 中的回调函数如下所示:
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
//... SignInManager<User> _signInManager; declared before
ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync();
SignInResult signInResult = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false);
byte[] thumbnailBytes …Run Code Online (Sandbox Code Playgroud) c# facebook-graph-api facebook-oauth asp.net-identity asp.net-core
我正在使用 Node 开发简单的 Web 应用程序,并使用 Facebook 身份验证进行反应。我还遵循了一些有关该主题的教程,但在这些实现中,客户端和后端位于同一服务器上。在这里,我的后端服务器在 localhost:5000 上运行,并在 localhost:3000 上运行应用程序。在react package.json中有到后端的代理,因此客户端知道如何调用api。
\n\n当我单击“使用 Facebook 登录”按钮时,我将重定向到 Facebook 页面,在其中我授权应用程序并接收我的客户端应用程序配置文件 ID 和其他请求的用户信息。然而,当我将用户信息发送到后端服务器时,我可以在控制台中看到以下错误:
\n\n\n\n\n跨源请求被阻止:同源策略不允许读取远程资源https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fapi%2Fauth%2Ffacebook% 2Fcallback&client_id=1617633901657669。(原因:CORS 标头 \xe2\x80\x98Access-Control-Allow-Origin\xe2\x80\x99 丢失)。
\n
下面你可以看到:
\n\n\n\n\n类型错误:尝试获取资源时出现网络错误。\n [了解更多]
\n
Facebook 应用程序设置:
\n\n\n\nOAuth 路由器:
\n\nconst router = require(\'express\').Router();\nconst passport = require(\'../config/facebook-passport\');\n\nrouter.get(\'/facebook\', passport.authenticate(\'facebook\'));\n\nrouter.get(\'/facebook/callback\',\n passport.authenticate(\'facebook\', { failureRedirect: \'/login\' }),\n function(req, res) {\n console.log(\'Successful authentication, redirect home\');\n res.redirect(\'/\');\n });\n\nmodule.exports = router;\nRun Code Online (Sandbox Code Playgroud)\n\n护照脸书:
\n\nconst passport = require(\'passport\');\nconst …Run Code Online (Sandbox Code Playgroud) node.js facebook-oauth reactjs passport-facebook passport.js
我正在尝试使用新的fbsr _ {{appID}} Cookie.
我正在使用以下函数来解析它,但是当我尝试获取access_token之后,我收到'验证验证码错误'消息.这些解析函数有问题吗?如果没有,可能是什么问题?
更多信息:我设法使用oauth链接在没有cookie的情况下登录用户,该链接以代码作为参数重定向回我的网站,因此它不能是app id,app secret或redirect_uri.另一个原因是它们有不同的错误信息.
def base64_url_decode(inp):
padding_factor = (4 - len(inp) % 4) % 4
inp += "="*padding_factor
return base64.b64decode(unicode(inp).translate(dict(zip(map(ord, u'-_'), u'+/'))))
def parse_signed_request(signed_request, secret):
l = signed_request.split('.', 2)
encoded_sig = l[0]
payload = l[1]
sig = base64_url_decode(encoded_sig)
data = json.loads(base64_url_decode(payload))
if data.get('algorithm').upper() != 'HMAC-SHA256':
logging.error('Unknown algorithm')
return None
else:
expected_sig = hmac.new(secret, msg=payload, digestmod=hashlib.sha256).digest()
if sig != expected_sig:
return None
else:
logging.debug('valid signed request received..')
return data
args = {}
args['client_id'] = fbapp_id
args['redirect_uri'] = …Run Code Online (Sandbox Code Playgroud) 有许多资源用于描述客户端,Facebook/LinkedIn/Twitter API用法方面的OAuth使用情况.还行吧.但我对OAuth服务器实现感兴趣.目标是让Web应用程序也可以被移动设备(本机应用程序)访问,因此我需要在我的后端Java服务器上设置OAuth.所以我想知道LinkedIn/Facebook/Twitter如何在服务器端实现OAuth,并在auth_token-s之间区分用户并授予相应的访问权限(某种数据库映射 - auth_token =用户身份?).
或者可能有更好的方法来验证移动用户(我将为后端使用REST风格的服务)?
我有以下错误.我怎么能抓到这个错误?
致命错误:未捕获OAuthException:验证访问令牌时出错:用户638720122未授权应用程序207445576002891.在第1039行的/var/www/clients/client1/web12/web/socialmediaping/fblibrary/base_facebook.php中引发
我有以下代码片段,我相信我会尝试管理错误.
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error) {
$facebookAuth = FALSE;
}
Run Code Online (Sandbox Code Playgroud)
如果$ facebookAuth == FALSE,我将用户重定向到facebook以进行身份验证,但这不起作用,那么我应该怎么做?
非常感谢您的帮助.
我已经阅读了1000多个关于如何在两次调用OAuth中获取用户令牌时redirect_uri必须相同的博客,但是100%的时间,无论我如何格式化URL,它都失败了:
{
"error": {
"message": "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request",
"type": "OAuthException",
"code": 100
}
}
Run Code Online (Sandbox Code Playgroud)
我一丝不苟地确保两个调用中的URL完全相同.我的网址必须有?在它,我尝试用%3f替换它,但这没有帮助.必须有其他可能导致此错误的东西,我需要了解可能是什么?
在过去的一个月里,这对我来说似乎有所突破.我们在7月下旬做了一个节目,事情很顺利(因为它是一个不同的服务器,因为该节目有不同的基本URL).可能是URL是这种格式:
someprestuff.morestuff.mainurl.com?prm=value
Run Code Online (Sandbox Code Playgroud)
Facebook的URL有太多"部分"可以接受吗?
我正在寻找替代品寻找.
我在我的应用程序中使用spring-security-oauth-facebook:0.1 grails插件.现在我想访问人的电子邮件ID,但我不能每次facebook服务器响应1829812989120 for socialId,Username,profileId并且没有电子邮件选项在返回Map对象时.为什么会发生这种情况.
oauth {
debug = true
providers {
facebook {
api = org.scribe.builder.api.FacebookApi
key = 'my-app-key'
secret = 'secret-key'
successUri = '/oauth/facebook/success'
failureUri = '/oauth/facebook/failure'
callback = "${baseURL}/oauth/facebook/callback"
scopes = "['public_profile','email','name','user']"
}
def sessionKey = oauthService.findSessionKeyForAccessToken(provider)
if (!session[sessionKey]) {
log.warn "No OAuth token in the session for provider '${provider}'"
throw new OAuthLoginException("Authentication error for provider '${provider}'")
}
// Create the relevant authentication token and attempt to log in.
OAuthToken oAuthToken = springSecurityOAuthService.createAuthToken(provider,
session[sessionKey])
println "oAuthToken.principal …Run Code Online (Sandbox Code Playgroud) 我正在使用Facebook的图形API来授权应用程序.我刚刚授权应用程序
并从重定向uri获得access_token,并且到期时间更短.
然后我就用了
这样可以获得具有更高过期时间的access_token.
问题是我从这种方法得到的响应格式是text/plain.就像
access_token=EAAYZC5w2OP4kBAKNU7nfSKRkdlrGeE2ZCamo8CSTEFZAwzZBMgqlPxPZATTE8EPpM0rdJJX1Rh7ZA8ABZAeOqt0ZA3OxldZB3nnfPWUrcqdTa5R0q9nas1T0OXSZChKgUyxzZBh5Ugbjvm4GMixVcM8vo2tZCdo3YUZD&expires=5184000
我的问题是如何获得响应application/json format.任何帮助将不胜感激 !!!
facebook-oauth ×10
oauth ×3
oauth-2.0 ×3
facebook ×2
node.js ×2
api ×1
asp.net-core ×1
c# ×1
google-oauth ×1
grails ×1
java ×1
javascript ×1
mobile ×1
passport.js ×1
php ×1
python ×1
reactjs ×1