src/login_github.php
public static function exchange_for_oauth_token($code) {
	$config = static::get_config();
	
	$url       = 'https://github.com/login/oauth/access_token';
	$options   = [
		'body' => [ // 'json' || 'body' || 'query'
			'client_id'     => $config['client_id'],
			'client_secret' => $config['client_secret'],
			'code'          => $code,
		],
		'headers' => [
			'Accept' => 'application/json',
		],
	];
	
	$http = new \GuzzleHttp\Client();
	$response = $http->post($url, $options)->json();
	
	if (empty($response['access_token'])) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('can not get oauth token for temporary code');
	}
	
	return [
		'oauth_token' => $response['access_token'],
		'scope'       => $response['scope'],
	];
}
public static function exchange_for_oauth_token($code) {
	$config = static::get_config();
	
	$url       = 'https://github.com/login/oauth/access_token';
	$options   = [
		'body' => [ // 'json' || 'body' || 'query'
			'client_id'     => $config['client_id'],
			'client_secret' => $config['client_secret'],
			'code'          => $code,
		],
		'headers' => [
			'Accept' => 'application/json',
		],
	];
	
	$http = new \GuzzleHttp\Client();
	$response = $http->post($url, $options)->json();
	
	if (empty($response['access_token'])) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('can not get oauth token for temporary code');
	}
	
	return [
		'oauth_token' => $response['access_token'],
		'scope'       => $response['scope'],
	];
}
public static function exchange_for_oauth_token ( $ code ) { $ config = static :: get_config ( ) ; $ url = 'https://github.com/login/oauth/access_token' ; $ options = [ 'body' => [ // 'json' || 'body' || 'query' 'client_id' => $ config [ 'client_id' ] , 'client_secret' => $ config [ 'client_secret' ] , 'code' => $ code , ] , 'headers' => [ 'Accept' => 'application/json' , ] , ] ; $ http = new \ GuzzleHttp \ Client ( ) ; $ response = $ http -> post ( $ url , $ options ) -> json ( ) ; if ( empty ( $ response [ 'access_token' ] ) ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'can not get oauth token for temporary code' ) ; } return [ 'oauth_token' => $ response [ 'access_token' ] , 'scope' => $ response [ 'scope' ] , ] ; }
exchange the temporary code for a lasting oauth token

@param  string    $code
@return string
@throws exception       if the exchange fails
exchange the temporary code for a lasting oauth token