|
![Picture of Martin Babinec Picture of Martin Babinec](/graphics/unknown.gif) Martin Babinec - 2015-04-09 21:56:24
I'm trying to use this library for 2-legged authorization in bitbucket but I cannot find out how to do. I've already find out that in the CallApi method is in associative array argument $parameters a key '2Legged' which I probably have to set to true value. But I have to call firstly the Initialize and the Process functions and the Process functions do redirect to bitbucket anyway like in a 3-legged authorization. So what do I do wrong?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2015-04-10 02:44:36 - In reply to message 1 from Martin Babinec
Can you show a minimal example code that I can try to reproduce the problem?
![Picture of Martin Babinec Picture of Martin Babinec](/graphics/unknown.gif) Martin Babinec - 2015-04-10 06:15:50 - In reply to message 2 from Manuel Lemos
Of course. It's almost the same code like in the login_with_bibtucket.php file.
$client = new oauth_client_class;
$client->server = 'Bitbucket';
$client->redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/login_with_bitbucket.php';
$client->client_id = 'my_id';
$client->client_secret = 'my_secret_key';
if(strlen($client->client_id) == 0
|| strlen($client->client_secret) == 0)
die('Empty client id or client secret.');
if(($success = $client->Initialize()))
{
if(($success = $client->Process()))
{
if(strlen($client->access_token))
{
$success = $client->CallAPI(
'https://bitbucket.org/api/1.0/repositories',
'POST', array('name'=>'test'), array('FailOnAccessError'=>true,'2Legged'=>true), $data);
}
}
$success = $client->Finalize($success);
}
if($client->exit)
exit;
var_dump($data);
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2015-04-10 21:31:04 - In reply to message 3 from Martin Babinec
I tried in BitBucket REST browser and it seems 2 Legged auth does not work, at least for these requests.
However it works with No Auth or Basic Auth, at least for resources that are not private. Check it out here:
restbrowser.bitbucket.org/
![Picture of Martin Babinec Picture of Martin Babinec](/graphics/unknown.gif) Martin Babinec - 2015-04-11 12:07:41 - In reply to message 4 from Manuel Lemos
On the REST API Browser it seems that 2-legged auth works well. I can just write there my consumer key and secret key and it do neither a redirect nor any approval. It just works after that. Isn't some error in your library? I really need work with my private repositories and don't want to write my password directly to the code..
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2015-04-13 04:57:38 - In reply to message 5 from Martin Babinec
Oh, sorry, I was sending GET requests.
Anyway, I tried 3 legged requests and it could create the repositories successfully.
As for 2 legged it fails probably because the parameters or the signature is not computed has BitBucket expects.
Do you know if is there an official BitBucket PHP library so I can see exactly what they do with 2 legged requests?
![Picture of Martin Babinec Picture of Martin Babinec](/graphics/unknown.gif) Martin Babinec - 2015-04-13 18:04:58 - In reply to message 6 from Manuel Lemos
As far as I know there isn't any official Bitbucket oAuth library. There is only this official article
confluence.atlassian.com/display/BI ...
but there isn't anything about 2 legged really.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2015-04-14 03:29:12 - In reply to message 7 from Martin Babinec
Right, it would be useful to find some library that supports 2-Legged with BitBucket, even if it is not official, or in the worst case is not PHP. Just let me know if you find out anything.
![Picture of allenmao Picture of allenmao](/graphics/unknown.gif) allenmao - 2015-04-28 08:24:53 - In reply to message 5 from Martin Babinec
hi expert,
i have a similar case for LinedIn post a job 2 legged implementation,
can you provide me an example to 2 legged example without redirect, without user authorization involved. is it possible in oauth 2, if not , do you have an example for oauth v1a ?
it posts to https://api.linkedin.com/v1/jobs
it does't have a request, access, authorisation endpoint that's why i confused.
thanks
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2015-04-29 09:25:40 - In reply to message 7 from Martin Babinec
I just fixed something wrong in the class that makes it work if you do not call the Process function.
I still need to investigate why calling the Process function makes 2-legged requests not work, but if you only need to make 2-legged requests it should work for you.
|