FOSUserBundle
…method for installing bundles.
Generating the User Entity¶
Let’s forget about security for a second and pretend that all we care about
is creating a User entity that is stored in the database. Let’s create
a new bundle called UserBundle to house the…
Creating & Mapping Layouts
…barkbite.com, password woof.
And when we submit... access denied! No worries: click down on the web debug
toolbar's security icon... and go to "Access Decision". Yup: we were denied access
because it was looking for a role called ROLE_NGLAYOUTS_ADMIN. To access…
Migrate Password Hashing
…what's actually stored on this field is a "hash" or kind of "fingerprint"
of the plaintext password and there are multiple hashing algorithms available.
The one you're using is configured in config/packages/security.yaml:
The encoders section says that whenever we encode…
The EnclosureBuilderService
…vendor/bin/phpspec run
Booya!
New plan time team! Let's add a method to the service where we can pass it
the number of dinosaurs we want, how much security we want, and... it will take
care of the rest! Let's examplify that…
Services, Autowiring & Pushing To GitHub
…
Inside SecurityBundle, look at DependencyInjection and open SecurityExtension.php.
This class loads several XML files that provide all of the services for this bundle.
Inside the Resources/config/ directory, open security.xml. Around line 136...
yep! You'll see the services that our new service…
Symfony's Branching Strategy & Pull Requests
…more level of difficulty: it's time to contribute new
code with a pull request. Let's look at an issue I found:
#27835.
This comes from the Security component. Let me give you some background: if you try
to access a protected page as…
Autowiring Deprecations
…supported in version 4.0. You should rename or
alias security.user_password_encoder.generic to ... long class name...
UserPasswordEncoder instead.
Um... what?????
This is saying that somewhere, we are type-hinting an argument with
Symfony\Component\Security\Core\Encoder\UserPasswordEncoder... but there is no…
Multiple Entries / Pages
…login
page... which has just a little bit of its own JavaScript: a toggleable message
and an error if you get crazy and type a super-long username.
Open up the template: app/Resources/FOSUserBundle/views/Security/login.html.twig.
Yep, it has a script…
Dependency Injection Extensions
…I just make something up, like journey and put a
dino_count of 10 under it:
When we refresh, we get a huge error!
And it says it found valid namespaces for framework, security, twig,
monolog, blah blah blah. Hey, those are the root keys…
Upgrading & What's New in Symfony 5!
…secrets management
Auto-validation
The new PHP 7.4 "preload" file
Using "migrate_from" to migrate your hashed passwords for max security
bin/console lint:container
And these are just my favorite features (see Symfony.com 4.4/5.0 Features Blog for even more…
FOSUserBundle FTW!
…you'll learn how to:
Install & setup FOSUserBundle
Understanding and configuring security
Using your own base layout
Overriding templates
Customizing and extending the forms
Removing the username field entirely
Updating any text via translations
Creating an event subscriber to do things before/after registration (or…
RESTful APIs in the Real World Course 2
…we're attacking the hard
stuff:
Using a serializer
Token Authentication System (Silex's security system)
Hypermedia versus media
The HAL hypermedia type
The HATEOAS PHP library
The HAL Browser
Embedding resources (versus adding links)
Tricks with Behat for testing API's
Pagination and filtering…
FOSUserBundle FTW! (v1.3)
…bundle, and with good reason.
It comes packed with features for login, registration, forgot password
and a lot more. But it's also a big tool, and learning to master it will
go a long way to making the security system in your application great.
Maker Bundle: Let's Generate Some Code!
…I'll start running symfony console, which is the same thing. Thanks
to the new bundle, we have a ton of commands that start with make! Commands for
generating a security system, making a controller, generating doctrine entities to
talk to the database, forms, listeners…
Creating the User Class
…double-check our user was added correctly, run:
symfony console dbal:run-sql 'select * from user'
Nice, here he is! But hmm... we have a serious security issue here... don't worry, we'll fix it soon... but
can you guess what it is?
Next…
app.user and Login/Logout Links
…accepts a $key
parameter, which is the firewall key defined in config/packages/security.yaml under the firewalls section.
Passing a key allows generating logout links for different firewalls.
There's another common method to check if a user is logged in. Our users have…
Protecting Logout with CSRF
…request, doesn't mean other sites can't
trigger it. To completely prevent this, we need to implement CSRF protection for it.
Open config/packages/security.yaml. Under the main firewall section, find the logout key.
Add enable_csrf: true:
Let's try it out…
Enabling "Remember Me" Feature
…tweak this cookie to your liking. To see the options,
run the following in your terminal:
symfony console config:dump framework session
Remember, the session isn't security-specific, that's why it's configured at
the framework level.
Here, you can see that we…
Admin Dashboard
…you want to, instead of using the IsGranted PHP attribute, you
could also say $this->denyAccessUnlessGranted(). And you could also go to
config/packages/security.yaml and, down at the bottom, add an access_control
that protects the entire /admin section:
Actually, adding this access…
API Tokens? Session Cookies?
…how the end-user will get that token.
So let's talk about that first use-case: the user of your API is your own JavaScript.
Well, before we even dive into security, make sure your frontend and your API live
on the same domain..…
x
1000+