workos-php-laravel icon indicating copy to clipboard operation
workos-php-laravel copied to clipboard

Call to undefined method WorkOS\\Resource\\Profile::json()

Open flexchar opened this issue 9 months ago • 1 comments

Seems like an old method.

My Code:

$sso = new \WorkOS\SSO();
$profile = $sso->getProfile($token);

Error:

 "message": "Call to undefined method WorkOS\\Resource\\Profile::json()",
"exception": "Error",
"file": "/var/www/vendor/workos/workos-php/lib/SSO.php",
"line": 153,

Your code:

    /**
     * Verify that SSO has been completed successfully and retrieve the identity of the user.
     *
     * @param string $accessToken, the token used to authenticate the API call
     *
     * @throws Exception\GenericException
     *
     * @return \WorkOS\Resource\Profile
     */
    public function getProfile($accessToken)
    {
        $getProfilePath = "sso/profile";

        $params = [
            "access_token" => $accessToken
        ];

        $method = Client::METHOD_GET;

        $url = "https://api.workos.com/sso/profile";

        $requestHeaders = ["Authorization: Bearer " . $accessToken];

        list($result) = Client::requestClient()->request(
            $method,
            $url,
            $requestHeaders,
            null
        );

        $decodedResponse = json_decode($result, true);

        $profile = Resource\Profile::constructFromResponse($decodedResponse);

        return $profile->json();
    }

I'm on the latest version. If you cannot see why, please let me know.

Also, why do you have these that are not used anywhere.

        $getProfilePath = "sso/profile";

        $params = [
            "access_token" => $accessToken
        ];

Are you using code generator? :)

flexchar avatar Feb 27 '25 20:02 flexchar

Seems like an old method.

My Code:

$sso = new \WorkOS\SSO();
$profile = $sso->getProfile($token);

Error:

 "message": "Call to undefined method WorkOS\\Resource\\Profile::json()",
"exception": "Error",
"file": "/var/www/vendor/workos/workos-php/lib/SSO.php",
"line": 153,

Your code:

    /**
     * Verify that SSO has been completed successfully and retrieve the identity of the user.
     *
     * @param string $accessToken, the token used to authenticate the API call
     *
     * @throws Exception\GenericException
     *
     * @return \WorkOS\Resource\Profile
     */
    public function getProfile($accessToken)
    {
        $getProfilePath = "sso/profile";

        $params = [
            "access_token" => $accessToken
        ];

        $method = Client::METHOD_GET;

        $url = "https://api.workos.com/sso/profile";

        $requestHeaders = ["Authorization: Bearer " . $accessToken];

        list($result) = Client::requestClient()->request(
            $method,
            $url,
            $requestHeaders,
            null
        );

        $decodedResponse = json_decode($result, true);

        $profile = Resource\Profile::constructFromResponse($decodedResponse);

        return $profile->json();
    }

I'm on the latest version. If you cannot see why, please let me know.

Also, why do you have these that are not used anywhere.

        $getProfilePath = "sso/profile";

        $params = [
            "access_token" => $accessToken
        ];

Are you using code generator? :)

azooz2024-2030 avatar Jun 04 '25 07:06 azooz2024-2030