Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Guard] Adding cutom role to the security token breaks authentication #36603

Copy link
Copy link
Closed
@alterphp

Description

@alterphp
Issue body actions

Symfony version(s) affected: 4.4

Description
I'm following Custom Authentication System with Guard to implement my own "switch user" feature (across different firewalls). Instead of extending AbstractGuardAuthenticator as described in the documentation, I use my own implementation of createAuthenticatedToken(UserInterface $user, $providerKey) method.

My goal is just to add a custom role in the generated PostAuthenticationGuardToken.

    /**
     * Shortcut to create a PostAuthenticationGuardToken for you, if you don't really
     * care about which authenticated token you're using.
     *
     * @param string $providerKey
     *
     * @return PostAuthenticationGuardToken
     */
    public function createAuthenticatedToken(UserInterface $user, $providerKey)
    {
        $roles = $user->getRoles();

        // Why adding any custom role breaks authentication ?
        $roles[] = 'ROLE_FOO';

        return new PostAuthenticationGuardToken($user, $providerKey, $roles);
    }

Adding the role in the code above breaks authentication. Adding the roles in the UserInterface::getRoles() method is OK...

Any idea of what is happening here ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.