Created
August 3, 2020 13:52
-
-
Save bootleg224/2e67473dabc17367867a861965566f2c to your computer and use it in GitHub Desktop.
PHP SSO Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Step 1 Create a template to begin the handshake process "OpenWaterBegin" | |
$userIsLoggedIn = false; //set using buddy press | |
$_SESSION["_openwater_auth"] = $_GET["returnUrl"]; //get the return url from the query string and save it to the session | |
if($userIsLoggedIn) { | |
header("Location: /openwater/process"); //forward to process page | |
die(); | |
} else { | |
header("Location: /LoginOrCreateAccount"); //forward to page to create an account | |
die(); | |
} | |
//step 2 Create a template to end the handshake process "OpenWaterProcess" | |
include_once "Authentication/JWT.php"; //https://github.com/firebase/php-jwt | |
$key = "openwater-handshake-1241"; //shared secret you set in the portal | |
$now = gmdate("Y-m-d H:i:s"); | |
$returnUrl = $_SESSION["_openwater_auth"]; // as saved in step 1 | |
if($returlUrl == '' || $returnUrl == NULL) | |
$returnUrl = 'https://OPENWATERDOMAINNAME/a/account/validatethirdpartycorporateauthresult?redirectUrl=http%3A%2F%2FOPENWATERDOMAINNAME%2Fa';//default return url, replace after we go live | |
//Get variables from contact database | |
$firstName = "FirstName"; //take from buddy press | |
$lastName = "LastName"; //take from buddy press | |
$email = "valid@email.com"; //Must be a valid email format | |
$validatedAsMember = false; //For example if you have member / nonmember pricing you may want to set this flag | |
$additionalData = ""; //Optional you can use this if you need to set pricing based on some other criteria like a member role | |
$token = array( | |
"TimeStampUtc" => $now, | |
"Email" => $email, | |
"FirstName" => $firstName, | |
"LastName" => $lastName, | |
"UserNameExists" => true, | |
"UserIsMember" => $validatedAsMember, | |
"UserData" => additionalData | |
); | |
$jwt = JWT::encode($token, $key); | |
$location = $returnUrl."&token=".$jwt; | |
// Redirect | |
header("Location: " . $location); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment