hslavich / OneloginSamlBundle

OneLogin SAML Bundle for Symfony
MIT License
149 stars 94 forks source link

I get atributes form IdP, but still redirect #195

Closed mariosiska closed 2 years ago

mariosiska commented 2 years ago

Hi, I go by description, I did create own User Factory that implements SamlUserFactoryInterface. In method createUser, I dump user, and I see him with all attributes that i get from IdP. But I am still (infinity) redirect to IdP. Symfony 5.3. Pls help.

SamlUserCreator.php:

namespace App\Security;
use App\Entity\User;
use Hslavich\OneloginSamlBundle\Security\Authentication\Token\SamlTokenInterface;
use Hslavich\OneloginSamlBundle\Security\User\SamlUserFactoryInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class SAMLUserCreator implements SamlUserFactoryInterface
{
    public function createUser($username, array $attributes = []): UserInterface
    {
        if (is_string($username)) {
            $idpAttributes = $attributes;
        } else {
            $idpAttributes = $username->getAttributes();
        }
        $user = new User();
        $user->setRoles(unserialize($idpAttributes["roles"][0]));
        $user->setId($idpAttributes["id"][0]);
        $user->setUsername($idpAttributes["name"][0]);
        $user->setSurname($idpAttributes["surname"][0]);
        $user->setEmail($idpAttributes["email"][0]);
        $user->setPassword($idpAttributes["password"][0]);
        //var_dump($user); die(); - when dump is disabled, still redirecting
        return $user;
    }
}

security.yaml:

providers:
        saml_provider:
              entity:
                  class: 'App\Entity\User'
                  property: 'username'
    firewalls:
        default:
            provider: saml_provider
            saml:
                username_attribute: username
                use_attribute_friendly_name: false
                user_factory: saml_user_factory
            logout:
                path: saml_logout
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

services.yaml

    saml_user_factory:
        class: App\Security\SAMLUserCreator
mariosiska commented 2 years ago

Hi, I did fix it. It was my bug. It crashed on isEqualTo method in user class. I make own isEqualTo method with own conditions, and seems it works now.