1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace Base\OAuthClientBundle\Security;
- use Symfony\Component\Security\Core\User\UserProviderInterface;
- use Symfony\Component\Security\Core\User\User;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
- class OAuthProxyUserProvider implements UserProviderInterface
- {
- public function getUsernameForApiKey($apiKey)
- {
- // Look up the username based on the token in the database, via
- // an API call, or do something entirely different
- $username = "nose";
- return $username;
- }
- public function loadUserByUsername($username)
- {
- return new User(
- $username,
- null,
- // the roles for the user - you may choose to determine
- // these dynamically somehow based on the user
- array('ROLE_API')
- );
- }
- public function refreshUser(UserInterface $user)
- {
- // this is used for storing authentication in the session
- // but in this example, the token is sent in each request,
- // so authentication can be stateless. Throwing this exception
- // is proper to make things stateless
- throw new UnsupportedUserException();
- }
- public function supportsClass($class)
- {
- return User::class === $class;
- }
- }
|