Skip to content

Commit

Permalink
connect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adi Chikara authored and Adi Chikara committed Apr 6, 2015
1 parent bf5c7dc commit 9a3d2f2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Crypt/
Math/
44 changes: 39 additions & 5 deletions OpenIDConnectClient.php5
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ class OpenIDConnectClient
*/
private $accessToken;

/**
* @var string to store id token
*/
private $id_token;

/**
* @var string to store claims
*/
private $claims;

/**
* @var array holds scopes
*/
Expand Down Expand Up @@ -214,6 +224,10 @@ class OpenIDConnectClient
// Save the access token
$this->accessToken = $token_json->access_token;

$this->id_token = $token_json->id_token;

$this->claims = $claims;

// Success!
return true;

Expand Down Expand Up @@ -243,6 +257,23 @@ class OpenIDConnectClient
$this->authParams = array_merge($this->authParams, (array)$param);
}

/**
* Check if user is already authenticated or not
*/
public function isAuthenticated() {
$currentTime = time();
if( isset($this->id_token) && ($currentTime < $this->claims->exp) ) {
return true;
} else {
return false;
}
}

public function getClaims() {
$dummy = $this->claims->exp;
return $dummy;
}

/**
* Get's anything that we need configuration wise including endpoints, and other values
*
Expand All @@ -269,8 +300,8 @@ class OpenIDConnectClient

return $this->providerConfig[$param];
}


/**
* @param $url Sets redirect URL for auth flow
*/
Expand All @@ -286,7 +317,7 @@ class OpenIDConnectClient
* @return string
*/
public function getRedirectURL() {

// If the redirect URL has been set then return it.
if (property_exists($this, 'redirectURL') && $this->redirectURL) {
return $this->redirectURL;
Expand Down Expand Up @@ -464,11 +495,14 @@ class OpenIDConnectClient
* @return bool
*/
private function verifyJWTclaims($claims) {

if(isset($claims->nonce)) {
return (($claims->iss == $this->getProviderURL())
&& (($claims->aud == $this->clientID) || (in_array($this->clientID, $claims->aud)))
&& ($claims->nonce == $_SESSION['openid_connect_nonce']));

} else {
return (($claims->iss == $this->getProviderURL())
&& (($claims->aud == $this->clientID) || (in_array($this->clientID, $claims->aud))));
}
}

/**
Expand Down
Empty file modified README.md
100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

require "OpenIDConnectClient.php5";

$oidc = new OpenIDConnectClient('http://localhost:3000',
'753ab695-395e-46ad-b57a-ec59095b5941',
'0dde479b01b85caa77ba');

$oidc->setRedirectURL('http://openid.local/');
$oidc->addScope(['openid','profile']);

?>
10 changes: 4 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php

require "OpenIDConnectClient.php5";
require "connect.php";

$oidc = new OpenIDConnectClient('http://openid.local/',
'ClientIDHere',
'ClientSecretHere');
if(!$oidc->isAuthenticated()) {
$oidc->authenticate();
}

$oidc->authenticate();
$name = $oidc->requestUserInfo('given_name');

?>

<html>
Expand Down

0 comments on commit 9a3d2f2

Please sign in to comment.