jolicode / slack-php-api

:hash: PHP Slack Client based on the official OpenAPI specification
https://jolicode.github.io/slack-php-api/
MIT License
222 stars 56 forks source link

No way to access OAuth Access Token. #71

Closed Root3287 closed 4 years ago

Root3287 commented 4 years ago

When executing the following code. All I was able to access getOk method, There is no way to access the access token.

$client->oauthAccess([
"redirect_uri" => "/path/to/redirectURI/",
"client_id" => Settings::where('key', 'slack.client.id')->first()->value,
"client_secret" => Settings::where('key', 'slack.client.secret')->first()->value,
"code" => $request->getQueryParams()["code"], 
]);

https://api.slack.com/methods/oauth.access

pyrech commented 4 years ago

Hello,

Thanks for opening an issue. As we explain in our documentation, our generated SDK is mainly dependent from the completeness of Slack's official API specification. In this case, their spec indeed only defines one property for the oauth.access end (ok - which is not useful at all).

FYI we did not need this endpoint yet because we usually use another package to handle the OAuth2 flow. Thus we did not came across this problem :confused:

To bypass those missing definitions, we have a patch system that allow us to fix their spec and build a better SDK. Fun fact is that their spec often describe - for each endpoint - an example of a response which contains all the fields. So this is quite easy to locally fix the OpenAPI spec, generate a patch and regenerate the SDK. All the procedure is describe in our documentation: https://github.com/jolicode/slack-php-api/blob/master/doc/updating-sdk.md#apply-local-modification

Would you mind to give a try and submit a PR? That would be awesome :wink: If not, don't worry we will try to have a look in the coming days.

ftipalek commented 4 years ago

Hi, we've also experienced this problem. In our case response JoliCode\Slack\Api\ModelOauthAccessGetResponse200 of client->oauthAccess() contains only ok property and nothing else.

We've implemented workaround that client.oauthAccess returns raw response \Psr\Http\Message\ResponseInterface so we can bypass the problem.

$response = $slackClient->oauthAccess(
    [
        'client_id' => '>clientId<',
        'client_secret' => '>clientSecret<',
        'code' => '>authCode<',
        'redirect_uri' => '>redirectUrl<',
    ],
    JoliCode\Slack\Api\Client::FETCH_RESPONSE
);

$result = json_decode((string) $response->getBody(),TRUE);

$incomingWebhook = $result['incoming_webhook'];

Is there any plan to fix this bug in the library?

pyrech commented 4 years ago

I just merged #76 so you should now be able to retrieve the token with the SDK :slightly_smiling_face:

I plan to release this as a new minor version (aka 2.5) in a few days. In the meantime, you can use dev-master version to try it :wink:

SimonPrague commented 3 years ago

Any chance you can do the same change also for: oauthV2Access

Thanks!