验证用户是否从WordPress 4.0以后的其他应用程序登录

时间:2016-04-20 作者:Nicolas Frbezar

我尝试在我的节点中实现。js应用程序是验证用户cookie是否有效的一种方法。我在互联网上找到了一些帖子,他们很好地向我解释了这些事情,但当我尝试实现它时,我使用了Node的WordPress身份验证模块。js,我发现它不起作用了。

经过一些搜索,我发现WordPress 4.0 出于某种原因:

现在,如果logged_in cookie name is still hashed with MD5, 哈希salted密码现在为sha256 (or sha1 if impossible) encrypted, 考虑WordPress函数中的这部分代码wp_generate_auth_cookie() :

// If ext/hash is not present, compat.php\'s hash_hmac() does not support sha256.
$algo = function_exists( \'hash\' ) ? \'sha256\' : \'sha1\';
$hash = hash_hmac( $algo, $user->user_login . \'|\' . $expiration . \'|\' . $token, $key );
我不确定,但正如我在代码中发现的那样,自WordPress 4.0以来,登录的salt不再使用,但在WP\\U Session\\U令牌中定义了令牌的用法,如下所示:

$manager = WP_Session_Tokens::get_instance( $user_id );
$token   = $manager->create( $expiration );
所以我想知道:is there a way from wordpress 4.0 to verify logged_in cookie ?

1 个回复
最合适的回答,由SO网友:Nicolas Frbezar 整理而成

好的,我找到了解决方案。

事实上,我没有注意到,there is always the hashed mdp, 但目前,logged\\u in cookie的结构如下:

%登录%|%超时%|%sessionId%|%已过期%

而不是:

%登录%|%超时%|%passhached%

自wordpress 4.0和wp\\u session\\u cookie集成以来,auth方法与之前相同,但只有两个变化:

  • the sessionid is introduced 在cookie和密钥计算中,登录的cookie加密为sha256 or if not possible sha1

    KEY = md5_HMAC(%login%|%caracter 8-12 of the passhached in database%|%timeout%|%sessionId% , LOGGED_IN_KEY.LOGGED_IN_SALT);
    
    RESULT = sha256_HMAC(%login%|%timeout%|%sessionId% , KEY);
    // RESULT = sha1_HMAC(%login%|%timeout%|%sessionId% , KEY); only if sha256 is not supported
    
    现在,要批准连接,登录的\\u cookie的pass hached需要与RESULT相同

相关推荐

Content-Security-Policy标头存在并显示正确的设置,但仍收到拒绝的连接

所以我把一个插件放在一起,它允许我用一个在线服务连接多个客户端站点。我可以让服务供应商代码段加载,但一旦你与它交互,事情就会变得棘手,它拒绝加载(我猜)iframe。。。它的文档记录很差。Refused to load https://www.service-domain.com/ because it does not appear in the frame-ancestors directive of the Content Security Policy.这是我收到的控制台日志错误。因此,我跳回插件