【问题标题】:YII2 OAuth Client Instagram - Instagram drops "authclient=instagram" when redirectingYII2 OAuth Client Instagram - Instagram 在重定向时丢弃“authclient=instagram”
【发布时间】:2018-07-23 11:22:57
【问题描述】:

我正在使用 yii2 oauthclinet 扩展 kotchuprik/yii2-instagram-authclient

所以它的工作原理,但有一件事不起作用

我在 instagram 中注册了我的应用 redirurl 像这样

myappurl/site/auth?authclient=instagram

所以我期望的重定向网址应该是这样的:

myappurl/site/auth?authclient=instagram&code=....

但它来了:

myappurl/site/auth?code=...

在我认识的浏览器中使用开发者工具:

https://www.instagram.com/accounts/login/ajax/

username=myusernam
password=mypassword
queryParams={"next":"/oauth/authorize?client_id=theclientid&   
response_type=code&redirect_uri=myappurl/site/auth?authclient=instagram&
xoauth_displayname=MyApps&state=statenumbers"}

所以下一个获取请求是错误的可以吗

https://www.instagram.com/oauth/authorize?client_id=theclientid&
response_type=code&redirect_uri=myappurl%2Fsite%2Fauth%3Fauthclient&
xoauth_displayname=MyApps&state=statenumbers

client_id=theclientid
response_type=code
redirect_uri=myappurls%2Fsite%2Fauth%3Fauthclient
xoauth_displayname=MyApp
state=statenumbers

=instagram 不见了

来自 instagram 的重定向网址是:

myappurl/site/auth?code=codenumbers&state=statenumbers

所以这是错误的 authclient=instagram 丢失了,我不知道为什么

有什么想法吗?

【问题讨论】:

  • 如果我理解正确,您需要将参数authclient 添加到您的操作中,目前SiteController 中的actionAuth 类似于function actionAuth($codenumber,$state),对吗?
  • 我在 Yii2 Docs 中集成了 authAction:'auth' => [ 'class' => '\common\components\AuthAction', //'yii\authclient\AuthAction', 'successCallback' =...如果 authclient 作为参数返回它的工作正常。问题我不知道为什么 instagram 的返回 url 没有这个参数。如果我再次调用 auth 操作,则返回 url 是正确的,并且登录/登录工作正常。但是我在哪里或为什么在没有 autclient 的情况下获得返回 url。我找不到这个参数下降发生的地方。

标签: oauth yii2 instagram


【解决方案1】:

我做了一个小变通方法,不是很漂亮,但工作正常。

`class AuthAction extends \yii\authclient\AuthAction
{

public function run()
{
$clientId = Yii::$app->getRequest()->getQueryParam($this->clientIdGetParamName);
if (!empty($clientId)) {
    $collection = Yii::$app->get($this->clientCollection);
    if (!$collection->hasClient($clientId)) {
        throw new NotFoundHttpException("Unknown auth client '{$clientId}'");
    }
    $client = $collection->getClient($clientId);

    return $this->auth($client);
} else {
    $clientId = 'instagram';
    $collection = Yii::$app->get($this->clientCollection);
    if (!$collection->hasClient($clientId)) {
        throw new NotFoundHttpException("Unknown auth client '{$clientId}'");
    }
    $client = $collection->getClient($clientId);

    return Yii::$app->response->redirect(['/site/auth','authclient'=>'instagram']);

}

 // throw new NotFoundHttpException();
}
}`

所以我认为 instagram 认识到在此设备上登录了一个 instagram 用户,并且返回的不是带有 authclient 参数的定义或预期的 url。或者它是一个 Instagram 错误 :-)。

如果有人有类似的问题,那就太好了,那就是更多的人被这个问题感染。所以我们可以得到一个解决方案。

【讨论】:

    猜你喜欢
    • 2017-03-07
    • 2022-09-26
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多