Created
January 20, 2017 22:28
-
-
Save cmacrander/e11562c4de18307f957754d815d73006 to your computer and use it in GitHub Desktop.
Neptune Custom Portal (ISR) 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
<?php | |
# Custom Portal Code Sample | |
# ---------------------------------------------------------------------------- | |
# | |
# The purpose of this script is to demonstrate how institutions should | |
# handle a PERTS program participant and correctly return them to PERTS. | |
# | |
# The most up-to-date version of this script and other accompanying | |
# documentation is available at: | |
# | |
# https://neptune.perts.net/static/custom_portal_technical_guide.pdf | |
# | |
# If your institution can run php scripts, you can adapt this sample by | |
# completing the function `get_network_id()` below. Otherwise this | |
# should provide a description of the logic necessary for implementation in | |
# another language. | |
# | |
# If you choose, you may append query parameters to the final URL. These will | |
# be recorded by PERTS and associated with the user's token. | |
# | |
# Inputs | |
# ------ | |
# | |
# $code string Provided in the query string of the request, set as | |
# '__missing_code__' if not present, which also logs | |
# an error. | |
# $session string Provided in the query string of the request | |
# '__missing_session__' if not present, which also logs | |
# an error. | |
# $token string Drawn from institution's sign in system. | |
# | |
# Outputs | |
# ------ | |
# | |
# None. Rather script redirects to a PERTS-controlled URL containing the | |
# three inputs. | |
# ---------------------------------------------------------------------------- | |
# Capture the PERTS-supplied query string parameters `code` and `session`. | |
function get_param($key) { | |
if (isset($_REQUEST[$key]) && $_REQUEST[$key]) { | |
$value = $_REQUEST[$key]; | |
} else { | |
error_log("Incoming URL missing '".$key."' parameter in query string."); | |
# This value will signal PERTS to attempt to handle the error. | |
$value = '__missing_'.$key.'__'; | |
} | |
return $value; | |
} | |
$code = get_param('code'); | |
$session = get_param('session'); | |
/** | |
* Retrieve student's institutional network id. | |
* Exact implementation depends on institution's network. | |
* YOU MUST ADAPT THIS FUNCTION FOR YOUR ENVIRONMENT. | |
* | |
* @return string The user's id on this organization's network. | |
*/ | |
function get_network_id() { | |
return $_SERVER['WEBAUTH_USER']; // example only! | |
} | |
$token = get_network_id(); | |
# Make sure the network id / token has been set and is well formed. | |
if (!isset($token) || !is_string($token) || $token == '') { | |
throw new Exception("Network id invalid."); | |
} | |
# Build the destination URL. | |
$base_url = 'https://neptune.perts.net/participate/portal'; | |
$redirect_url = implode('/', array($base_url, $code, $session, $token)); | |
# Add arbitrary query parameters (optional) | |
$query_params = array(); // define as an associate array to add params | |
if (count($query_params) > 0) { | |
$redirect_url .= '?'.http_build_query($query_params); | |
} | |
# Redirect the user to PERTS with the network id. | |
header('Location: '.$redirect_url); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment