Skip to content

神超你好,关于企业微信 userFromCode 的相关问题,无法直接获取敏感信息了 #296

@tlerbao

Description

@tlerbao

构造的 oauth 链接 scope= snsapi_privateinfo,并且用户授权了敏感信息的情况下

在 overtrue/socialite=3.5.4 中,下面这样写是可以获取用户获取敏感信息

$app->oauth->detailed()->userFromCode($code)

但是在overtrue/socialite=4.12.1中却不行了

追了一下代码发现 userFromCode 代码变了

为什么要改这部分代码呢?有点疑惑

https://easywechat.com/5.x/wework/oauth.html 文档还是没变得。

官方文档也是用user_ticket 来获取用户敏感信息的
https://developer.work.weixin.qq.com/document/path/95833

public function userFromCode(string $code): User
    {
        $token = $this->getApiAccessToken();
        $user = $this->getUser($token, $code);

        if ($this->detailed) {
            $userTicket = $user['user_ticket'] ?? '';
            $user = $this->getUserById($user['UserId']);
            if ($userTicket) {
                $user += $this->getUserDetail($userTicket);
            }
        }

        return $this->mapUserToObject($user)->setProvider($this)->setRaw($user);
    }

变成了

public function userFromCode(string $code): Contracts\UserInterface
    {
        $token = $this->getApiAccessToken();
        $user = $this->getUser($token, $code);

        if ($this->detailed) {
            if (empty($user['UserId'])) {
                throw new Exceptions\AuthorizeFailedException('Authorization failed: missing UserId in user response', $user);
            }
            $user = $this->getUserById($user['UserId']);
        }

        return $this->mapUserToObject($user)->setProvider($this)->setRaw($user);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions