[New in Symfony 3.4] Stateless User Impersonation

I’m always grateful to receive feedback.

Things that might seem obvious to you may have completely bypassed me altogether. Some of the forthcoming site improvements would honestly have never even made my radar if I hadn’t been told so by your feedback.

Sometimes though, I get feedback that throws me.

Earlier this week I got an email from a site visitor saying there are too many long courses on the site, and it’s hard to find the time to follow along with each course.

It was suggested that focusing on specific concepts would be preferable to the vast majority of people.

Now, I admit to having taken guesses at the answer to questions like this in the past.

And the problem with guessing is that I’m often wrong. Fortunately, I’ve learned (the hard way) that it’s simply better to ask.

Yesterday (thinking it was Wednesday), I sent out a 1 question survey to see what others thought about this.

The answers are as above.

Now, the “other (please specify)” drew in some extra interesting feedback, so thank you to those who added answers in this field. Mostly, these were requests for Symfony 4 content 🙂 There were two other requests which have been added to the list also.

Anyway, I found the answers interesting. My personal preference is for longer tutorials, with shorter ones every now and again. It seems that’s roughly in line with the feedback, so that was good to learn.

Video Update

This week saw four new videos added to the site.

All four videos come under one short course:

Stateless User Impersonation

This is a new feature coming in Symfony 3.4 that, if you’re using Symfony as a JSON API, will make one small part of your day-to-day admin burden that little bit easier.

(who am I kidding, I only recorded this series as I wanted to use this as a course cover image :))

#1 – Tutorial Setup – Getting Docker Up and Running

Docker is great. It’s allowing me to cover bigger project setups in shorter video series.

It’s not so great as, despite all its good intentions, the process of using Docker is different on Linux to how it is on a Mac. I haven’t used Docker on Windows, but I dare say the process is different there, too.

The big problem is permissions. I keep harping on about Docker permissions because they give me 95% of headaches in my usage of Docker.

This video aims to get you a working stack with the right permissions.

If you are already a Docker user, you can likely skim, or entirely skip this video.

#2 – Impersonating Users on a JSON API (WIthout FOS User Bundle)

Up until Symfony 3.4, if you wanted to impersonate a User when using stateless authentication (think: LexikJWTAuthenticationBundle), then you had to use a third party bundle to enable this functionality.

Unfortunately, it looks like support around this bundle is lacking.

Robin Chalas (chalasr) put in a change (which subsequently got merged) to add this functionality directly into Symfony.

So, now we get it for free. Well, so long as you are using Symfony 3.4 onwards.

Note that at the time of writing, Symfony 3.4 is still in Beta.

#3 – Impersonating Users on a JSON API (WIth FOS User Bundle)

Whatever I do here on CodeReviewVideos, I more likely than not get asked the question:

Yes, but how can I do {insert anything} with FOSUserBundle?

There’s no magic to FOSUserBundle. It doesn’t change the way your Symfony application works. But I understand why people ask this question.

Anyway, I get asked this so much that I have preemptively covered how to do stateless user impersonation with FOS User Bundle to save both of us the trouble 🙂

Honestly, it’s 99% the same as what we covered in the previous video. Only this time, with 100% more Friends of Symfony.

#4 – Digging A Little Deeper

To round up this short series we go a little more in-depth as to why this setup works.

We examine what the outcome of both $this->getUser()  and the outcome of injecting a $user  object directly into our controller actions.

More specifically, we cover how each of these differ, or stay the same, when working with stateless user impersonation.

What’s Next?

I keep getting requests to cover deployment. I’ve had some interesting deployment setups requested, and plan to cover these, too.

I started recording this series about 3 weeks ago. And then Symfony 4 started looming.

I then got hesitant:

Should I record a bunch of videos for deploying Symfony 3.x and Symfony 2.x, only to have Symfony 4.x drop, and make all of the newly recorded content almost immediately obsolete?

Well, then today I saw sense:

I will cover deploying with both. The Symfony 4 content will be added at a later date, and in the interim I will upload what I’ve already recorded.

Right now this is mainly Symfony with Apache, and Symfony with nginx. There’s a bit more too it than this, but that’s the gist.

Ok, that’s it from me. As ever, have a great weekend, and happy coding.

Chris

Published by

Code Review

CodeReviewVideos is a video training site helping software developers learn Symfony faster and easier.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.