在 hybridauth 中恢复访问令牌 [英] Restore Access Token in hybridauth

查看:17
本文介绍了在 hybridauth 中恢复访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将访问令牌(使用此方法:getAccessToken())保存在我的数据库中,但现在我想将此值恢复到一个对象中.

我该怎么做?

解决方案

hybridauth 用户手册对此进行了解释,代码如下:

<块引用>

//从你的存储系统中获取存储的混合验证数据$hybridauth_session_data = get_sorted_hybridauth_session( $current_user_id );

Get_sorted_hybridauth_session 是您获取存储数据的内部函数.无论您是将数据存储在名为external_token"的字段中还是其他字段中的表中,通过普通的 sql 查询获取它,然后将其提供给以下函数:

<块引用>

//然后调用 Hybrid_Auth::restoreSessionData() 获取存储的数据$hybridauth->restoreSessionData( $hybridauth_session_data );//回调一个 Twitter 适配器实例$twitter = $hybridauth->getAdapter("推特");//重新获取用户配置文件$user_profile = $twitter->getUserProfile();

$hybridauth->restoreSessionData($hybridauth_session_data);将恢复序列化的会话对象,然后它将为保存它的任何提供程序获取一个适配器.最好将提供者名称(在本例中为 Twitter)与诸如 external_provider 之类的内容保存在同一个数据库表中,然后您可以通过 sql auery 获取它并将其提供给 getAdapter 函数.那应该做你需要做的事情.

手动示例如下:

http://hybridauth.sourceforge.net/userguide/HybridAuth_Sessions.html

==============

作为附加信息 - 我在测试中看到的是,以这种方式保存会话并不会阻止 hybridauth 登录用户,即使用户在此期间撤销了对应用程序的访问.即,如果用户已经登录并获得授权,但是,单独进入应用程序并撤销了访问权限(例如谷歌),hybridauth 仍会将用户登录到您的系统.我目前正试图找到一种方法来确保用户也登录到远程系统.

I saved the Access Token (using this method: getAccessToken ()) in my database, but now I would like to restore this value to an object.

How can I do this?

解决方案

This is explained in hybridauth user manual with below code :

  // get the stored hybridauth data from your storage system
   $hybridauth_session_data = get_sorted_hybridauth_session( $current_user_id );

Get_sorted_hybridauth_session is your internal function to get the stored data. It doesnt matter whether you store the data in a table in a field named 'external_token' or something, get it through a normal sql query, and then just feed it to below function :

   // then call Hybrid_Auth::restoreSessionData() to get stored data
   $hybridauth->restoreSessionData( $hybridauth_session_data );

   // call back an instance of Twitter adapter
   $twitter = $hybridauth->getAdapter( "Twitter" ); 

   // regrab te user profile
   $user_profile = $twitter->getUserProfile();

$hybridauth->restoreSessionData( $hybridauth_session_data ); will restore the serialized session object, and then it will get an adapter for whichever provider it was saved for. Its best that you also save the provider name (Twitter in this case) in the same database table with something like external_provider , and then you can get it through a sql auery and feed it to getAdapter function. That should do what you need to do.

The manual example is below :

http://hybridauth.sourceforge.net/userguide/HybridAuth_Sessions.html

=============

As an added info - what i saw in my tests was, saving session in this way does not prevent hybridauth from logging the user in, even if the user has revoked access from the app in the meantime. Ie, if user is already logged in and authorized, but, went to the app separately and revoked the access (google for example), hybridauth will still log in the user to your system. Im currently trying to find a way to make sure the user is logged to the remote system too.

这篇关于在 hybridauth 中恢复访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆