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

+1-1
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

+1-1
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

+1-1
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

+20
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

+10
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+
}

examples/link-users/dotenv-loader.php

+15
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

+9
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

+37
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

+93
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

+43
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>

examples/link-users/public/app.css

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
body {
2+
font-family: "proxima-nova", sans-serif;
3+
text-align: center;
4+
font-size: 300%;
5+
font-weight: 100;
6+
}
7+
input[type=checkbox],
8+
input[type=radio] {
9+
position: absolute;
10+
opacity: 0;
11+
}
12+
input[type=checkbox] + label,
13+
input[type=radio] + label {
14+
display: inline-block;
15+
}
16+
input[type=checkbox] + label:before,
17+
input[type=radio] + label:before {
18+
content: "";
19+
display: inline-block;
20+
vertical-align: -0.2em;
21+
width: 1em;
22+
height: 1em;
23+
border: 0.15em solid #0074d9;
24+
border-radius: 0.2em;
25+
margin-right: 0.3em;
26+
background-color: white;
27+
}
28+
input[type=radio] + label:before {
29+
border-radius: 50%;
30+
}
31+
input[type=radio]:checked + label:before,
32+
input[type=checkbox]:checked + label:before {
33+
background-color: #0074d9;
34+
box-shadow: inset 0 0 0 0.15em white;
35+
}
36+
input[type=radio]:focus + label:before,
37+
input[type=checkbox]:focus + label:before {
38+
outline: 0;
39+
}
40+
.btn {
41+
font-size: 140%;
42+
text-transform: uppercase;
43+
letter-spacing: 1px;
44+
border: 0;
45+
background-color: #16214D;
46+
color: white;
47+
}
48+
.btn:hover {
49+
background-color: #44C7F4;
50+
}
51+
.btn:focus {
52+
outline: none !important;
53+
}
54+
.btn.btn-lg {
55+
padding: 20px 30px;
56+
}
57+
.btn:disabled {
58+
background-color: #333;
59+
color: #666;
60+
}
61+
h1,
62+
h2,
63+
h3 {
64+
font-weight: 100;
65+
}
66+
#logo img {
67+
width: 300px;
68+
margin-bottom: 60px;
69+
}
70+
.home-description {
71+
font-weight: 100;
72+
margin: 100px 0;
73+
}
74+
h2 {
75+
margin-top: 30px;
76+
margin-bottom: 40px;
77+
font-size: 200%;
78+
}
79+
label {
80+
font-size: 100%;
81+
font-weight: 300;
82+
}
83+
.btn-next {
84+
margin-top: 30px;
85+
}
86+
.answer {
87+
width: 70%;
88+
margin: auto;
89+
text-align: left;
90+
padding-left: 10%;
91+
margin-bottom: 20px;
92+
}
93+
.login-page .login-box {
94+
padding: 100px 0;
95+
}

examples/link-users/public/app.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$(document).ready(function() {
2+
3+
var lock = new Auth0Lock(AUTH0_CLIENT_ID, AUTH0_DOMAIN);
4+
5+
$('.btn-login').click(function(e) {
6+
e.preventDefault();
7+
8+
lock.show({
9+
callbackURL: AUTH0_CALLBACK_URL
10+
, responseType: 'code'
11+
, authParams: {
12+
scope: 'openid'
13+
}
14+
});
15+
16+
});
17+
18+
$('.btn-link').click(function(e) {
19+
e.preventDefault();
20+
21+
lock.show({
22+
callbackURL: AUTH0_LINKUSER_CALLBACK_URL
23+
, responseType: 'code'
24+
, authParams: {
25+
scope: 'openid'
26+
}
27+
});
28+
29+
});
30+
});

0 commit comments

Comments
 (0)