0

I just need to authorize custom user. Without any froms, tokens and etc. I have user entity in my DB. User class is already configuren it fos_user.yaml:

fos_user:
db_driver: orm
firewall_name: main
from_email:
    address: '***@*******.**'
    sender_name: '**.****.**'
user_class: App\Entity\User

Is it possible? Somethong like

Authurizer::authorize($userEntity)

Thanks.

rib
  • 94
  • 6
  • So, existing FOS users are supplied from the DB, where are but those "custom" supplied from? – Jovan Perovic Aug 20 '18 at 13:03
  • I mean, is there any way to authorize user programmly from entity object? Somthing like "Authurizer::authorize($userEntity)" – rib Aug 20 '18 at 13:06
  • What do you mean you want to authorize without any forms, tokens, etc.? How do you know which user to authenticate? – dbrumann Aug 20 '18 at 13:06
  • I find my user by api information from other web service. I know, its bad idea..=( I have a complicated task, so i cant explain it all) – rib Aug 20 '18 at 13:09
  • 1
    Sure, FOSUserBundle does provide a command line tools which can be used to create, authorize (promote) and demote a user. Similar commands can be used within your app (outside of terminal) – Jovan Perovic Aug 20 '18 at 13:10
  • Please, can u explain me how 2 use it?=) Or may me provide documentation link or "Len me Google that for You" link?) – rib Aug 20 '18 at 13:13
  • You could also try this: https://symfony.com/doc/current/security/impersonating_user.html – Vyctorya Aug 20 '18 at 14:10

3 Answers3

1

Custom Commands for FOSUserBundle are

  fos:user:activate                                           
  fos:user:change-password                                    
  fos:user:create                                             
  fos:user:deactivate                                         
  fos:user:demote                                             
  fos:user:promote     

There is no such way to authorize directly as you want it.

You can create a custom command in symfony which accepts username and authenticates a user. Here is a way to create such a command : https://symfony.com/doc/current/console.html

1

Authorization in Symfony done Tokens. To be logged in Symfony's World you'll need to set a Token.

One of the common use cases is "auto login" right after registration.

Take a look at this article -> https://ourcodeworld.com/articles/read/459/how-to-authenticate-login-manually-an-user-in-a-controller-with-or-without-fosuserbundle-on-symfony-3

especially for that part

$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);

BUT also take a look at symfony's impersonalizaiton => https://symfony.com/doc/current/security/impersonating_user.html

It basically allows you to switch users without filling out forms and knowing users' credentials

V-Light
  • 3,065
  • 3
  • 25
  • 31
0

Thanks you, guys! I found the solution here!
How to programmatically login/authenticate a user?
Sorry for wrong or stupid question.

rib
  • 94
  • 6