How do i send following curl request with php
$ curl -X POST -u "client_id:secret" https://bitbucket.org/site/oauth2/access_token
-d grant_type=authorization_code -d code={code}
How do i send following curl request with php
$ curl -X POST -u "client_id:secret" https://bitbucket.org/site/oauth2/access_token
-d grant_type=authorization_code -d code={code}
Use GuzzleHttp.
<?php
$client = new GuzzleHttp\Client();
$response = $client->request('POST', 'https://bitbucket.org/site/oauth2/access_token', [
'auth' => ['client_id', 'secret'],
'form_params' => [
'grant_type' => 'authorization_code',
'code' => 'code'
]
]);
$code = $response->getStatusCode(); // must be 200
$reason = $response->getReasonPhrase(); // must be OK
$body = (string) $response->getBody(); // must have your data
Attention, if you are implementing an OAuth Client, I strongly recommend using an opensource library: