w7corp/easywechat · error · HttpException

Failed to get auth_corp_info: %s

Error message

Failed to get auth_corp_info: %s

What it means

OpenWork\Application::getAuthorization() POSTs auth_corpid plus permanent_code to cgi-bin/service/get_auth_info, authenticated by the suite access token, and throws HttpException with the raw JSON when auth_corp_info is absent. WeChat Work declined to return the authorizer corp's profile for that permanent code.

Source

Thrown at src/OpenWork/Application.php:225

    public function getAuthorization(
        string $corpId,
        string $permanentCode,
        ?AccessTokenInterface $suiteAccessToken = null
    ): Authorization {
        $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken();

        $response = $this->getHttpClient()->request('POST', 'cgi-bin/service/get_auth_info', [
            'query' => [
                'suite_access_token' => $suiteAccessToken->getToken(),
            ],
            'json' => [
                'auth_corpid' => $corpId,
                'permanent_code' => $permanentCode,
            ],
        ])->toArray(false);

        if (empty($response['auth_corp_info'])) {
            throw new HttpException('Failed to get auth_corp_info: '.json_encode($response, JSON_UNESCAPED_UNICODE));
        }

        return new Authorization($response);
    }

    public function getAuthorizerAccessToken(
        string $corpId,
        string $permanentCode,
        ?AccessTokenInterface $suiteAccessToken = null
    ): AuthorizerAccessToken {
        $suiteAccessToken = $suiteAccessToken ?? $this->getSuiteAccessToken();

        return new AuthorizerAccessToken(
            corpId: $corpId,
            permanentCodeOrAccessToken: $permanentCode,
            suiteAccessToken: $suiteAccessToken,
            cache: $this->getCache(),
            httpClient: $this->getHttpClient(),

View on GitHub (pinned to f0cf0a8b83)

Solutions

  1. Decode the embedded errcode/errmsg to classify the refusal
  2. Verify you stored and are sending the permanent_code obtained from the initial auth-code exchange, not the temporary code
  3. If the authorization was revoked, mark that corp inactive and restart the install flow
  4. Refresh the suite access token and retry the call once

Example fix

// before: using the temporary code from the install redirect
$auth = $openWork->getAuthorization($corpId, $temporaryAuthCode);

// after: query with the persisted permanent code from the initial exchange
$auth = $openWork->getAuthorization($corpId, $row->permanent_code);
Defensive patterns

Strategy: try-catch

Validate before calling

if (blank($permanentCode) || $permanentCode === $temporaryAuthCode) {
    throw new \RuntimeException('A valid permanent_code (not the temporary auth code) is required.');
}

Try / catch

try {
    $auth = $openWork->getAuthorization($corpId, $permanentCode);
} catch (\EasyWeChat\Kernel\Exceptions\HttpException $e) {
    $payload = json_decode(strstr($e->getMessage(), '{') ?: '[]', true) ?: [];
    // invalid permanent code → mark corp for reinstall; invalid suite credential → refresh suite token first
    report($e);
}

Prevention

When it happens

Trigger: The corp revoked the suite app (permanent_code invalidated); the temporary auth code from the install redirect was passed instead of the exchanged permanent_code; permanent_code belongs to a different suite; suite_access_token expired or invalid so the query credential is rejected.

Common situations: An authorizer uninstalls the app from the WeChat Work admin; the DB stored the initial temporary code rather than the permanent one; rows lost or stale after partial migrations; idle installations with expired suite tokens.

Related errors


AI-assisted analysis of w7corp/easywechat@f0cf0a8b83 (2026-08-21). Data as JSON: /api/errors/c05a29d1b562112a. Report an issue: GitHub.