philsturgeon / codeigniter-oauth2

NO LONGER ACTIVELY MAINTAINED. USE https://github.com/thephpleague/oauth2-client INSTEAD
http://getsparks.org/packages/oauth2/versions/HEAD/show
351 stars 178 forks source link

Github Provider : file_get_content issue #57

Closed radaniba closed 10 years ago

radaniba commented 10 years ago

I am trying to use oauth2 with Github api but I am keeping having this message

Message: file_get_contents(https://api.github.com/user?access_token=sometokenhiddenhere): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

Filename: Provider/Github.php

Line Number: 32 

Any idea on how to solve that problem ? I tried cURL to but it is giving an empty array. That said when I copy paste the url on the browser I get all the information

Cheers

jakelehner commented 10 years ago

What's on line 32?

radaniba commented 10 years ago

It is the file_get_content function, and I actually solved it by adding this to the Github provider code

$options  = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT']));
$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);

by adding a user agent to the options, file_get_content is now working, same thing if it was with cURL method.

adampatterson commented 10 years ago

Thanks :)

Adding the user agent fixed an issue that I was having on an unrelated project.