Symfony2 Authentication (Login) without Doctrine?

Asked
Active3 hr before
Viewed126 times

9 Answers

withoutauthenticationlogin
90%

Meta Stack Overflow ,As I implement an existing postgresql database and I want to re-use a lot of an already existing PHP code, ORM was not a fit in my case (too much timecost to do the reverse engineering). Hence I have been actively searching how to use Symfony without ORM. (I did implement DBAL because what I wrote for PDO works with it... so far ... with some minor fixes)., Stack Overflow Public questions & answers , Stack Overflow help chat

[projectname]\app\config\security.yml

encoders:
   CustomBundle\ Entity\ CustomUsers:
   algorithm: [enter an encoding algorithm, eg: MD5, sha512, etc.]

role_hierarchy:
   ROLE_NAME2: ROLE_NAME1
ROLE_NAME3: ROLE_NAME2

providers:
   custom_users_provider:
   id: custom_users_provider

firewalls:
   main_login:
   pattern: ^ /login$
anonymous: ~
   main:
   pattern: ^ /
anonymous: true
provider: custom_users_provider
form_login:
   check_path: /login_check
login_path: /login
provider: custom_users_provider
username_parameter: email
password_parameter: password

logout: true

access_control:
   -{
      path: ^ /login$, role: IS_AUTHENTICATED_ANONYMOUSLY } -
         {
            path: ^ /secured_for_role_name, role: ROLE_NAME }
load more v
88%

src: Contains all the Symfony-specific code (controllers and forms), your domain code (e.g., Doctrine classes) and all your business logic,Lastly, generate a new controller that will handle the login process for a user:,Another way to install Symfony is via Symfony installer. You simply need to run the following command:,Finally in this section, open the .env and include your Auth0 credentials as shown here:

To create our application for this tutorial, run the following command to create a new web application named top-tech-companies:

composer create - project symfony / website - skeleton top - tech - companies
load more v
72%

Learn More Authentication (Identifying/Logging in the User) Authorization (Denying Access) , Authentication (Identifying/Logging in the User) , Authorization (Denying Access) ,Enable remote user authentication using the remote_user key:

1
$ composer require symfony / security - bundle
load more v
65%

I am new @symfony and completely new in doctrine. The symfony page contains a tutorial on how to create an sf2 login process. And I love it BUT I can't work with doctrine and I don't want to work with it (there are many thinkers who don't work with doctrine ... - like enum's etc.).,At the beginning of this chapter, all authorization is done without Doctrine.,You still need to implement the Symfony Controller SecurityController (find it here: http://symfony.com/doc/2.0/book/security.html ) and its route to the / login and Twig file.,The Symfony documentation explains everything in the Security chapter. Security

[project_name] \ application \ Config \ security.yml

encoders:
   CustomBundle\ Entity\ CustomUsers:
   algorithm: [enter an encoding algorithm, eg: MD5, sha512, etc.]

role_hierarchy:
   ROLE_NAME2: ROLE_NAME1
ROLE_NAME3: ROLE_NAME2

providers:
   custom_users_provider:
   id: custom_users_provider

firewalls:
   main_login:
   pattern: ^ /login$
anonymous: ~
   main:
   pattern: ^ /
anonymous: true
provider: custom_users_provider
form_login:
   check_path: /login_check
login_path: /login
provider: custom_users_provider
username_parameter: email
password_parameter: password

logout: true

access_control:
   -{
      path: ^ /login$, role: IS_AUTHENTICATED_ANONYMOUSLY } -
         {
            path: ^ /secured_for_role_name, role: ROLE_NAME }

            (adsbygoogle = window.adsbygoogle || []).push({});
load more v
75%

when constructing the UserProviderInterface object is Symfony\Bridge\Doctrine\Security\User\EntityUserProvider (not UserProvider) I am not fully sure if this is correct or not. the thing is in the mefhod retrieveUser an exception is thrown by,I am not sure if this is ok. but the root cause of the issue rely on $userProvider in DaoAuthenticationProvider (Symfony\Component\Security\Core\Authentication\Provider),The Doctrine repository “Doctrine\ORM\EntityRepository” must implement UserProviderInterface.,How you solved the above problem of The Doctrine repository “Doctrine\ORM\EntityRepository” must implement UserProviderInterface. Can you please show any example

In project, I am using standard Symfony2 authentication mechanism. So, by default, I created entity User and added it to security.yml file like this:

    providers:
       main:
       entity: {
          class: Surgeworks\ CoreBundle\ Entity\ User,
          property: username
       }

    firewalls:
       login:
       pattern: ^ /admin/login$
    security: false

    secured_area:
       pattern: ^ /admin/
    form_login:
       check_path: /admin/login_check
    login_path: /admin/login
    always_use_default_target_path: true
    default_target_path: /admin/login_after
    logout:
       path: /admin/logout
    target: /admin/
    #anonymous: ~
       http_basic:
       realm: "Secured Admin Area"
load more v
40%

Make the login authentication: ,This will update the config/packages/security.yaml file by adding a logout route and create authenticator, controller and login form files.,We want to shorten that constructor in the EmailVerifier class and also add proper user roles after email verification: ,Select [1] Login form authenticator, call it LoginFormAuthenticator, confirm the controller name: SecurityController and accept adding the logout route.

composer create - project symfony / website - skeleton my_new_app
load more v
22%

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages. , Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages. ,Users can be stored via Doctrine ORM or MongoDB/CouchDB ODM,the EntityUserProvider of Symfony already provides the UserProvider when using the Doctrine ORM (and other object managers integrated with Symfony have an equivalent feature)

b48f820
load more v
60%

Symfony Flex requires you to explicitly install the Security bundle to use it in your application. Additionally, no matter what kind of authentication method you choose, you must create your User entity class, and it must implement UserInterface.,Modify the HomeController to implement the login and callback methods:,Create a new .env.local file inside the main project directory to store your local credentials and add the following values:,Test the new links and pages - the Login link is not yet functional, of course, and you will have free access to the ‘Personal’ page without authorization.

mysql - uroot - p
CREATE DATABASE symfony_auth CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL on symfony_auth.*to 'symfony_auth'
@ '127.0.0.1'
identified by 'symfony_auth';
quit
load more v
48%

Doctrine: The Doctrine ORM will help with managing the application database,In this article, I will show you how to implement Two-factor authentication in a Symfony application using the Authy app to add an extra level of authentication to the traditional login form.,two-factor authentication,In src/Security/LoginAuthenticator, update the onAuthenticationSuccess function to match the following

symfony new 2 - fa - demo
cd 2 - fa - demo
load more v

Other "without-authentication" queries related to "Symfony2 Authentication (Login) without Doctrine?"