PHP code example of vatsim / sso

1. Go to this page and download the library: Download vatsim/sso library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vatsim / sso example snippets


'providers' => array(
    // ...
    'Vatsim\OAuth\OAuthServiceProvider',
),

'aliases' => array(
    // ...
    'VatsimSSO'       => 'Vatsim\OAuth\Facades\SSO',
),

/*
 * DO NOT PUBLISH THE KEY, SECRET AND CERT TO CODE REPOSITORIES
 * FOR SECURITY.
 */

/*
 * The location of the VATSIM OAuth interface
 */
$base = 'https://';

/*
 * The consumer key for your organisation (provided by VATSIM)
 */
$key = 'MY_KEY';

/*
 * The secret key for your organisation (provided by VATSIM)
 * Do not give this to anyone else or display it to your users. It must be kept server-side
 */
$secret = 'my_secret';

/*
 * The signing method you are using to encrypt your request signature.
 * Different options must be enabled on your account at VATSIM.
 * Options: RSA / HMAC
 */
$method = 'HMAC';

/*
 * Your RSA **PRIVATE** key
 * If you are not using RSA, this value can be anything (or not set)
 */
$cert = '';

/*
 * The URL users will be redirected to after they log in, this should
 * be on the same server as the request
 */
$return = 'http://example.com/valiatelogin';

// load the Composer autoload file, which automatically
// loads all the classes o = new SSO($base, $key, $secret, $method, $cert);

// Laravel
return VatsimSSO::login(
    Config::get('vatsimsso:return'),
    function($key, $secret, $url) {
        Session::put('vatsimauth', compact('key', 'secret'));
        return Redirect::to($url);
    },
    function($error) {
        throw new Exception('Could not authenticate: ' . $error['message']);
    }
);

// Outside Laravel
$sso->login(
    $return,
    function($key, $secret, $url) {
        $_SESSION['vatsimauth'] = compact('key', 'secret');
        header('Location: ' . $url);
        die();
    }
);

// Laravel
$session = Session::get('vatsimauth');

return VatsimSSO::validate(
    $session['key'],
    $session['secret'],
    Input::get('oauth_verifier'),
    function($user, $request) {
        // At this point we can remove the session data.
        Session::forget('vatsimauth');
        
        Auth::loginUsingId($user->id);
        return Redirect::home();
    },
    function($error) {
        throw new Exception('Could not authenticate: ' . $error['message']);
    }
);

// Outside Laravel
$session = $_SESSION['vatsimauth'];

$sso->validate(
    $session['key'],
    $session['secret'],
    $_GET['oauth_verifier'],
    function($user, $request) {
        // At this point we can remove the session data.
        unset($_SESSION['vatsimauth']);
        
        // do something to log the user in on your site using the user id
        // $user->id
        
        // Redirect home
        header('Location: /');
        die();
    }
);