Ejemplo n.º 1
0
 public function getServer($force = false)
 {
     if ($this->_server === null || $force === true) {
         $storages = $this->createStorages();
         $server = new \OAuth2\Server($storages, $this->options);
         $server->addGrantType(new \OAuth2\GrantType\UserCredentials($storages['user_credentials']));
         $server->addGrantType(new \OAuth2\GrantType\RefreshToken($storages['refresh_token'], ['always_issue_new_refresh_token' => true]));
         $this->_server = $server;
     }
     return $this->_server;
 }
Ejemplo n.º 2
0
 /**
  * 搭建OAuth2 的服务
  */
 public function oauth_server()
 {
     require_once './OAuth2/Autoloader.php';
     \OAuth2\Autoloader::register();
     $dsn = 'mysql:host=127.0.0.1;dbname=opencenter';
     $this->storage = new \OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => 'root', 'password' => 'suzhouadmin'));
     $server = new \OAuth2\Server($this->storage);
     $this->server_all = $server;
     $server->addGrantType(new \OAuth2\GrantType\ClientCredentials($this->storage));
     $server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($this->storage));
 }
 public function __construct()
 {
     global $CONFIG;
     \OAuth2\Autoloader::register();
     $storage = new \OAuth2\Storage\Pdo(array('dsn' => "mysql:dbname=" . $CONFIG->dbname . ";host=" . $CONFIG->dbhost, 'username' => $CONFIG->dbuser, 'password' => $CONFIG->dbpass));
     $server = new \OAuth2\Server($storage, array('access_lifetime' => 3600 * 24 * 7, 'enforce_state' => false));
     $uc_storage = new UserCredentialsStorage();
     $server->addGrantType(new \OAuth2\GrantType\UserCredentials($uc_storage));
     $server->addGrantType(new \OAuth2\GrantType\RefreshToken($storage, array('always_issue_new_refresh_token' => true, 'refresh_token_lifetime' => 3600 * 24 * 30 * 6)));
     $this->server = $server;
 }
 public function testServiceCreatedWithOverriddenValues()
 {
     $adapter = $this->getMockBuilder('OAuth2\\Storage\\Pdo')->disableOriginalConstructor()->getMock();
     $this->services->setService('TestAdapter', $adapter);
     $this->services->setService('Config', array('zf-oauth2' => array('storage' => 'TestAdapter', 'enforce_state' => false, 'allow_implicit' => true, 'access_lifetime' => 12000)));
     $expectedService = new \OAuth2\Server($adapter, array('enforce_state' => false, 'allow_implicit' => true, 'access_lifetime' => 12000));
     $expectedService->addGrantType(new ClientCredentials($adapter));
     $expectedService->addGrantType(new AuthorizationCode($adapter));
     $expectedService->addGrantType(new UserCredentials($adapter));
     $expectedService->addGrantType(new RefreshToken($adapter));
     $service = $this->factory->createService($this->services);
     $this->assertInstanceOf('OAuth2\\Server', $service);
     $this->assertEquals($expectedService, $service);
 }
 /**
  * @Get("/auth")
  */
 public function authAction()
 {
     $storage = new OAuth2\Storage\Mongo(DI::getDefault()->getMongo());
     $server = new \OAuth2\Server($storage);
     $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
     $server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
 }
Ejemplo n.º 6
0
 /**
  * Create an OAuth2 Server
  *
  */
 public function createServer()
 {
     // Init storage
     $storage = new OAuth2\Storage\Pdo($this->modx->config['connections'][0], $this->tablenames);
     if (!$storage instanceof OAuth2\Storage\Pdo) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[OAuth2Server] could not load a valid storage class!');
         return null;
     }
     // Init server
     $server = new OAuth2\Server($storage, $this->options['server']);
     if (!$server instanceof OAuth2\Server) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[OAuth2Server] could not load a valid server class!');
         return null;
     }
     // Only auth code and refresh token grant types supported right now
     $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage, $this->options['server']));
     $server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, $this->options['server']));
     return $server;
 }
Ejemplo n.º 7
0
/**
 * Returns an OAuth2 access token to the client
 *
 * @param array $post Post data
 *
 * @return mixed
 */
function getToken($post)
{
    $old_server_method = $_SERVER['REQUEST_METHOD'];
    if (!empty($_SERVER['CONTENT_TYPE'])) {
        $old_content_type = $_SERVER['CONTENT_TYPE'];
    }
    $_SERVER['REQUEST_METHOD'] = 'POST';
    $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
    $_POST = $post;
    OAuth2\Autoloader::register();
    $oauth_config = array('user_table' => 'users');
    $val_array = array('dsn' => 'pgsql:host=' . R_DB_HOST . ';dbname=' . R_DB_NAME . ';port=' . R_DB_PORT, 'username' => R_DB_USER, 'password' => R_DB_PASSWORD);
    $storage = new OAuth2\Storage\Pdo($val_array, $oauth_config);
    $server = new OAuth2\Server($storage);
    if (isset($_POST['grant_type']) && $_POST['grant_type'] == 'password') {
        $val_array = array('password' => $_POST['password']);
        $users = array($_POST['username'] => $val_array);
        $user_credentials = array('user_credentials' => $users);
        $storage = new OAuth2\Storage\Memory($user_credentials);
        $server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));
    } elseif (isset($_POST['grant_type']) && $_POST['grant_type'] == 'refresh_token') {
        $always_issue_new_refresh_token = array('always_issue_new_refresh_token' => true);
        $server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, $always_issue_new_refresh_token));
    } elseif (isset($_POST['grant_type']) && $_POST['grant_type'] == 'authorization_code') {
        $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
    } else {
        $val_array = array('client_secret' => OAUTH_CLIENT_SECRET);
        $clients = array(OAUTH_CLIENTID => $val_array);
        $credentials = array('client_credentials' => $clients);
        $storage = new OAuth2\Storage\Memory($credentials);
        $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
    }
    $response = $server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send('return');
    $_SERVER['REQUEST_METHOD'] = $old_server_method;
    if (!empty($old_content_type)) {
        $_SERVER['CONTENT_TYPE'] = $old_content_type;
    }
    return json_decode($response, true);
}
Ejemplo n.º 8
0
 /**
  * Method to instantiate the file-based api call.
  *
  * @param   mixed  $options  Optional custom options to load. JRegistry or array format
  *
  * @since   1.2
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     // Get the global JAuthentication object.
     jimport('joomla.user.authentication');
     // Register OAuth2 classes
     require_once dirname(__FILE__) . '/Autoloader.php';
     OAuth2\Autoloader::register();
     // OAuth2 Server config from plugin
     $this->serverConfig = array('use_jwt_access_tokens' => (bool) RBootstrap::getConfig('oauth2_use_jwt_access_tokens', false), 'store_encrypted_token_string' => (bool) RBootstrap::getConfig('oauth2_store_encrypted_token_string', true), 'use_openid_connect' => (bool) RBootstrap::getConfig('oauth2_use_openid_connect', false), 'id_lifetime' => RBootstrap::getConfig('oauth2_id_lifetime', 3600), 'access_lifetime' => RBootstrap::getConfig('oauth2_access_lifetime', 3600), 'www_realm' => 'Service', 'token_param_name' => RBootstrap::getConfig('oauth2_token_param_name', 'access_token'), 'token_bearer_header_name' => RBootstrap::getConfig('oauth2_token_bearer_header_name', 'Bearer'), 'enforce_state' => (bool) RBootstrap::getConfig('oauth2_enforce_state', true), 'require_exact_redirect_uri' => (bool) RBootstrap::getConfig('oauth2_require_exact_redirect_uri', true), 'allow_implicit' => (bool) RBootstrap::getConfig('oauth2_allow_implicit', false), 'allow_credentials_in_request_body' => (bool) RBootstrap::getConfig('oauth2_allow_credentials_in_request_body', true), 'allow_public_clients' => (bool) RBootstrap::getConfig('oauth2_allow_public_clients', true), 'always_issue_new_refresh_token' => (bool) RBootstrap::getConfig('oauth2_always_issue_new_refresh_token', false));
     // Set database names to Redcore DB tables
     $prefix = JFactory::getDbo()->getPrefix();
     $databaseConfig = array('client_table' => $prefix . 'redcore_oauth_clients', 'access_token_table' => $prefix . 'redcore_oauth_access_tokens', 'refresh_token_table' => $prefix . 'redcore_oauth_refresh_tokens', 'code_table' => $prefix . 'redcore_oauth_authorization_codes', 'user_table' => $prefix . 'redcore_oauth_users', 'jwt_table' => $prefix . 'redcore_oauth_jwt', 'jti_table' => $prefix . 'redcore_oauth_jti', 'scope_table' => $prefix . 'redcore_oauth_scopes', 'public_key_table' => $prefix . 'redcore_oauth_public_keys');
     $conf = JFactory::getConfig();
     $dsn = 'mysql:dbname=' . $conf->get('db') . ';host=' . $conf->get('host');
     $username = $conf->get('user');
     $password = $conf->get('password');
     $storage = new OAuth2\Storage\Pdoredcore(array('dsn' => $dsn, 'username' => $username, 'password' => $password), $databaseConfig);
     $this->server = new OAuth2\Server($storage, $this->serverConfig);
     // Add the "Authorization Code" grant type (this is where the oauth magic happens)
     $this->server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage, $this->serverConfig));
     // Add the "Client Credentials" grant type (it is the simplest of the grant types)
     $this->server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage, $this->serverConfig));
     // Add the "User Credentials" grant type (this is modified to suit Joomla authorization)
     $this->server->addGrantType(new OAuth2\GrantType\UserCredentials($storage, $this->serverConfig));
     // Add the "Refresh Token" grant type (this is great for extending expiration time on tokens)
     $this->server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, $this->serverConfig));
     /*
      * @todo Implement JwtBearer Grant type with public_key
     // Typically, the URI of the oauth server
     $audience = rtrim(JUri::base(), '/');
     
     // Add the "Refresh Token" grant type (this is great for extending expiration time on tokens)
     $this->server->addGrantType(new OAuth2\GrantType\JwtBearer($storage, $audience));
     */
     // Init Environment
     $this->setApiOperation();
 }
Ejemplo n.º 9
0
 /**
  * Get oauth2 server instance
  * @param type $force
  * @return \OAuth2\Server
  */
 public function getServer($force = false)
 {
     if ($this->_server === null || $force === true) {
         $storages = $this->createStorages();
         $server = new \OAuth2\Server($storages, $this->options);
         foreach ($this->grantTypes as $name => $options) {
             if (!isset($storages[$name]) || empty($options['class'])) {
                 throw new \yii\base\InvalidConfigException('Invalid grant types configuration.');
             }
             $class = $options['class'];
             unset($options['class']);
             $reflection = new \ReflectionClass($class);
             $config = array_merge([0 => $storages[$name]], [$options]);
             $instance = $reflection->newInstanceArgs($config);
             $server->addGrantType($instance);
         }
         $this->_server = $server;
     }
     return $this->_server;
 }
<?php

$dsn = 'mysql:host=db;dbname=test;port=3306';
$username = '******';
$password = '******';
$storagePdo = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
$storageRedis = new OAuth2\Storage\Redis(new \Predis\Client('tcp://redis:6379'));
$server = new OAuth2\Server(['client_credentials' => $storagePdo, 'scope' => $storagePdo, 'access_token' => $storageRedis, 'authorization_code' => $storageRedis]);
$server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storageRedis));
Ejemplo n.º 11
0
        $stmt = $this->db->prepare(sprintf('SELECT * from %s c JOIN %s u ON c.user_id = u.user_id where c.client_id = :client_id and u.email_verified = 1', $this->config['client_table'], $this->config['user_table']));
        $stmt->execute(compact('client_id'));
        $result = $stmt->fetch();
        // make this extensible
        return $result && $result['client_secret'] == $client_secret;
    }
}
$authenticateForRole = function () {
    //global $conOptions;
    $_dsn = diyConfig::read('db.dsn');
    $_username = diyConfig::read('db.username');
    $_password = diyConfig::read('db.password');
    $storage = new PdoStorageWithEmailVerification(array('dsn' => $_dsn, 'username' => $_username, 'password' => $_password));
    //$storage = new OAuth2\Storage\Pdo(array('dsn' => $_dsn, 'username' => $_username, 'password' => $_password));
    $server = new OAuth2\Server($storage);
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage), array('allow_credentials_in_request_body => true'));
    $cryptoStorage = new OAuth2\Storage\CryptoToken($storage);
    $server->addStorage($cryptoStorage, "access_token");
    $cryptoResponseType = new OAuth2\ResponseType\CryptoToken($storage);
    $server->addResponseType($cryptoResponseType);
    return $server;
};
$diy_storage = function () {
    //global $conOptions;
    $_dbfile = diyConfig::read('db.file');
    $db = new PDO(sprintf('sqlite:%s', $_dbfile));
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    return $db;
};
$diy_exception = function () {
 public function testServiceCreatedWithSelectedGrandTypes()
 {
     $adapter = $this->getMockBuilder('OAuth2\\Storage\\Pdo')->disableOriginalConstructor()->getMock();
     $this->services->setService('TestAdapter', $adapter);
     $this->services->setService('Config', ['zf-oauth2' => ['storage' => 'TestAdapter', 'grant_types' => ['client_credentials' => false, 'password' => true, 'refresh_token' => true]]]);
     $expectedService = new \OAuth2\Server($adapter, ['enforce_state' => true, 'allow_implicit' => false, 'access_lifetime' => 3600]);
     $expectedService->addGrantType(new UserCredentials($adapter));
     $expectedService->addGrantType(new RefreshToken($adapter));
     $service = $this->factory->createService($this->services);
     $this->assertInstanceOf('ZF\\OAuth2\\Factory\\OAuth2ServerInstanceFactory', $service);
     $server = $service();
     $this->assertInstanceOf('OAuth2\\Server', $server);
     $this->assertEquals($expectedService, $server);
 }
Ejemplo n.º 13
0
function app()
{
    // 创建服务容器。
    $app = new Container();
    // 注册加载服务。
    $app['loader'] = function () {
        require_once __DIR__ . '/../../application/libraries/Loader.php';
        return new Loader();
    };
    //注册http核心服务。
    $app['http'] = function () {
        return new Slim();
    };
    // 注册数据库配置信息。
    $app['db_config'] = $app['loader']->config('database', $app);
    // 注册全局配置信息。
    $app['global_config'] = $app['loader']->config('config', $app);
    // 注册数据库服务。
    $app['pdo'] = function () use($app) {
        $db_config = $app['db_config']['default'];
        $pdo = new \PDO($db_config['dsn'], $db_config['username'], $db_config['password']);
        $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $pdo->query('SET NAMES ' . $db_config['char_set']);
        return new NotORM($pdo);
    };
    // 注册事件服务。
    $app['event'] = function () {
        return new Evenement\EventEmitter();
    };
    // 注册命令服务。
    $app['buslocator'] = function () {
        return new CommandHandlerLocator();
    };
    $app['bus'] = function () use($app) {
        $app['loader']->config('bus', $app);
        return new SequentialCommandBus($app['buslocator']);
    };
    // 注册视图服务。
    $app['view'] = function () use($app) {
        $config = $app['loader']->config('config', $app);
        $loader = new Twig_Loader_Filesystem($config['view']['templates']);
        $twig = new Twig_Environment($loader, array('cache' => $config['view']['compilation_cache']));
        return $twig;
    };
    // 注册认证服务。
    $app['oauth2'] = function () use($app) {
        $db_config = $app['db_config']['oauth2'];
        $storage = new \OAuth2\Storage\Pdo(array('dsn' => $db_config['dsn'], 'username' => $db_config['username'], 'password' => $db_config['password']));
        $server = new \OAuth2\Server($storage);
        require_once __DIR__ . '/../../application/libraries/PasswordCredentials.php';
        $server->addGrantType(new \OAuth2\GrantType\UserCredentials(new \OAuth2\Storage\PasswordCredentials()));
        require_once __DIR__ . '/../../application/libraries/RefreshToken.php';
        $server->addGrantType(new \OAuth2\GrantType\RefreshToken(new \OAuth2\Storage\RefreshToken(), array('always_issue_new_refresh_token' => true)));
        return $server;
    };
    // 注册Json解析服务。
    $app['encoder'] = function () {
        return new JsonEncoder();
    };
    $app['decoder'] = function () {
        return new JsonDecoder();
    };
    $app['JsonValidator'] = function () {
        return new JsonValidator();
    };
    // 载入助手函数。
    $app['loader']->helper('function', $app);
    return $app;
}
Ejemplo n.º 14
0
<?php

require 'vendor/autoload.php';
$dsn = 'mysql:dbname=oauth2_db;host=localhost';
$username = '******';
$password = '';
// error reporting enabled
ini_set('display_errors', 1);
error_reporting(E_ALL);
$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
$server = new OAuth2\Server($storage);
$server->addGrantType(new OAuth2\GrantType\RefreshToken($storage));
$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
Ejemplo n.º 15
0
<?php

require_once 'vendor/bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php';
OAuth2\Autoloader::register();
$dsn = 'mysql:dbname=oauth;host=localhost';
$username = '******';
$password = '******';
ini_set('display_errors', 1);
error_reporting(E_ALL);
$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
// Pass a storage object or array of storage objects to the OAuth2 server class
$server = new OAuth2\Server($storage);
// create the grant type
$grantType = new OAuth2\GrantType\UserCredentials($storage);
// add the grant type to your OAuth server
$server->addGrantType($grantType);
Ejemplo n.º 16
0
$well_known = $wp_query->get('well-known');
$storage = new OAuth2\Storage\Wordpressdb();
$config = array('use_crypto_tokens' => false, 'store_encrypted_token_string' => false, 'use_openid_connect' => $o['use_openid_connect'] == '' ? false : $o['use_openid_connect'], 'issuer' => site_url(null, 'https'), 'id_lifetime' => $o['id_token_lifetime'] == '' ? 3600 : $o['id_token_lifetime'], 'access_lifetime' => $o['access_token_lifetime'] == '' ? 3600 : $o['access_token_lifetime'], 'refresh_token_lifetime' => $o['refresh_token_lifetime'] == '' ? 86400 : $o['refresh_token_lifetime'], 'www_realm' => 'Service', 'token_param_name' => 'access_token', 'token_bearer_header_name' => 'Bearer', 'enforce_state' => $o['enforce_state'] == '1' ? true : false, 'require_exact_redirect_uri' => $o['require_exact_redirect_uri'] == '1' ? true : false, 'allow_implicit' => $o['implicit_enabled'] == '1' ? true : false, 'allow_credentials_in_request_body' => true, 'allow_public_clients' => false, 'always_issue_new_refresh_token' => true, 'redirect_status_code' => 302);
$server = new OAuth2\Server($storage, $config);
/*
|--------------------------------------------------------------------------
| SUPPORTED GRANT TYPES
|--------------------------------------------------------------------------
|
| Authorization Code will always be on. This may be a bug or a f@#$ up on
| my end. None the less, these are controlled in the server settings page.
|
*/
$support_grant_types = array();
if ('1' == $o['auth_code_enabled']) {
    $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
}
if ('1' == $o['client_creds_enabled']) {
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
}
if ('1' == $o['user_creds_enabled']) {
    $server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));
}
if ('1' == $o['refresh_tokens_enabled']) {
    $server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, $config));
}
if ('1' == $o['use_openid_connect']) {
    $server->addGrantType(new OAuth2\OpenID\GrantType\AuthorizationCode($storage, $config));
}
/*
|--------------------------------------------------------------------------
Ejemplo n.º 17
0
        });
    });
    post('upload/file', 'FileController@uploadFile');
    get('download/{id}', 'FileController@getDownload');
    Route::resource('project', 'ProjectController');
    Route::resource('clients', 'ClientController');
    Route::resource('role', 'RoleController');
});
App::bind('App\\Services\\Interfaces\\SendMailInterface', 'App\\Services\\SESSendMail');
/* Routes for desktop and mobile apps */
Route::group(['prefix' => 'rest'], function () {
    post('get-timeentries-by-uid', 'RestController@getTimeEntryByUid');
    post('auth', 'RestController@login');
    get('projects', 'RestController@getProjectList');
    get('tags', 'RestController@getTags');
    post('timesheet/save', 'RestController@save');
    post('timesheet/delete', 'RestController@deleteTimeEntry');
    post('timesheet/sync-timesheets', 'RestController@syncTimesheets');
});
/************************************  OAUTH  ***********************************************/
/* Routes for oauth */
post('oauth/token', 'Auth\\OAuthController@getOAuthToken');
//oauth singleton object
App::singleton('oauth2', function () {
    $storage = new OAuth2\Storage\Pdo(array('dsn' => 'mysql:dbname=' . env('DB_DATABASE') . ';host=' . env('DB_HOST'), 'username' => env('DB_USERNAME'), 'password' => env('DB_PASSWORD')));
    $server = new OAuth2\Server($storage, array('access_lifetime' => env('ACCESS_TOKEN_LIFETIME')));
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
    $server->addGrantType(new App\Http\Controllers\Auth\DesktopAppGrantType($storage));
    $server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, ['always_issue_new_refresh_token' => true]));
    return $server;
});
Ejemplo n.º 18
0
<?php

//database configuration
$dsn = 'mysql:dbname=oauth2server;host=localhost';
$username = '******';
$password = '******';
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once 'src/OAuth2/Autoloader.php';
OAuth2\Autoloader::register();
$storage = new OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
// Pass a storage object or array of storage objects to the OAuth2 server class
$server = new OAuth2\Server($storage);
// Add the "Client Credentials" grant type
$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
// Add the "Authorization Code" grant type
$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
//Add the "Refresh Token" grant type
$server->addGrantType(new OAuth2\GrantType\RefreshToken($storage, array('always_issue_new_refresh_token' => true)));
Ejemplo n.º 19
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
App::singleton('oauth2', function () {
    $storage = new OAuth2\Storage\Mongo(App::make('db')->getMongoDB());
    $server = new OAuth2\Server($storage);
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
    return $server;
});
Route::get('/', function () {
    if (Auth::check()) {
        $site = \Site::first();
        $admin_dashboard = new \app\locker\data\dashboards\AdminDashboard();
        //if super admin, show site dashboard, otherwise show list of LRSs can access
        if (Auth::user()->role == 'super') {
            $list = Lrs::all();
            return View::make('partials.site.dashboard', array('site' => $site, 'list' => $list, 'stats' => $admin_dashboard->getFullStats(), 'graph_data' => $admin_dashboard->getGraphData(), 'dash_nav' => true));
        } else {
            $lrs = Lrs::where('users._id', \Auth::user()->_id)->get();
            return View::make('partials.lrs.list', array('lrs' => $lrs, 'list' => $lrs, 'site' => $site));
        }
    } else {
Ejemplo n.º 20
0
<?php

$database = 'aums_api';
$dsn = 'mysql:dbname=' . $database . ';host=localhost';
$username = '******';
$password = '******';
DB::$user = $username;
DB::$password = $password;
DB::$dbName = $database;
// error reporting (this is a demo, after all!)
ini_set('display_errors', 1);
error_reporting(E_ALL);
// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
$storage = new OAuth2\Storage\Pdo(['dsn' => $dsn, 'username' => $username, 'password' => $password]);
// Pass a storage object or array of storage objects to the OAuth2 server class
$server = new OAuth2\Server($storage);
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
$grantType = new OAuth2\GrantType\RefreshToken($storage);
$server->addGrantType($grantType);
// configure available scopes
$defaultScope = 'basic';
$supportedScopes = ['basic', 'extras', 'profile_pic'];
$memory = new OAuth2\Storage\Memory(['default_scope' => $defaultScope, 'supported_scopes' => $supportedScopes]);
$scopeUtil = new OAuth2\Scope($memory);
$server->setScopeUtil($scopeUtil);
Ejemplo n.º 21
0
 * If the configuration specify the use of metadata adapter use it or use memory otherwise.
 */
$di->setShared('modelsMetadata', function () {
    return new MetaDataAdapter();
});
/**
 * Start the session the first time some component request the session service.
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
/**
 * Set OAuth2 server.
 */
$di->setShared('oauth', function () use($config) {
    $dsn = strtolower($config->database->adapter) . ':dbname=' . $config->database->dbname . ';host=' . $config->database->host;
    OAuth2\Autoloader::register();
    $storage = new ApiStorage(['dsn' => $dsn, 'username' => $config->database->username, 'password' => $config->database->password]);
    $server = new OAuth2\Server($storage, ['allow_implicit' => true]);
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
    $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));
    return $server;
});
/**
 * Set Facebook API credentials.
 */
$di->setShared('facebook', function () use($config) {
    return new Facebook(['app_id' => $config->fb->appId, 'app_secret' => $config->fb->secret, 'callback_uri' => $config->application->domain . $config->application->baseUri . 'v1/' . $config->fb->callback]);
});
Ejemplo n.º 22
0
 *
 * @category   PHP
 * @package    Restyaboard
 * @subpackage Core
 * @author     Restya <*****@*****.**>
 * @copyright  2014 Restya
 * @license    http://restya.com/ Restya Licence
 * @link       http://restya.com/
 */
require_once 'config.inc.php';
require_once 'libs/vendors/OAuth2/Autoloader.php';
OAuth2\Autoloader::register();
$oauth_config = array('user_table' => 'users');
$val_array = array('dsn' => 'pgsql:host=' . R_DB_HOST . ';dbname=' . R_DB_NAME . ';port=' . R_DB_PORT, 'username' => R_DB_USER, 'password' => R_DB_PASSWORD);
$storage = new OAuth2\Storage\Pdo($val_array, $oauth_config);
$server = new OAuth2\Server($storage);
if (isset($_POST['grant_type']) && $_POST['grant_type'] == 'password') {
    $val_array = array('password' => $_POST['password']);
    $users = array($_POST['username'] => $val_array);
    $user_credentials = array('user_credentials' => $users);
    $storage = new OAuth2\Storage\Memory($user_credentials);
    $server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));
} elseif (isset($_POST['grant_type']) && $_POST['grant_type'] == 'refresh_token') {
    $server->addGrantType(new OAuth2\GrantType\RefreshToken($storage));
} else {
    $val_array = array('client_secret' => OAUTH_CLIENT_SECRET);
    $clients = array(OAUTH_CLIENTID => $val_array);
    $credentials = array('client_credentials' => $clients);
    $storage = new OAuth2\Storage\Memory($credentials);
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
}