php - Silex framework: using both OAuth and Basic authentication -


in current silex project realize login via oauth , basic login both. oauth, using silex extension (https://github.com/gigablah/silex-oauth). unfortunately, have problems integrating basic login. thoughts have create custom user provider provides both oauth , password via db, don't know how realize really.

at point, have ugly mixture of 2 user providers. me, logic, not work. think off track, nice, if can give me tips - trying few days now...

my user provider:

<?php namespace core;  use symfony\component\security\core\user\userproviderinterface; use symfony\component\security\core\user\userinterface; use symfony\component\security\core\user\user; use symfony\component\security\core\exception\usernamenotfoundexception; use symfony\component\security\core\exception\unsupporteduserexception; use doctrine\dbal\connection;  class userprovider implements userproviderinterface { private $conn; private $oauth;  public function __construct($oauth = null) {     global $app;     if($oauth) { $this->oauth = $oauth; }     $this->conn = $app['db']; }   /*public function loadallusers() {     $users = $this->conn->executequery('select * users')->fetchall();     $users_object = array();      foreach ($users $user) {         if (!empty($user['username'])) {             $users_object[$user['username']] =  array($user['password'], $user['firstname'], $user['lastname'], explode(',', $user['roles']));         }     }       $oauth = (array)$this->oauth;     print_r($oauth->users);     if (count($oauth['users']) > 0 ) {                 print_r($this->oauth);     }      if ($this->oauth) {         if (count($oauth['users'])) {             return $this->oauth;         } else {      }     return $users_object;         } else {         return $users_object;     } }*/    public function loaduserbyoauthcredentials($token) {     return $this->oauth->loaduserbyoauthcredentials($token); }  public function loaduserbyusername($username) {     if ($this->oauth->loaduserbyusername($username)) {         return $this->oauth->loaduserbyusername($username);     } else {     $stmt = $this->conn->executequery('select * users username = ?', array(strtolower($username)));     if (!$user = $stmt->fetch()) {         throw new usernamenotfoundexception(sprintf('username "%s" not exist.', $username));     }           return new user($user['username'], $user['password'], explode(',', $user['roles']), true, true, true, true);     } }  public function refreshuser(userinterface $user) {     if (!$user instanceof user) {         throw new unsupporteduserexception(sprintf('instances of "%s" not supported.', get_class($user)));     }          return $this->loaduserbyusername($user->getusername());     }     public function supportsclass($class)     {         return $class === 'symfony\component\security\core\user\user';     } } 

thank in advance, if need more info, please tell me. thoras


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -