php - User authentication with SecurityServiceProvider via POST -


what i'm looking

  1. authenticate users on bar.com ,
  2. post credentials foo.com/login , re-authenticate them without needing log in again.

currently, secure pages on foo.com i'm using form-based access via securityserviceprovider , db-backed userprovider authenticate. works great: attempt load secured route intercepted firewall , redirected after successful authentication.

what can't figure out how pass post variables (username , password) on provider instance , forward user supplied route.

stub post route:

$app->post('/login', function(request $req) use ($app) {     $route    = $req->request->filter('route');     $username = $req->get('username');     $password = $req->get('password');      /* magic happens...? */  }); 

here example of using user provider load user check password matches setting token in security service. if put code route can access request username , password.

$userprovider = $app['security.user_provider.default'];  $user = null; try {    $user = $userprovider->loaduserbyusername($username); } catch (usernamenotfoundexception $e) {    ; } $encoder = $app['security.encoder_factory']->getencoder($user);  // compute encoded password $encodedpassword = $encoder->encodepassword($password, $user->getsalt());  // compare passwords if ($user->password == $encodedpassword) {    // set security token security    $token = new usernamepasswordtoken($user, $password, 'yourproviderkeyhere', array('role_user'));    $app['security']->settoken($token);     // redirect or give response here } else {    // error feedback } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -