Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open_platform.oauth 过早的获取 access token #701

Closed
tsunamilx opened this issue May 16, 2017 · 1 comment
Closed

open_platform.oauth 过早的获取 access token #701

tsunamilx opened this issue May 16, 2017 · 1 comment
Labels

Comments

@tsunamilx
Copy link
Contributor

我用的环境

PHP 版本:
overtrue/wechat 版本:3.3.2

问题及现象

看下面

\EasyWeChat\Foundation\ServiceProviders\OpenPlatformServiceProvider

// OAuth for OpenPlatform.
$pimple['open_platform.oauth'] = function ($pimple) {
    $callback = $this->prepareCallbackUrl($pimple);
    $scopes = $pimple['config']->get('open_platform.oauth.scopes', []);
    $socialite = (new Socialite([
        'wechat_open' => [
            'client_id' => $pimple['open_platform.authorizer']->getAppId(),
            'client_secret' => [
                $pimple['open_platform.access_token']->getAppId(),

                // 这里过早的获取 token
                $pimple['open_platform.access_token']->getToken(),
            ],
            'redirect' => $callback,
        ],
    ]))->driver('wechat_open');

    if (!empty($scopes)) {
        $socialite->scopes($scopes);
    }

    return $socialite;
};

如此 $openPlatorm->createAuthorizerApplication() 时就会触发获取 token,无论是否使用 oauth。
缓存无效的情况下,明显减慢应用的初始化,而且如果 token 过期后,在使用 oauth 就会报错了吧。

直接这样可行否?

'client_secret' =>$pimple['open_platform.access_token']

等实际用上的时候在获取。

@mingyoung
Copy link
Collaborator

的确存在这个问题

@mingyoung mingyoung added the Bug label May 16, 2017
overtrue pushed a commit that referenced this issue May 16, 2017
* update socialite version.

* Fix #701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants