1000 search results

Decorating the Core State Provider

…Shazam! We're green! So let's go set that value for real. This is easy enough: add a private Security argument... and make sure you first arg has a comma. Then this is true if $this->security->getUser() equals $treasure->getOwner(). And... then... the…

4:47
Tailwind CSS

…on a Mac. Run: open bin/tailwindcss If this is the first time you've downloaded the file, it will ask you to verify that you do want to open it from a security standpoint. Okay! We now have the bin/tailwindcss executable, which does…

5:47
Normalizer Decoration & "Normalizer Aware"

…we want to add the owner:read group. On the constructor, autowire the Security service as a property: Then, down here, if $object is an instanceof DragonTreasure - because this method will be called for all of our API resource classes - and $this->security->getUser() equals…

6:29
Auto Setting the "owner"

…chain of decorated services. Ok, let's get to work setting the owner. Autowire our favorite Security service so we can figure out who is logged in: Then, before we do the saving, if $data is an instanceof DragonTreasure and $data->getOwner() is null and…

4:19
Global From (and Fun) with Email Events

…But that won't work, as we're not authorized to send emails on behalf of that user. More on email security soon. Fortunately, there's a special email header called Reply-To for just this scenario. When building your email, set it with ->replyTo…

4:06
Simpler State Processor

…but not normal users. Add treasure:write. That means anyone with access to the Patch operation can write to this field... which in reality, thanks to the security on that operation... and a custom voter we created... is just admin users and the owner. Try…

5:47
Entities, DTO's & The "Central" Object

…item, that central object is that single item. And that's really important. It's used in various places, like the security attribute: when we use is_granted, the object variable will be that "central" object. For example, if we make a Patch() request, that…

6:24
2 Factor Authentication & Authentication Tokens

…Step 4 is to configure the firewall. This part we do need to do. Start by copying the two_factor stuff. Then open up config/packages/security.yaml. This new config can live anywhere under our main firewall. I'll paste it after form_login…

8:33
Customize Error Messages & Adding Logout

security.yaml. Anywhere under our firewall, add logout: true: Internally, this activates a "listener" that looks for any requests to /logout. And actually, instead of just saying logout: true, you can customize how this works. Find your terminal and run: symfony console debug:config security

7:33
Complex Symfony2 Examples: Users, Menus, CMS Features

…Depending on your preference, you will probably either use the popular FOSUserBundle or implement this yourself by following our How to load Security Users from the Database cookbook entry. In either case, creating a system with “groups” and “permissions” is very possible, where a user…

12:41:14
Hello Layouts+ Setup!

…inspire people to be the best chefs they can be... for their dogs. This is a pretty traditional Symfony app with a few controllers and some Twig templates. It also has two entities: A User entity for security, and a Recipe entity. On the site…

7:30
Custom Stimulus JavaScript Controller

…file for the frontend. This means that users that visit our frontend are downloading snarkdown_controller and snarkdown itself. That's probably not a security problem... but it is wasteful and will slow down the frontend experience. My favorite way to fix this is to…

6:20
QR Data & Scanning with an Authenticator App

…this isTotpAuthenticationEnabled() method returned true. Second, the security "token" - that internal thing that wraps your User object when you log in - well, it matches one of the tokens in our configuration. Specifically, we get the UsernamePasswordToken when we log in via the form_login mechanism…

4:35
Activating 2FA

…and hit tab to get the use statement on top: For the most part, I've been using IS_AUTHENTICATED_REMEMBERED for security... so that you just need to be logged in... even if it’s via a "remember me" cookie. But I'm using…

5:34
Manual Authentication

…really easy. We could just autowire the LoginFormAuthenticator service up here and pass it in. But, in our security.yaml file, our main way of authenticating is form_login: That does activate an authenticator service behind the scenes - just like our custom LoginFormAuthenticator. The tricky…

6:12
Hashing Plain Passwords & PasswordCredentials

…in the database. I love that. This is all possible thanks to a powerful event listener system inside of security. Let's learn more about that next and see how we can leverage it to add CSRF protection to our login form... with about two…

4:22
Rendering the QR Code

…after the user enables two-factor authentication, let's render a template with an image to this URL. Return $this->render('security/enable2fa.html.twig'). Copy the template name, head into templates/security, and create that: enable2fa.html.twig. I'll paste in a basic…

6:13
Custom Redirect when "Email Not Verified"

…it in action. To start, we need to create a custom authentication exception class. This will serve as the "signal" that we're in this "account not verified" situation. In the Security/ directory, add a new class: how about AccountNotVerifiedAuthenticationException. Make it extend AuthenticationException. And…

7:16
The Entry Point: Inviting Users to Log In

…none of our authenticators provide an entry point... so let's add one! Open up our authenticator: src/Security/LoginFormAuthenticator.php. If you want your authenticator to provide an entry point, all you need to do is implement a new interface: AuthenticationEntryPointInterface: This requires the…

6:45
Giving Users Passwords

…and we're implementing PasswordAuthenticatedUserInterface, I'm going to remove this comment above the method: Ok, let's forget about security for a minute. Instead, focus on the fact that we need to be able to store a unique password for each user in the…

5:26