title: How to use Silex authorization with OpenID?
body: <p>I'm trying to integrate OpenID into my Silex application, but I'm unsure how to hook it into <a href="http://silex.sensiolabs.org/doc/providers/security.html" rel="nofollow">Silex's authorization service provider</a>. It looks like they've bundled authentication and authorization, which I'm not super keen on.</p>
  
  <h3>What I've got so far:</h3>
  
  <p>First I generate an OpenID login URL using <a href="https://gitlab.com/barrel/LightOpenID" rel="nofollow">LightOpenID</a> and inject it into my Twig templates:</p>
  
  <pre><code>$app['openid'] = $app-&gt;share(function (Application $app) {
      $openid = new \LightOpenID($app['request']-&gt;getHttpHost());
      $openid-&gt;identity = 'https://www.google.com/accounts/o8/id';
      $openid-&gt;returnUrl = $app-&gt;url('check_openid', array('returnUrl' =&gt; $app['request']-&gt;get('returnUrl', $app['request']-&gt;getRequestUri())));
      return $openid;
  });
  
  $app-&gt;before(function (Request $request) use ($app) {
      // todo: check if user is logged in, if not generate OpenID login url
      $app['twig']-&gt;addGlobal('openid', array('authUrl' =&gt; $app['openid']-&gt;authUrl()));
  });
  </code></pre>
  
  <p>And render that as part of my <a href="http://twig.sensiolabs.org/" rel="nofollow">Twig</a> layout:</p>
  
  <pre><code>&lt;a href="{{ openid.authUrl }}" class="btn btn-google-plus btn-xs" type="button"&gt;&lt;i class="icon-google-plus"&gt;&lt;/i&gt; Sign in with Google&lt;/a&gt;
  </code></pre>
  
  <p>When you click that link, <a href="https://developers.google.com/accounts/docs/OpenID" rel="nofollow">Google</a> does the authentication and sends you back here:</p>
  
  <pre><code>$app-&gt;get('/login/openid', function (Request $request) use ($app) {
      if(!$app['openid']-&gt;mode) {
          return $app-&gt;redirect($app['openid']-&gt;authUrl(), 303);
      } elseif($app['openid']-&gt;mode === 'cancel') {
          // TODO: redirect user back to login page w/ error message
          die('User has canceled authentication!');
      } elseif($app['openid']-&gt;validate()) {
          // TODO: log user in (set session variables)
          return $app-&gt;redirect($request-&gt;get('returnUrl', $app-&gt;path('home')), 303);
      } else {
          throw new Exception('User could not be validated');
      }
  })-&gt;bind('check_openid');
  </code></pre>
  
  <h3>Where I'm stuck:</h3>
  
  <p>How do I log the user in such that I can take advantage of Silex/Symfony's security "firewalls"? I want to limit the <code>/admin</code> section of my site to only certain users and I don't want to implement a whole ACL mechanism myself.</p>