PHP authentication Symfony2 without a database (SOAP)

I have a soap for user authentication

<?php $client = new SoapClient('http://mysite/code/soap.wsdl'); $user = $client->login('username','password'); if( isset($user['IdAccount']) && ($user['IdAccount'] > 0) ) echo 'Logon OK'; else echo 'Logon Fail!'; 

I would like to use in Symfony2 without a database, only in memory ...

I tried to implement Custom UserProvider , but I do not have all the data necessary for it to work ...

 class WebserviceUserProvider implements UserProviderInterface { public function loadUserByUsername($username) { $client = new SoapClient('http://mysite/code/soap.wsdl'); $user = $client->login($username, PASSWORD???? ); if ( isset($user['IdAccount']) && ($user['IdAccount'] > 0) ) return new WebserviceUser($username, PASSWORD????, SALT???, ROLES????); throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username) ); } 

I can not change the soap

Sorry for my bad english !: (

+5
source share
1 answer

As I understand it, you want to use authentication and password verification using the SOAP service.

If you are using Symfony 2.4 or higher, you can use SimpleFormAuthenticatorInterface

Implementation Example:

 // ... namespace and uses class Authenticator implements SimpleFormAuthenticatorInterface { private $soapClient; public function __construct(\SoapClient $soapClient) { $this->soapClient = $soapClient; } public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey) { $user = $this->soapClient->login($token->getUsername(), $token->getCredentials()); if (isset($user['IdAccount']) && ($user['IdAccount'] > 0)) { $user = $userProvider->loadUserByUsername($token->getUsername()); return new UsernamePasswordToken( $user, null, $providerKey, $user->getRoles() ); } throw new AuthenticationException('Invalid username or password'); } public function supportsToken(TokenInterface $token, $providerKey) { return $token instanceof UsernamePasswordToken && $token->getProviderKey() === $providerKey; } public function createToken(Request $request, $username, $password, $providerKey) { return new UsernamePasswordToken($username, $password, $providerKey); } } 
+2
source

Source: https://habr.com/ru/post/1201957/


All Articles