vendor/bshaffer/oauth2-server-bundle/OAuth2/ServerBundle/Storage/UserCredentials.php

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace OAuth2\ServerBundle\Storage;

use OAuth2\Storage\UserCredentialsInterface;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use OAuth2\ServerBundle\User\OAuth2UserInterface;
use OAuth2\ServerBundle\User\AdvancedOAuth2UserInterface;

class UserCredentials implements UserCredentialsInterface
{
    private $em;
    private $up;
    private $encoderFactory;

    public function __construct(EntityManager $entityManager, UserProviderInterface $userProvider, EncoderFactoryInterface $encoderFactory)
    {
        $this->em = $entityManager;
        $this->up = $userProvider;
        $this->encoderFactory = $encoderFactory;
    }

    /**
     * Grant access tokens for basic user credentials.
     *
     * Check the supplied username and password for validity.
     *
     * You can also use the $client_id param to do any checks required based
     * on a client, if you need that.
     *
     * Required for OAuth2::GRANT_TYPE_USER_CREDENTIALS.
     *
     * @param $username
     * Username to be check with.
     * @param $password
     * Password to be check with.
     *
     * @return
     * TRUE if the username and password are valid, and FALSE if it isn't.
     * Moreover, if the username and password are valid, and you want to
     *
     * @see http://tools.ietf.org/html/rfc6749#section-4.3
     *
     * @ingroup oauth2_section_4
     */
    public function checkUserCredentials($username, $password)
    {
        // Load user by username
        try {
            $user = $this->up->loadUserByUsername($username);
        } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
            return false;
        }

        // Do extra checks if implementing the AdvancedUserInterface
        if ($user instanceof AdvancedUserInterface) {
            if ($user->isAccountNonExpired() === false) return false;

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。