src/login_github.php
public static function request_authorization($scope=null, $callback_url=null) {
	$config = static::get_config();
	
	if (!empty($callback_url) && strpos($callback_url, $config['callback_url']) !== 0) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('custom callback url needs to start with defined callback url');
	}
	if (empty($callback_url)) {
		$callback_url = $config['callback_url'];
	}
	
	$text    = bootstrap::get_library('text');
	$session = bootstrap::get_library('session');
	$request = bootstrap::get_library('request');
	
	// state is a shared secret to prevent people faking the callback
	$state = $text::generate_token($length=40);
	
	$session::start(session::TYPE_TEMPORARY);
	$_SESSION['fem/login_github/state'] = $state;
	$_SESSION['fem/login_github/scope'] = $scope;
	
	// let the user authorize at github
	$url       = 'https://github.com/login/oauth/authorize';
	$arguments = [
		'client_id' => $config['client_id'],
		'scope'     => $scope,
		'state'     => $state,
	];
	$request::redirect($url.'?'.http_build_query($arguments));
}
public static function request_authorization($scope=null, $callback_url=null) {
	$config = static::get_config();
	
	if (!empty($callback_url) && strpos($callback_url, $config['callback_url']) !== 0) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('custom callback url needs to start with defined callback url');
	}
	if (empty($callback_url)) {
		$callback_url = $config['callback_url'];
	}
	
	$text    = bootstrap::get_library('text');
	$session = bootstrap::get_library('session');
	$request = bootstrap::get_library('request');
	
	// state is a shared secret to prevent people faking the callback
	$state = $text::generate_token($length=40);
	
	$session::start(session::TYPE_TEMPORARY);
	$_SESSION['fem/login_github/state'] = $state;
	$_SESSION['fem/login_github/scope'] = $scope;
	
	// let the user authorize at github
	$url       = 'https://github.com/login/oauth/authorize';
	$arguments = [
		'client_id' => $config['client_id'],
		'scope'     => $scope,
		'state'     => $state,
	];
	$request::redirect($url.'?'.http_build_query($arguments));
}
public static function request_authorization ( $ scope = null , $ callback_url = null ) { $ config = static :: get_config ( ) ; if ( ! empty ( $ callback_url ) && strpos ( $ callback_url , $ config [ 'callback_url' ] ) !== 0 ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'custom callback url needs to start with defined callback url' ) ; } if ( empty ( $ callback_url ) ) { $ callback_url = $ config [ 'callback_url' ] ; } $ text = bootstrap :: get_library ( 'text' ) ; $ session = bootstrap :: get_library ( 'session' ) ; $ request = bootstrap :: get_library ( 'request' ) ; // state is a shared secret to prevent people faking the callback $ state = $ text :: generate_token ( $ length = 40 ) ; $ session :: start ( session :: TYPE_TEMPORARY ) ; $ _SESSION [ 'fem/login_github/state' ] = $ state ; $ _SESSION [ 'fem/login_github/scope' ] = $ scope ; // let the user authorize at github $ url = 'https://github.com/login/oauth/authorize' ; $ arguments = [ 'client_id' => $ config [ 'client_id' ] , 'scope' => $ scope , 'state' => $ state , ] ; $ request :: redirect ( $ url . '?' . http_build_query ( $ arguments ) ) ; }
send a user to github to authorize our application

@param  string $scope        defaults to the scope of the previous authorization
or no scopes at all if authorization is never done yet
see https://developer.github.com/v3/oauth/#parameters
@param  string $callback_url defaults to what is set in the config
@return void                 even more so, the user is gone
send a user to github to authorize our application