Skip to content

Instantly share code, notes, and snippets.

@IntuitDeveloperRelations
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IntuitDeveloperRelations/69699c7577cf675b251e to your computer and use it in GitHub Desktop.
Save IntuitDeveloperRelations/69699c7577cf675b251e to your computer and use it in GitHub Desktop.
IPP PHP OpenID Login
<?php
# The MIT License (MIT)
#
# Copyright (c) 2014 Intuit Partner Platform
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>IPP PHP OpenID sample</title>
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
</head>
<body>
<div>IPP PHP OpenID Sample</div><br />
<?php
# This sample uses the LightOpenID library located here: https://gitorious.org/lightopenid
require 'lightopenid-lightopenid/openid.php';
try {
# Change 'localhost' to your domain name.
$openid = new LightOpenID('localhost');
if(!$openid->mode) {
# The connectWithIntuitOpenId parameter is passed when the user clicks the login button below
# The subscribeFromAppsDotCom parameter is an argument in the OpenID URL of a sample app on developer.intuit.com
# Example of OpenID URL: http://localhost/ippPhpOpenId/IPP-PHP-OpenID-Login.php?subscribeFromAppsDotCom
if(isset($_GET['connectWithIntuitOpenId']) || isset($_GET['subscribeFromAppsDotCom'])) {
$openid->identity = "https://openid.intuit.com/Identity-me";
# The following two lines request email and full name
# from the Intuit OpenID provider
$openid->required = array('contact/email');
$openid->optional = array('namePerson', 'namePerson/friendly');
header('Location: ' . $openid->authUrl());
}else{
# Show the login button. The user is not in the process of loggin in
echo '<div><ipp:login href="IPP-PHP-OpenID-Login.php?connectWithIntuitOpenId" type="vertical"></div>';
}
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.<br />';
# Print the OpenID attributes that we requested above, email and full name
print_r($openid->getAttributes());
# Add a link to allow the user to logout. The link makes a JavaScript call to intuit.ipp.anywhere.logout()
echo '<br /><a href="javascript:void(0)" onclick="return intuit.ipp.anywhere.logout(function () { window.location.href = \'http://localhost/ippPhpOpenId/IPP-PHP-OpenID-Login.php\'; });">Sign Out</a>';
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment