I am trying to implement Github authentication in my application (built using Laravel 4) using php-github-api by KnpLabs. I went ahead and created an app in my Github account to obtain the client_id and the secret key.
The problem is, I cannot authenticate using this library. A null result is returned. It implementation seems simple but I cannot get it work. Checkout how I am implementing it.
try{
$client = new Github\Client();
$auth= $client->authenticate('myclientid','mysecret',AUTH_URL_CLIENT_ID);
$emails = $client->api('current_user')->emails()->all();
return Response::json(array("user"=>$emails));
}catch(Exception $e){
return Response::json(array('failed',$e->getMessage()));
}
This is the result I get from the above:
["failed","Requires authentication"]
Please someone help me figure out what I am doing wrong.
Thank you.
I believe
AUTH_URL_CLIENT_ID
should be
Github\Client::AUTH_URL_CLIENT_ID
Update, Github\Client::AUTH_URL_CLIENT_ID no longer used. Please see:
https://github.com/KnpLabs/php-github-api/blob/v3.3.0/doc/security.md
Supported methods are:
In this case $client->authenticate('myclientid','mysecret',AUTH_URL_CLIENT_ID) should be:
$client->authenticate('myclientid', 'mysecret', Github\Client::AUTH_CLIENT_ID)
If using auth token, we can ommit the mysecret/password part:
$client->authenticate('myauthtoken', Github\Client::AUTH_ACCESS_TOKEN);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With