From 44ee268297fd94b59a01490decbf14fa81725343 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 4 Aug 2015 14:41:37 +0300 Subject: [PATCH 1/5] Comment out code that rewrites user_id property in $body And actually it is useless code as i see. --- src/API/ApiUsers.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/API/ApiUsers.php b/src/API/ApiUsers.php index e8893a9d..7da9b8a0 100644 --- a/src/API/ApiUsers.php +++ b/src/API/ApiUsers.php @@ -142,12 +142,12 @@ public static function createEmailVerificationTicket($domain, $token, $user_id, ->withHeader(new AuthorizationBearer($token)) ->withBody(json_encode($body)); - if ($result_url) { - $body = json_encode(array( - 'result_url' => $result_url - )); - $request->withBody($body); - } + // if ($result_url) { + // $body = json_encode(array( + // 'result_url' => $result_url + // )); + // $request->withBody($body); + // } return $request->call(); From 08e3f5edaaa9cb059b1c263a8bf1b9233e6b221f Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 4 Aug 2015 15:14:24 +0300 Subject: [PATCH 2/5] Add application/json content-type --- src/API/ApiUsers.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/API/ApiUsers.php b/src/API/ApiUsers.php index 7da9b8a0..444c1ad2 100644 --- a/src/API/ApiUsers.php +++ b/src/API/ApiUsers.php @@ -139,6 +139,7 @@ public static function createEmailVerificationTicket($domain, $token, $user_id, $request = self::getApiV2Client($domain)->post() ->tickets() ->addPath('email-verification') + ->withHeader(new ContentType('application/json')) ->withHeader(new AuthorizationBearer($token)) ->withBody(json_encode($body)); From 78da395b53456b1a66ba8631897271d8d3cff4c5 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 4 Aug 2015 16:21:08 +0300 Subject: [PATCH 3/5] remove useless code --- src/API/ApiUsers.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/API/ApiUsers.php b/src/API/ApiUsers.php index 444c1ad2..f49fb6f2 100644 --- a/src/API/ApiUsers.php +++ b/src/API/ApiUsers.php @@ -143,13 +143,6 @@ public static function createEmailVerificationTicket($domain, $token, $user_id, ->withHeader(new AuthorizationBearer($token)) ->withBody(json_encode($body)); - // if ($result_url) { - // $body = json_encode(array( - // 'result_url' => $result_url - // )); - // $request->withBody($body); - // } - return $request->call(); } From 5f594470e8542f4fbdb6b8607e963a438bfacccb Mon Sep 17 00:00:00 2001 From: German Lena Date: Wed, 23 Sep 2015 10:37:58 -0300 Subject: [PATCH 4/5] Fix users unlink, removed profile scope in lock, issues #35, #34 --- composer.json | 2 +- examples/basic-oauth/public/app.js | 2 +- examples/basic-webapp/public/app.js | 2 +- src/API/ApiUsers.php | 6 +++--- src/Auth0.php | 3 +++ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 0cac4791..52c87fdf 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.3.0", + "php": ">=5.4.0", "guzzlehttp/guzzle": "~5.0", "ext-json": "*", "adoy/oauth2": "~1.3", diff --git a/examples/basic-oauth/public/app.js b/examples/basic-oauth/public/app.js index 66ca303e..7f2fd6d8 100644 --- a/examples/basic-oauth/public/app.js +++ b/examples/basic-oauth/public/app.js @@ -9,7 +9,7 @@ $(document).ready(function() { callbackURL: AUTH0_CALLBACK_URL , responseType: 'code' , authParams: { - scope: 'openid profile' + scope: 'openid' } }); diff --git a/examples/basic-webapp/public/app.js b/examples/basic-webapp/public/app.js index 66ca303e..7f2fd6d8 100644 --- a/examples/basic-webapp/public/app.js +++ b/examples/basic-webapp/public/app.js @@ -9,7 +9,7 @@ $(document).ready(function() { callbackURL: AUTH0_CALLBACK_URL , responseType: 'code' , authParams: { - scope: 'openid profile' + scope: 'openid' } }); diff --git a/src/API/ApiUsers.php b/src/API/ApiUsers.php index e8893a9d..63b791c3 100644 --- a/src/API/ApiUsers.php +++ b/src/API/ApiUsers.php @@ -103,12 +103,12 @@ public static function linkAccount($domain, $token, $user_id, $post_identities_b ->call(); } - public static function unlinkAccount($domain, $token, $user_id, $multifactor_provider, $identity) { + public static function unlinkAccount($domain, $token, $user_id, $provider, $identity_id) { return self::getApiV2Client($domain)->delete() ->users($user_id) - ->addPathVariable($identity) - ->identities($multifactor_provider) + ->identities($provider) + ->addPathVariable($identity_id) ->withHeader(new AuthorizationBearer($token)) ->call(); } diff --git a/src/Auth0.php b/src/Auth0.php index 1bc60fd1..8c502ff9 100644 --- a/src/Auth0.php +++ b/src/Auth0.php @@ -246,6 +246,9 @@ private function exchangeCode() { if (!$access_token) { throw new ApiException('Invalid access_token - Retry login.'); } + if (!$id_token) { + throw new ApiException('Missing JWT after code exchange. Remember to ask for openid scope.'); + } // Set the access token in the oauth client for future calls to the Auth0 API $this->oauth_client->setAccessToken($access_token); $this->oauth_client->setAccessTokenType(Client::ACCESS_TOKEN_BEARER); From 93a0a9f00f49126c5ac694a921e977361fe9d4b0 Mon Sep 17 00:00:00 2001 From: German Lena Date: Wed, 23 Sep 2015 11:25:58 -0300 Subject: [PATCH 5/5] add link users with validation example --- examples/link-users/composer.json | 20 ++++++ examples/link-users/config.php | 10 +++ examples/link-users/dotenv-loader.php | 15 +++++ examples/link-users/helpers.php | 9 +++ examples/link-users/index.php | 37 +++++++++++ examples/link-users/linkuser.php | 93 ++++++++++++++++++++++++++ examples/link-users/login.php | 43 ++++++++++++ examples/link-users/public/app.css | 95 +++++++++++++++++++++++++++ examples/link-users/public/app.js | 30 +++++++++ 9 files changed, 352 insertions(+) create mode 100644 examples/link-users/composer.json create mode 100644 examples/link-users/config.php create mode 100644 examples/link-users/dotenv-loader.php create mode 100644 examples/link-users/helpers.php create mode 100644 examples/link-users/index.php create mode 100644 examples/link-users/linkuser.php create mode 100644 examples/link-users/login.php create mode 100644 examples/link-users/public/app.css create mode 100644 examples/link-users/public/app.js diff --git a/examples/link-users/composer.json b/examples/link-users/composer.json new file mode 100644 index 00000000..e5a46898 --- /dev/null +++ b/examples/link-users/composer.json @@ -0,0 +1,20 @@ +{ + "name": "auth0/basic-webapp-sample", + "description": "Basic sample for securing a WebApp with Auth0", + "require": { + "adoy/oauth2": "dev-master", + "vlucas/phpdotenv": "1.1.1", + "auth0/auth0-php": "~1.0" + }, + "license": "MIT", + "authors": [ + { + "name": "Martin Gontovnikas", + "email": "martin@gon.to" + }, + { + "name": "Germán Lena", + "email": "german.lena@gmail.com" + } + ] +} diff --git a/examples/link-users/config.php b/examples/link-users/config.php new file mode 100644 index 00000000..be2021d1 --- /dev/null +++ b/examples/link-users/config.php @@ -0,0 +1,10 @@ + 'wptest.auth0.com', + 'client_id' => 'KNuydwEqwGsPNpxdAhACmOWDUmBEZsLn', + 'client_secret' => 'cQT57M1wIYvcW1Rr6lTGWitqlkBtYwsyYkHG-mhVKdxhXBATWDwM6tB0mJFJVWFv', + 'redirect_uri' => 'http://localhost:3000/index.php', + ]; +} \ No newline at end of file diff --git a/examples/link-users/dotenv-loader.php b/examples/link-users/dotenv-loader.php new file mode 100644 index 00000000..72b45129 --- /dev/null +++ b/examples/link-users/dotenv-loader.php @@ -0,0 +1,15 @@ +"; + foreach(func_get_args() as $param) + var_dump($param); + exit; +} \ No newline at end of file diff --git a/examples/link-users/index.php b/examples/link-users/index.php new file mode 100644 index 00000000..3da0d160 --- /dev/null +++ b/examples/link-users/index.php @@ -0,0 +1,37 @@ + getenv('AUTH0_DOMAIN'), + 'client_id' => getenv('AUTH0_CLIENT_ID'), + 'client_secret' => getenv('AUTH0_CLIENT_SECRET'), + 'redirect_uri' => getenv('AUTH0_CALLBACK_URL'), + 'persist_id_token' => true, +); + +if (isset($_REQUEST['link'])) { + $auth0_config['persist_user'] = false; + $auth0_config['persist_id_token'] = false; + $auth0_config['store'] = false; +} + +$auth0Oauth = new \Auth0\SDK\Auth0($auth0_config); + +$userInfo = $auth0Oauth->getUser(); + +if (isset($_REQUEST['logout'])) { + $auth0Oauth->logout(); + session_destroy(); + header("Location: /"); +} + +if ($userInfo) { + header("Location: /linkuser.php"); + exit; +} + + +require 'login.php'; diff --git a/examples/link-users/linkuser.php b/examples/link-users/linkuser.php new file mode 100644 index 00000000..01bdbc99 --- /dev/null +++ b/examples/link-users/linkuser.php @@ -0,0 +1,93 @@ +get('user'); +if (!$main_user) { + header("Location: /linkuser.php"); + exit; +} + +$auth0_config = array( + 'domain' => getenv('AUTH0_DOMAIN'), + 'client_id' => getenv('AUTH0_CLIENT_ID'), + 'client_secret' => getenv('AUTH0_CLIENT_SECRET'), + 'redirect_uri' => getenv('AUTH0_CALLBACK_URL'), + 'persist_user' => false, + 'persist_id_token' => false, + 'store' => false, +); + +$auth0Oauth = new \Auth0\SDK\Auth0($auth0_config); + +$secondary_user = $auth0Oauth->getUser(); + +if ($secondary_user) { + + $app_token = getenv('AUTH0_APPTOKEN'); + $domain = getenv('AUTH0_DOMAIN'); + + echo '
';
+
+  echo "Main user: " . $main_user["user_id"] . "\n";
+  echo "Main user: " . $secondary_user["user_id"] . "\n";
+
+  var_dump(
+    \Auth0\SDK\API\ApiUsers::linkAccount($domain, $app_token, $main_user["user_id"], array(
+      "provider" => $secondary_user["identities"][0]["provider"],
+      "user_id" => $secondary_user["identities"][0]["user_id"]
+    ) )
+  );
+  echo '
'; + exit; +} + + +?> + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + diff --git a/examples/link-users/login.php b/examples/link-users/login.php new file mode 100644 index 00000000..cfac5b5a --- /dev/null +++ b/examples/link-users/login.php @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + diff --git a/examples/link-users/public/app.css b/examples/link-users/public/app.css new file mode 100644 index 00000000..3a965f1b --- /dev/null +++ b/examples/link-users/public/app.css @@ -0,0 +1,95 @@ + body { + font-family: "proxima-nova", sans-serif; + text-align: center; + font-size: 300%; + font-weight: 100; +} +input[type=checkbox], +input[type=radio] { + position: absolute; + opacity: 0; +} +input[type=checkbox] + label, +input[type=radio] + label { + display: inline-block; +} +input[type=checkbox] + label:before, +input[type=radio] + label:before { + content: ""; + display: inline-block; + vertical-align: -0.2em; + width: 1em; + height: 1em; + border: 0.15em solid #0074d9; + border-radius: 0.2em; + margin-right: 0.3em; + background-color: white; +} +input[type=radio] + label:before { + border-radius: 50%; +} +input[type=radio]:checked + label:before, +input[type=checkbox]:checked + label:before { + background-color: #0074d9; + box-shadow: inset 0 0 0 0.15em white; +} +input[type=radio]:focus + label:before, +input[type=checkbox]:focus + label:before { + outline: 0; +} +.btn { + font-size: 140%; + text-transform: uppercase; + letter-spacing: 1px; + border: 0; + background-color: #16214D; + color: white; +} +.btn:hover { + background-color: #44C7F4; +} +.btn:focus { + outline: none !important; +} +.btn.btn-lg { + padding: 20px 30px; +} +.btn:disabled { + background-color: #333; + color: #666; +} +h1, +h2, +h3 { + font-weight: 100; +} +#logo img { + width: 300px; + margin-bottom: 60px; +} +.home-description { + font-weight: 100; + margin: 100px 0; +} +h2 { + margin-top: 30px; + margin-bottom: 40px; + font-size: 200%; +} +label { + font-size: 100%; + font-weight: 300; +} +.btn-next { + margin-top: 30px; +} +.answer { + width: 70%; + margin: auto; + text-align: left; + padding-left: 10%; + margin-bottom: 20px; +} +.login-page .login-box { + padding: 100px 0; +} diff --git a/examples/link-users/public/app.js b/examples/link-users/public/app.js new file mode 100644 index 00000000..4e61b9d0 --- /dev/null +++ b/examples/link-users/public/app.js @@ -0,0 +1,30 @@ +$(document).ready(function() { + + var lock = new Auth0Lock(AUTH0_CLIENT_ID, AUTH0_DOMAIN); + + $('.btn-login').click(function(e) { + e.preventDefault(); + + lock.show({ + callbackURL: AUTH0_CALLBACK_URL + , responseType: 'code' + , authParams: { + scope: 'openid' + } + }); + + }); + + $('.btn-link').click(function(e) { + e.preventDefault(); + + lock.show({ + callbackURL: AUTH0_LINKUSER_CALLBACK_URL + , responseType: 'code' + , authParams: { + scope: 'openid' + } + }); + + }); +});