在HybridAuth中还原访问令牌

在HybridAuth中还原访问令牌

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

问题描述

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

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

如何

推荐答案

这在Hybridauth用户手册中用以下代码进行了解释:

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是获取存储数据的内部函数。
不管将数据存储在表中名为 external_token的字段中,还是通过常规的sql查询获取数据,然后将其馈送到以下函数中,都没关系:

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);将恢复序列化的会话对象,然后将为其保存的任何提供程序获取一个适配器。最好也将提供者名称(在这种情况下为Twitter)与external_provider之类的内容保存在同一数据库表中,然后可以通过sql auery获取它并将其提供给getAdapter函数。

$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.

手动示例如下:

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

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

作为附加信息-我在测试中看到的是,将会话保存在即使用户同时撤消了从应用程序的访问权限,这种方式也不会阻止hybridauth登录用户。即,如果用户已经登录并获得授权,但是单独进入了该应用并撤消了访问权限(例如Google),hybridauth仍将用户登录到您的系统中。我目前正在尝试寻找一种方法来确保用户也登录到远程系统。

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中还原访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 20:58