Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JWT Creator service #15

Merged
merged 2 commits into from
Jul 11, 2014
Merged

Added JWT Creator service #15

merged 2 commits into from
Jul 11, 2014

Conversation

gfreeau
Copy link
Contributor

@gfreeau gfreeau commented Jul 11, 2014

I have split out the code that creates a JWT from the authentication success handler.

This is really important in my application for two reasons.

It allows you to easily customize the payload, for example:

use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;

class JWTCreatedListener
{
    public function onJWTCreated(JWTCreatedEvent $event)
    {
        $payload = $event->getData();

        $payload['ip'] = $_SERVER['REMOTE_ADDR'];

        $event->setData($payload);
    }
}

Shows a quick example to add an IP address to the payload.

Secondly, it allows you to create a JWT in other parts of the application.

In my angularjs app, I need the ability to refresh the token. By having a separate JWT creation service, I can create a JWT for a user very easily in other parts of the application.

@slashfan
Copy link
Contributor

Great ! I was thinking about moving the jwt creation out of the handler, thanks !

slashfan added a commit that referenced this pull request Jul 11, 2014
Added JWT Creator service
@slashfan slashfan merged commit 2e50b09 into lexik:master Jul 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants