예제 #1
7
<?php

require_once 'vendor/autoload.php';
require_once 'helpers.php';
require_once 'dotenv-loader.php';
use Auth0\SDK\Store\SessionStore;
$store = new SessionStore();
$main_user = $store->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 '<pre>';
    echo "Main user: "******"user_id"] . "\n";
    echo "Secondary user: "******"user_id"] . "\n";
    $auth0Api = new \Auth0\SDK\Auth0Api($app_token, $domain);
    $response = $auth0Api->users->linkAccount($main_user["user_id"], array("provider" => $secondary_user["identities"][0]["provider"], "user_id" => $secondary_user["identities"][0]["user_id"]));
    var_dump($response);
    echo '</pre>';
    exit;
}
?>

<html>
    <head>
예제 #2
0
 /**
  * When authenticating, user visits remote service and then is redirected back to
  * /ccm/system/authentication/oauth2/auth0/callback?code=xxxxxx
  * which triggers this function.
  * 
  * Here we need to validate the ?code=xxx using a server-side PHP call and log the user in
  * if everything validates OK.
  * 
  * @return null
  */
 public function handle_authentication_callback()
 {
     try {
         // Setup the Auth0 API object with settings stored in the CMS
         $auth0 = new \Auth0\SDK\Auth0(array('domain' => \Config::get('auth.auth0.domain'), 'client_id' => \Config::get('auth.auth0.client_id'), 'client_secret' => \Config::get('auth.auth0.client_secret'), 'redirect_uri' => (string) \URL::to('/ccm/system/authentication/oauth2/auth0/callback')));
         // Print out debug messages (when debug = true)
         $auth0->setDebugger(function ($message) {
             echo "Auth0: {$message}<br>";
         });
         $this->user = $auth0->getUser();
         // We will now have an array that looks something like this...
         // Array
         // (
         //     [email] => simon@yump.com.au
         //     [email_verified] => 1
         //     [user_id] => auth0|56975523xxxxxxx711e7
         //     [picture] => https://s.gravatar.com/avatar/59a4e8xxxx7d19ba2?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fsi.png
         //     [nickname] => simon
         //     [identities] => Array
         //         (
         //             [0] => Array
         //                 (
         //                     [user_id] => 5697xxxxxxxxxxxx711e7
         //                     [provider] => auth0
         //                     [connection] => Username-Password-Authentication
         //                     [isSocial] =>
         //                 )
         //         )
         //     [updated_at] => 2016-01-15T01:00:59.553Z
         //     [created_at] => 2016-01-14T07:58:27.945Z
         //     [name] => simon@xxxxxxxx.com.au (or a full name if that is present in database)
         //     [given_name] => John
         //     [family_name] => Citizen
         //     [last_ip] => 203.111.222.182
         //     [last_login] => 2016-01-15T01:00:59.553Z
         //     [logins_count] => 20
         // )
         // echo '<pre>'; print_r($this->user); echo '</pre>';
         if ($this->user) {
             // User was authenticated via Auth0 successfully...
             $user = $this->registerOrLoginUser($this->user);
             // d($user);
             // Do final login steps and redirect user to home screen
             // Call the necessary functions in AuthenticationTypeController and the login page controller
             $this->completeAuthentication($user);
         } else {
             // TODO: Send an email to Yump team indicating a problem
             // Redirect back to login page with the following message
             $this->showError('Unfortunately you do not appear to have access to the intranet. Please contact <a href="mailto:support@yump.com.au">support@yump.com.au</a> for assistance.');
             // die;
         }
     } catch (\Exception $e) {
         // TODO: Send an email to Yump team indicating a problem
         // echo "Exception: " . $e->getMessage();
         $this->showError('Oops, there was a problem connecting to the authentication server and we could not log you in. Please contact <a href="mailto:support@yump.com.au">support@yump.com.au</a> for assistance.<br><br><small style="font-size: 66%; opacity: 0.7">' . $e->getMessage() . '</small>');
     }
 }
예제 #3
0
<?php

require_once 'vendor/autoload.php';
require_once 'helpers.php';
require_once 'dotenv-loader.php';
$auth0Oauth = new \Auth0\SDK\Auth0(array('domain' => 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));
$userInfo = $auth0Oauth->getUser();
if (isset($_REQUEST['logout'])) {
    $auth0Oauth->logout();
    session_destroy();
    header("Location: /");
}
if (isset($_REQUEST['update-metadata'])) {
    require 'update-metadata.php';
}
if (isset($_REQUEST['create-user'])) {
    require 'create_user.php';
    exit;
}
if ($userInfo) {
    require 'logeduser.php';
}
require 'login.php';
예제 #4
0
파일: index.php 프로젝트: Amialc/auth0-PHP
<?php

// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/dotenv-loader.php';
$auth0 = new \Auth0\SDK\Auth0(array('domain' => getenv('AUTH0_DOMAIN'), 'client_id' => getenv('AUTH0_CLIENT_ID'), 'client_secret' => getenv('AUTH0_CLIENT_SECRET'), 'redirect_uri' => getenv('AUTH0_CALLBACK_URL')));
$userInfo = $auth0->getUser();
?>
<html>
    <head>
        <script src="http://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script>
        <script src="https://cdn.auth0.com/js/lock/10.0/lock.min.js"></script>

        <script type="text/javascript" src="//use.typekit.net/iws6ohy.js"></script>
        <script type="text/javascript">try{Typekit.load();}catch(e){}</script>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- font awesome from BootstrapCDN -->
        <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">

        <script>
          var AUTH0_CLIENT_ID = '<?php 
echo getenv("AUTH0_CLIENT_ID");
?>
';
          var AUTH0_DOMAIN = '<?php 
echo getenv("AUTH0_DOMAIN");
?>
';