src/login_github.php
public static function is_valid($callback_data, $extended=true) {
	$exception = bootstrap::get_library('exception');
	
	if (empty($callback_data['state'])) {
		throw new $exception('state expected in oauth callback');
	}
	
	$session = bootstrap::get_library('session');
	$session::start($session::TYPE_TEMPORARY);
	if ($callback_data['state'] != $_SESSION['fem/login_github/state']) {
		throw new $exception('state is different, someone tries to fake the callback?');
	}
	
	if (empty($callback_data['code'])) {
		return false;
	}
	
	if ($extended) {
		return static::is_valid_extended($callback_data);
	}
	return true;
}
public static function is_valid($callback_data, $extended=true) {
	$exception = bootstrap::get_library('exception');
	
	if (empty($callback_data['state'])) {
		throw new $exception('state expected in oauth callback');
	}
	
	$session = bootstrap::get_library('session');
	$session::start($session::TYPE_TEMPORARY);
	if ($callback_data['state'] != $_SESSION['fem/login_github/state']) {
		throw new $exception('state is different, someone tries to fake the callback?');
	}
	
	if (empty($callback_data['code'])) {
		return false;
	}
	
	if ($extended) {
		return static::is_valid_extended($callback_data);
	}
	return true;
}
public static function is_valid ( $ callback_data , $ extended = true ) { $ exception = bootstrap :: get_library ( 'exception' ) ; if ( empty ( $ callback_data [ 'state' ] ) ) { throw new $ exception ( 'state expected in oauth callback' ) ; } $ session = bootstrap :: get_library ( 'session' ) ; $ session :: start ( $ session :: TYPE_TEMPORARY ) ; if ( $ callback_data [ 'state' ] != $ _SESSION [ 'fem/login_github/state' ] ) { throw new $ exception ( 'state is different, someone tries to fake the callback?' ) ; } if ( empty ( $ callback_data [ 'code' ] ) ) { return false ; } if ( $ extended ) { return static :: is_valid_extended ( $ callback_data ) ; } return true ; }
checks whether an oauth callback contains a valid state and code

magic alert: this also does a lot more validation and info gathering
to do manually, set $extended to false and call ::is_valid_extended() or ..
.. call ::exchange_for_oauth_token(), ::verify_scope(), ::get_user_info() and ::verify_user()

can return an info array containing 'oauth_token', 'github_username', etc.
@see ::is_valid_extended()

@param  array         $callback_data as received from github, containing 'state', 'code' and 'scope'
@param  boolean       $extended      defaults to true
@return boolean|array                returns array on successful validation and $extended set to true
checks whether an oauth callback contains a valid state and code