Skip to content

Commit 2562a36

Browse files
committed
Initial commit
0 parents  commit 2562a36

9 files changed

+2020
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Mewp <mewp151 at gmail dot com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# LightOpenId
2+
3+
This is a modified version of [LightOpenId by mewp on Gitorious](https://gitorious.org/lightopenid). It allows client to force a specific OpenId endpoint URL. This is useful for organization applications wishing to authenticate with Google Apps Federated Login. You can specify the Google Apps Federated Login endpoint url directly with:
4+
5+
$openid = new LightOpenId('localhost'); // replace with your host
6+
$openid->server = 'https://www.google.com/a/YOURDOMAIN.com/o8/ud?be=o8';
7+
8+
For more usage examples, see `example.php` and `example-google.php`.

composer.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "phpmycoder/lightopenid",
3+
"type": "library",
4+
"keywords": ["openid"],
5+
"homepage": "https://github.com/phpmycoder/lightopenid/",
6+
"license": "MIT",
7+
"version": "0.7.0",
8+
"require": {
9+
"php": ">=5.2.3"
10+
},
11+
"autoload": {
12+
"classmap": ["./"]
13+
}
14+
}

example-google.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
3+
require 'openid.php';
4+
try {
5+
# Change 'localhost' to your domain name.
6+
$openid = new LightOpenID('localhost');
7+
if(!$openid->mode) {
8+
if(isset($_GET['login'])) {
9+
$openid->identity = 'https://www.google.com/accounts/o8/id';
10+
header('Location: ' . $openid->authUrl());
11+
}
12+
?>
13+
<form action="?login" method="post">
14+
<button>Login with Google</button>
15+
</form>
16+
<?php
17+
} elseif($openid->mode == 'cancel') {
18+
echo 'User has canceled authentication!';
19+
} else {
20+
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
21+
}
22+
} catch(ErrorException $e) {
23+
echo $e->getMessage();
24+
}

example.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require 'openid.php';
3+
try {
4+
# Change 'localhost' to your domain name.
5+
$openid = new LightOpenID('localhost');
6+
if(!$openid->mode) {
7+
if(isset($_POST['openid_identifier'])) {
8+
$openid->identity = $_POST['openid_identifier'];
9+
# The following two lines request email, full name, and a nickname
10+
# from the provider. Remove them if you don't need that data.
11+
$openid->required = array('contact/email');
12+
$openid->optional = array('namePerson', 'namePerson/friendly');
13+
header('Location: ' . $openid->authUrl());
14+
}
15+
?>
16+
<form action="" method="post">
17+
OpenID: <input type="text" name="openid_identifier" /> <button>Submit</button>
18+
</form>
19+
<?php
20+
} elseif($openid->mode == 'cancel') {
21+
echo 'User has canceled authentication!';
22+
} else {
23+
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
24+
print_r($openid->getAttributes());
25+
}
26+
} catch(ErrorException $e) {
27+
echo $e->getMessage();
28+
}

0 commit comments

Comments
 (0)