PHPAuth
PHPAuth copied to clipboard
basic google authentication
added two functions:
getGoogleAuthURL()
Generates a URL which points to the google-login form provided by google. You can use it with HTML-link like
//get url
$result = $auth->getGoogleAuthURL();
//check if url-generating was okay
if($result['error'] == false){
echo "<a href='" . $result['auth_url']. "'>Login via Google</a>
}
authenticateViaGoogle()
Verifies the authentication-code that is bound to the redirect-url as a get parameter, that it is a successfull authentication. Checks via scope (at the moment fixed 'email') if the google-account is bound to a phpauth-users (both need to have the same e-mail-address). Adds a session + cookie and returns the result. Small example code of how to use:
if(isset($_GET['code'])){
$result = $auth->authenticateViaGoogle($_GET['code']);
if($result['error'] == false){
//locate to your application
header("Location: /");
}
}
TODO
check if google-parameter are present (not null)
PLEASE FEEL FREE TO COMMENT & IMPROVE THIS SOLUTION!
What problem does this code solve?
I think, this MUST NOT be inside PHPAuth CORE.
This branch isn't core.