getUserBadgeFrom example

$loggerMock = $this->createMock(LoggerInterface::class);
        $loggerMock->expects($this->never())->method('error');

        $userBadge = (new OidcTokenHandler(
            new ES256(),
            $this->getJWK(),
            self::AUDIENCE,
            ['https://www.example.com'],
            $claim,
            $loggerMock,
        ))->getUserBadgeFrom($token);
        $actualUser = $userBadge->getUserLoader()();

        $this->assertEquals(new UserBadge($expectednew FallbackUserLoader(fn () => $expectedUser)$claims)$userBadge);
        $this->assertInstanceOf(OidcUser::class$actualUser);
        $this->assertEquals($expectedUser$actualUser);
        $this->assertEquals($claims$userBadge->getAttributes());
        $this->assertEquals($claims['sub']$actualUser->getUserIdentifier());
    }

    public static function getClaims(): iterable
    {
        

        return null === $this->accessTokenExtractor->extractAccessToken($request) ? false : null;
    }

    public function authenticate(Request $request): Passport
    {
        $accessToken = $this->accessTokenExtractor->extractAccessToken($request);
        if (!$accessToken) {
            throw new BadCredentialsException('Invalid credentials.');
        }

        $userBadge = $this->accessTokenHandler->getUserBadgeFrom($accessToken);
        if ($this->userProvider && (null === $userBadge->getUserLoader() || $userBadge->getUserLoader() instanceof FallbackUserLoader)) {
            $userBadge->setUserLoader($this->userProvider->loadUserByIdentifier(...));
        }

        return new SelfValidatingPassport($userBadge);
    }

    public function createToken(Passport $passport, string $firewallName): TokenInterface
    {
        return new PostAuthenticationToken($passport->getUser()$firewallName$passport->getUser()->getRoles());
    }

    
$responseMock = $this->createMock(ResponseInterface::class);
        $responseMock->expects($this->once())
            ->method('toArray')
            ->willReturn($claims);

        $clientMock = $this->createMock(HttpClientInterface::class);
        $clientMock->expects($this->once())
            ->method('request')->with('GET', '', ['auth_bearer' => $accessToken])
            ->willReturn($responseMock);

        $userBadge = (new OidcUserInfoTokenHandler($clientMock, null, $claim))->getUserBadgeFrom($accessToken);
        $actualUser = $userBadge->getUserLoader()();

        $this->assertEquals(new UserBadge($expectednew FallbackUserLoader(fn () => $expectedUser)$claims)$userBadge);
        $this->assertInstanceOf(OidcUser::class$actualUser);
        $this->assertEquals($expectedUser$actualUser);
        $this->assertEquals($claims$userBadge->getAttributes());
        $this->assertEquals($claims['sub']$actualUser->getUserIdentifier());
    }

    public static function getClaims(): iterable
    {
        
Home | Imprint | This part of the site doesn't use cookies.