Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 authenticating users through a webservice

I'm currently dealing with Symfony2's Security component.

I try to authenticate users against a webservice. To authenticate a user, I have to provide to the webservice a username and a password.

I know that I've got to create a class that implements UserProvider. But the loadUserByUsername function doesn't fit my webservice needs : in order to authenticate a user, it ask for both username and password whereas the UserProvider's function only requires username.

Here is a similar question to the problem I face : Symfony2 authentication without UserProvider

I've been struggling on this problem for a couple of days...

like image 932
SupaCoco Avatar asked Nov 04 '22 03:11

SupaCoco


1 Answers

I fixed this problem in that way:

services.yml:

services:
     user_provider:
         class: "%my_class%"
         arguments: ["@service_container"]

WebServiceUserProvider.php

/**
 * @param ContainerInterface $container
 */
public function __construct(ContainerInterface $container)
{
    $this->apiClient = $container->get('api_client');
    $this->request = $container->get('request');
}

and use $password = $this->request->get('password'); in your loadUserByUsername method

like image 155
Mauro Avatar answered Nov 15 '22 08:11

Mauro