Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12694 anikendra 1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
/**
3
 * GitHub OAuth2 Provider
4
 *
5
 * @package    CodeIgniter/OAuth2
6
 * @category   Provider
7
 * @author     Phil Sturgeon
8
 * @copyright  (c) 2012 HappyNinjas Ltd
9
 * @license    http://philsturgeon.co.uk/code/dbad-license
10
 */
11
 
12
class OAuth2_Provider_Github extends OAuth2_Provider
13
{
14
	public function url_authorize()
15
	{
16
		return 'https://github.com/login/oauth/authorize';
17
	}
18
 
19
	public function url_access_token()
20
	{
21
		return 'https://github.com/login/oauth/access_token';
22
	}
23
 
24
	public function get_user_info(OAuth2_Token_Access $token)
25
	{
26
		$url = 'https://api.github.com/user?'.http_build_query(array(
27
			'access_token' => $token->access_token,
28
		));
29
 
30
		$user = json_decode(file_get_contents($url));
31
 
32
		// Create a response from the request
33
		return array(
34
			'uid' => $user->id,
35
			'nickname' => $user->login,
36
			'name' => $user->name,
37
			'email' => $user->email,
38
			'urls' => array(
39
			  'GitHub' => 'http://github.com/'.$user->login,
40
			  'Blog' => $user->blog,
41
			),
42
		);
43
	}
44
}