PHPAuth icon indicating copy to clipboard operation
PHPAuth copied to clipboard

basic google authentication

Open louis123562 opened this issue 4 years ago • 2 comments

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!

louis123562 avatar Oct 31 '20 12:10 louis123562

What problem does this code solve?

I think, this MUST NOT be inside PHPAuth CORE.

KarelWintersky avatar Oct 31 '20 22:10 KarelWintersky

This branch isn't core.

Conver avatar Oct 31 '20 22:10 Conver