forked from jakub/paypal-access-demo
/
rp.php
executable file
·88 lines (63 loc) · 3.34 KB
/
rp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/*
Janrain AX example
modified from http://stackoverflow.com/questions/1183788/example-usage-of-ax-in-php-openid
originally by http://stackoverflow.com/users/52888/glen
*/
$oid_identifier = 'https://www.paypal.com/webapps/auth/server';
require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/Store/FileStore.php";
require_once "Auth/OpenID/Extension/AX.php";
require_once "Auth/OpenID/Extension/PAPE.php";
session_start();
// Create file storage area for OpenID data
// The Janrain library also supports databases, memcache, etc.
$store = new Auth_OpenID_Store_FileStore('./tmp');
$consumer = new Auth_OpenID_Consumer($store);
$auth = $consumer->begin($oid_identifier);
// add PAPE extensions
// request everything, see what we get back
$pape_policy_uris = array (
PAPE_AUTH_PHISHING_RESISTANT,
PAPE_AUTH_MULTI_FACTOR,
PAPE_AUTH_MULTI_FACTOR_PHYSICAL,
);
$max_auth_age = 7200; // 2 hours
$pape_request = new Auth_OpenID_PAPE_Request($policy_uris, $max_auth_age);
if ($pape_request) {
$auth->addExtension($pape_request);
}
// Required AX attributes to request
// PayPal will not return attributes marked as optional
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/namePerson/first', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/namePerson/last', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://schema.openid.net/contact/fullname', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/contact/email', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/contact/phone/default', 1, 1);
// default billing address
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://schema.openid.net/contact/street1', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://schema.openid.net/contact/street2', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/contact/city/home', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/contact/state/home', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/contact/postalCode/home', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/contact/country/home', 1, 1);
// e.g. en_GB
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/pref/language', 1, 1);
// e.g. Europe/London
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('http://axschema.org/pref/timezone', 1, 1);
// PayPal specific attributes
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('https://www.paypal.com/webapps/auth/schema/verifiedAccount', 1, 1);
$attribute[] = Auth_OpenID_Extension_AX_AttrInfo::make('https://www.paypal.com/webapps/auth/schema/payerID', 1, 1);
$ax = new Auth_OpenID_Extension_AX_FetchRequest;
foreach($attribute as $attr){
$ax->add($attr);
}
$auth->addExtension($ax);
$scriptPath = implode("/", (explode('/', $_SERVER["REQUEST_URI"], -1)));
if (isset($_GET['popup'])) {
$returnScript = $scriptPath . '/verify.php?popup=true';
} else {
$returnScript = $scriptPath . '/verify.php';
}
$url = $auth->redirectURL('https://' . $_SERVER["SERVER_NAME"], 'https://' . $_SERVER["SERVER_NAME"] . $returnScript);
header('Location: ' . $url);