Skip to content

Commit b8a093c

Browse files
committed
Merge pull request #36 from auth0/1.x.x-dev
Release 1.0.10
2 parents 723071a + 857e84e commit b8a093c

File tree

14 files changed

+362
-13
lines changed

14 files changed

+362
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.3.0",
13+
"php": ">=5.4.0",
1414
"guzzlehttp/guzzle": "~5.0",
1515
"ext-json": "*",
1616
"adoy/oauth2": "~1.3",

examples/basic-oauth/public/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $(document).ready(function() {
99
callbackURL: AUTH0_CALLBACK_URL
1010
, responseType: 'code'
1111
, authParams: {
12-
scope: 'openid profile'
12+
scope: 'openid'
1313
}
1414
});
1515

examples/basic-webapp/public/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $(document).ready(function() {
99
callbackURL: AUTH0_CALLBACK_URL
1010
, responseType: 'code'
1111
, authParams: {
12-
scope: 'openid profile'
12+
scope: 'openid'
1313
}
1414
});
1515

examples/link-users/composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "auth0/basic-webapp-sample",
3+
"description": "Basic sample for securing a WebApp with Auth0",
4+
"require": {
5+
"adoy/oauth2": "dev-master",
6+
"vlucas/phpdotenv": "1.1.1",
7+
"auth0/auth0-php": "~1.0"
8+
},
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"name": "Martin Gontovnikas",
13+
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Germán Lena",
17+
"email": "[email protected]"
18+
}
19+
]
20+
}

examples/link-users/config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
function getAuth0Config() {
4+
return [
5+
'domain' => 'wptest.auth0.com',
6+
'client_id' => 'KNuydwEqwGsPNpxdAhACmOWDUmBEZsLn',
7+
'client_secret' => 'cQT57M1wIYvcW1Rr6lTGWitqlkBtYwsyYkHG-mhVKdxhXBATWDwM6tB0mJFJVWFv',
8+
'redirect_uri' => 'http://localhost:3000/index.php',
9+
];
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
// Read .env
3+
try {
4+
Dotenv::load(__DIR__);
5+
} catch(InvalidArgumentException $ex) {
6+
// Ignore if no dotenv
7+
}
8+
9+
10+
11+
12+
13+
14+
15+

examples/link-users/helpers.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
4+
function dd() {
5+
echo "<pre>";
6+
foreach(func_get_args() as $param)
7+
var_dump($param);
8+
exit;
9+
}

examples/link-users/index.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
require_once 'vendor/autoload.php';
4+
require_once 'helpers.php';
5+
require_once 'dotenv-loader.php';
6+
7+
$auth0_config = array(
8+
'domain' => getenv('AUTH0_DOMAIN'),
9+
'client_id' => getenv('AUTH0_CLIENT_ID'),
10+
'client_secret' => getenv('AUTH0_CLIENT_SECRET'),
11+
'redirect_uri' => getenv('AUTH0_CALLBACK_URL'),
12+
'persist_id_token' => true,
13+
);
14+
15+
if (isset($_REQUEST['link'])) {
16+
$auth0_config['persist_user'] = false;
17+
$auth0_config['persist_id_token'] = false;
18+
$auth0_config['store'] = false;
19+
}
20+
21+
$auth0Oauth = new \Auth0\SDK\Auth0($auth0_config);
22+
23+
$userInfo = $auth0Oauth->getUser();
24+
25+
if (isset($_REQUEST['logout'])) {
26+
$auth0Oauth->logout();
27+
session_destroy();
28+
header("Location: /");
29+
}
30+
31+
if ($userInfo) {
32+
header("Location: /linkuser.php");
33+
exit;
34+
}
35+
36+
37+
require 'login.php';

examples/link-users/linkuser.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
require_once 'vendor/autoload.php';
3+
require_once 'helpers.php';
4+
require_once 'dotenv-loader.php';
5+
6+
use Auth0\SDK\Store\SessionStore;
7+
$store = new SessionStore();
8+
$main_user = $store->get('user');
9+
if (!$main_user) {
10+
header("Location: /linkuser.php");
11+
exit;
12+
}
13+
14+
$auth0_config = array(
15+
'domain' => getenv('AUTH0_DOMAIN'),
16+
'client_id' => getenv('AUTH0_CLIENT_ID'),
17+
'client_secret' => getenv('AUTH0_CLIENT_SECRET'),
18+
'redirect_uri' => getenv('AUTH0_CALLBACK_URL'),
19+
'persist_user' => false,
20+
'persist_id_token' => false,
21+
'store' => false,
22+
);
23+
24+
$auth0Oauth = new \Auth0\SDK\Auth0($auth0_config);
25+
26+
$secondary_user = $auth0Oauth->getUser();
27+
28+
if ($secondary_user) {
29+
30+
$app_token = getenv('AUTH0_APPTOKEN');
31+
$domain = getenv('AUTH0_DOMAIN');
32+
33+
echo '<pre>';
34+
35+
echo "Main user: " . $main_user["user_id"] . "\n";
36+
echo "Main user: " . $secondary_user["user_id"] . "\n";
37+
38+
var_dump(
39+
\Auth0\SDK\API\ApiUsers::linkAccount($domain, $app_token, $main_user["user_id"], array(
40+
"provider" => $secondary_user["identities"][0]["provider"],
41+
"user_id" => $secondary_user["identities"][0]["user_id"]
42+
) )
43+
);
44+
echo '</pre>';
45+
exit;
46+
}
47+
48+
49+
?>
50+
51+
<html>
52+
<head>
53+
<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
54+
<script src="https://cdn.auth0.com/js/lock-7.min.js"></script>
55+
56+
<script type="text/javascript" src="//use.typekit.net/iws6ohy.js"></script>
57+
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
58+
59+
<meta name="viewport" content="width=device-width, initial-scale=1">
60+
61+
<!-- font awesome from BootstrapCDN -->
62+
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
63+
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
64+
65+
<script>
66+
var AUTH0_CLIENT_ID = '<?php echo getenv("AUTH0_CLIENT_ID") ?>';
67+
var AUTH0_DOMAIN = '<?php echo getenv("AUTH0_DOMAIN") ?>';
68+
var AUTH0_LINKUSER_CALLBACK_URL = '<?php echo is_null(getenv("AUTH0_LINKUSER_CALLBACK_URL")) ?
69+
"http://localhost:3000/linkuser.php" : getenv("AUTH0_LINKUSER_CALLBACK_URL") ?>';
70+
</script>
71+
72+
73+
<script src="/public/app.js"> </script>
74+
<link href="/public/app.css" rel="stylesheet">
75+
76+
77+
78+
</head>
79+
<body class="home">
80+
<div class="container">
81+
<div class="login-page clearfix">
82+
83+
<div class="login-box auth0-box before">
84+
<img src="https://i.cloudup.com/StzWWrY34s.png" />
85+
<h3>Auth0 Example</h3>
86+
<p>Link user</p>
87+
<a class="btn btn-primary btn-lg btn-link btn-block">Link</a>
88+
</div>
89+
90+
</div>
91+
</div>
92+
</body>
93+
</html>

examples/link-users/login.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<html>
2+
<head>
3+
<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
4+
<script src="https://cdn.auth0.com/js/lock-7.min.js"></script>
5+
6+
<script type="text/javascript" src="//use.typekit.net/iws6ohy.js"></script>
7+
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
8+
9+
<meta name="viewport" content="width=device-width, initial-scale=1">
10+
11+
<!-- font awesome from BootstrapCDN -->
12+
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
13+
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
14+
15+
<script>
16+
var AUTH0_CLIENT_ID = '<?php echo getenv("AUTH0_CLIENT_ID") ?>';
17+
var AUTH0_DOMAIN = '<?php echo getenv("AUTH0_DOMAIN") ?>';
18+
var AUTH0_CALLBACK_URL = '<?php echo is_null(getenv("AUTH0_CALLBACK_URL")) ?
19+
"http://localhost:3000/index.php" : getenv("AUTH0_CALLBACK_URL") ?>';
20+
</script>
21+
22+
23+
<script src="/public/app.js"> </script>
24+
<link href="/public/app.css" rel="stylesheet">
25+
26+
27+
28+
</head>
29+
<body class="home">
30+
<div class="container">
31+
<div class="login-page clearfix">
32+
33+
<div class="login-box auth0-box before">
34+
<img src="https://i.cloudup.com/StzWWrY34s.png" />
35+
<h3>Auth0 Example</h3>
36+
<p>Zero friction identity infrastructure, built for developers</p>
37+
<a class="btn btn-primary btn-lg btn-login btn-block">SignIn</a>
38+
</div>
39+
40+
</div>
41+
</div>
42+
</body>
43+
</html>

0 commit comments

Comments
 (0)