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.

7
  • So, existing FOS users are supplied from the DB, where are but those "custom" supplied from? Commented Aug 20, 2018 at 13:03
  • I mean, is there any way to authorize user programmly from entity object? Somthing like "Authurizer::authorize($userEntity)" Commented Aug 20, 2018 at 13:06
  • What do you mean you want to authorize without any forms, tokens, etc.? How do you know which user to authenticate? Commented Aug 20, 2018 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) Commented Aug 20, 2018 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) Commented Aug 20, 2018 at 13:10

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.