認証処理を一括して行います。

@param	array		$authenticate
@param	callback	$authorize
@return boolean
348902
public static function Auth () {
		if (static::IsInitial() || !static::Authorize($authorize, $authenticate)) {
			http_response_code(401);
			header(sprintf('WWW-Authenticate: %s %s', static::AUTH_TYPE, static::ImplodeAuthenticate($authenticate, true)));
			return false;
		}
		return true;
	}
805772
public function validateAccessToken($redirect = true)
    {
        $this->_do_not_redirect = !$redirect;
        $this->log('validateAccessToken()');

        //Check to see if token in session has expired
        if (!empty($this->_expires) && $this->_expires < time()) {
            $this->log('access token expired so reauthorize');

            if (strlen($this->_refresh_token) > 0) {
                //use a refresh token to get a new token
                return $this->requestAccessToken();
            }

            //Reauthorize
            $this->authorize($this->_scope);

            return false;
        }

        //Check for existing access token
        if (strlen($this->_access_token) > 0) {
            $this->log('has access token');

            return true;
        }

        //Reauthorize if no token was found
        if (strlen($this->_access_token) == 0) {
            $this->log('access token empty so authorize');

            //OAuth flows
            if ($this->isOauth1()) {
                //OAuth 1.0
                $this->log('authorizing with OAuth1.0a spec');

                //Request token and authorize app
                if (!isset($_GET['oauth_token']) && !isset($_GET['oauth_verifier'])) {
                    $this->log('initializing authorization');

                    //Request token
                    $this->requestToken();
                    //Authorize token
                    $this->authorize();

                    return false;
                }

                //Request access token
                if ($_GET['oauth_token'] != $_SESSION['oauth']['token']) {
                    unset($_SESSION['oauth']['token'], $_SESSION['oauth']['token_secret']);

                    return false;
                }

                $this->requestAccessToken();
                unset($_SESSION['oauth']['token'], $_SESSION['oauth']['token_secret']);

                return true;
            }

            //OAuth 2.0
            $this->log('authorizing with OAuth2 spec');

            //Authorize app
            if (!isset($_GET['state']) && !isset($_GET['code'])) {
                $this->authorize($this->_scope);

                return false;
            }

            if ($this->_debug) {
                $_SESSION['oauth']['debug']['received_state'] = $_GET['state'];
            }

            //Request an access token
            if ($_GET['state'] != $_SESSION['oauth']['state']) {
                unset($_SESSION['oauth']['state']);

                return false;
            }

            unset($_SESSION['oauth']['state']);
            $this->requestAccessToken('POST', array(), 'json');

            return true;
        }

        return false;
    }
251690
public function onAuthenticationSuccess(AuthenticationEvent $event)
    {
        /** @var \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token */
        $token = $event->getAuthenticationToken();

        $this->logger->info(
            sprintf(
                'Entity (%s) was successfully recognized.',
                $token->getUsername()
            )
        );
    }
120982
public function beginSession($callback, array $scope = [])
    {
        $requestUrl = $this->config['request_url'];

        if (0 < count($scope)) {
            $requestUrl .= ((false === strpos($requestUrl, '?')) ? '?' : '&') . 'scope=' . rawurlencode(implode(' ', $scope));
        }

        $response = $this->sendCustomOauthPostRequest(
            $requestUrl,
            [
                'callback' => $callback,
                'token' => null,
                'token_secret' => null,
            ]
        );

        parse_str($response->getBody(), $responseData);

        if (!isset($responseData['oauth_callback_confirmed'])) {
            throw new UnexpectedValueException('Oauth exchange is missing `oauth_callback_confirmed`.');
        } elseif (!isset($responseData['oauth_token'])) {
            throw new UnexpectedValueException('Oauth exchange is missing `oauth_token`.');
        } elseif (!isset($responseData['oauth_token_secret'])) {
            throw new UnexpectedValueException('Oauth exchange is missing `oauth_token_secret`.');
        }

        if ('true' !== $responseData['oauth_callback_confirmed']) {
            throw new UnexpectedValueException('Oauth exchange must have `oauth_callback_confirmed` as `true`.');
        }

        $this->authentication->getTokenStorage()->setRequestToken($responseData['oauth_token']);
        $this->authentication->getTokenStorage()->setRequestTokenSecret($responseData['oauth_token_secret']);

        $redirect = $this->config['authorize_url'];
        $redirect .= ((false === strpos($redirect, '?')) ? '?' : '&') . 'oauth_token=' . rawurlencode($this->authentication->getTokenStorage()->getRequestToken());

        return $redirect;
    }
864769
public function authenticate()
    {
        $result = call_user_func_array($this->_callback, $this->_params);
        if ( !($result instanceof Result)) {
            if ($result === true) {
                $result = new Result(Result::SUCCESS, $this->_identity);
            } else {
                $result = new Result(Result::FAILURE_CREDENTIAL_INVALID, $this->_identity);
            }
        }
        return $result;
    }
843643
public function authorize($callback_url=NULL){
		$url = 'https://www.dropbox.com/1/oauth/authorize';
		$params = array(
			'oauth_token' => $this->authToken,
			'locale ' => $this->f3->get('LANGUAGE'),
		);
		if($callback_url) $params['oauth_callback'] = $callback_url;
		$this->f3->reroute($url.'?'.http_build_query($params));
	}
577799
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        if (empty($this->secretKey) == false) {
            $captcha = $this->request->get('g-recaptcha-response');

            $reCaptcha = new ReCaptcha($this->secretKey);
            $response = $reCaptcha->verify($captcha, $this->request->getClientIp());

            if ($response->isSuccess() == false) {
                throw new AuthenticationException('Captcha not passed');
            }
        }

        try {
            $user = $userProvider->loadUserByUsername($token->getUsername());
        } catch (UsernameNotFoundException $e) {
            throw new AuthenticationException('Invalid username or password');
        }

        $passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());

        if ($passwordValid) {
            return new UsernamePasswordToken(
                $user,
                $user->getPassword(),
                $providerKey,
                $user->getRoles()
            );
        }

        throw new AuthenticationException('Invalid username or password');
    }
262849
public function authenticate($credentials, $remember = false, $login = true)
    {
        $response = $this->fireEvent('sentinel.authenticating', $credentials, true);

        if ($response === false) {
            return false;
        }

        if ($credentials instanceof UserInterface) {
            $user = $credentials;
        } else {
            $user = $this->users->findByCredentials($credentials);

            $valid = $user !== null ? $this->users->validateCredentials($user, $credentials) : false;

            if ($user === null || $valid === false) {
                $this->cycleCheckpoints('fail', $user, false);

                return false;
            }
        }

        if (! $this->cycleCheckpoints('login', $user)) {
            return false;
        }

        if ($login === true) {
            $method = $remember === true ? 'loginAndRemember' : 'login';

            if (! $user = $this->{$method}($user)) {
                return false;
            }
        }

        $this->fireEvent('sentinel.authenticated', $user);

        return $this->user = $user;
    }
301267
func (c *Connection) Authenticate() (err error) {
	c.authLock.Lock()
	defer c.authLock.Unlock()
	return c.authenticate()
}
564744
public function auth(callable $fn, $retried = false)
    {
        // 1. 获取Access token
        $token = $this->getAccessTokenByAuth();
        if (!$token) {
            $this->code = -1;
            $this->message = '很抱歉,网络繁忙,请再试一次';

            return false;
        }

        // 2. 调用接口,转换异常为错误信息
        try {
            /** @var Http $http */
            $http = $fn();
        } catch (\Exception $e) {
            $this->code = -abs($e->getCode());
            $this->message = $e->getMessage();

            $http = \Miaoxing\App\Callback\Http::$lastErrorHttp;
            if ($http) {
                $this->logApi($http);
            }

            return false;
        }

        // 3. 成功直接返回
        if (!$this->isError($http)) {
            $this->code = 1;
            $this->message = '操作成功';

            return $http;
        }

        // 4. 处理接口返回错误
        // 如果是Access token无效或过期,清除缓存数据,然后重试一次
        if ($http['errcode'] == 40001 || $http['errcode'] == 42001) {
            $this->removeAccessTokenByAuth();
            if (!$retried) {
                $this->statsD->increment('wechat.credentialInvalid');

                return $this->auth($fn, true);
            }
        }
        $credential = $this->cache->get($this->getAccessTokenCacheKey());

        return $this->prepareError($http, $credential);
    }
398797
public function addAuth(array $auth, $validate = false)
    {
        $response = $this->getUser()->post(
            'source/auth/add',
            array('id' => $this->getId(), 'auth' => $auth, 'validate' => $validate)
        );

        $this->auth = $response['auth'];
    }
1007813
public function authenticate($auth = null)
    {
        if ($auth !== null) {
            $this->auth = $auth;
        }

        return $this->auth;
    }
612445
@Override
    public boolean authenticate() {
        UndertowLogger.SECURITY_LOGGER.debugf("Attempting to authenticate %s, authentication required: %s", exchange.getRequestPath(), isAuthenticationRequired());
        if(authenticationState == AuthenticationState.ATTEMPTED || (authenticationState == AuthenticationState.CHALLENGE_SENT && !exchange.isResponseStarted())) {
            //we are re-attempted, so we just reset the state
            //see UNDERTOW-263
            authenticationState = AuthenticationState.NOT_ATTEMPTED;
        }
        return !authTransition();
    }
150182
function authenticate($username,$password,$prevent_rebind=false){
        if ($username==NULL || $password==NULL){ return (false); } //prevent null binding
        
        //bind as the user		
        $this->_bind = @ldap_bind($this->_conn,$username.$this->_account_suffix,$password);
        $this->_bind_paged = @ldap_bind($this->_conn_paged,$username.$this->_account_suffix,$password);
        if (!$this->_bind){ return (false); }
        
        //once we've checked their details, kick back into admin mode if we have it
        if ($this->_ad_username!=NULL && !$prevent_rebind){
            $this->_bind = @ldap_bind($this->_conn,$this->_ad_username.$this->_account_suffix,$this->_ad_password);
            $this->_bind_paged = @ldap_bind($this->_conn_paged,$this->_ad_username.$this->_account_suffix,$this->_ad_password);
            if (!$this->_bind){
                // Modified by SysCo/al
                $this->_error = TRUE;
                $this->_error_message = 'FATAL: AD rebind failed.';
                exit();
            } //this should never happen in theory
        }
        
        return (true);
    }
617046
protected function parseAuthorization($model, $authorize = [])
    {
        if (!empty($authorize)) {
            // We need to authorize this change

            if (is_string($authorize)) {
                // Only an ability name was given, so use $model
                $authorize = [$authorize, $model];
            }

            list($ability, $authorizeModel) = $authorize;

            $this->authorize($ability, $authorizeModel);
        }
    }
615167
function authorize($subject='',$ondeny=NULL) {
        $f3=\Base::instance();
        if (!$this->granted($route=$f3->VERB.' '.$f3->PATH,$subject) &&
            (!isset($ondeny) || FALSE===$f3->call($ondeny,array($route,$subject)))) {
            $f3->error($subject?403:401);
            return FALSE;
        }
        return TRUE;
    }
1097732
public function authenticate(Request $request)
    {
        $this->checkForToken($request);

        try {
            if (! $this->auth->parseToken()->authenticate()) {
                throw new UnauthorizedHttpException('jwTauth', 'User not found');
            }
        } catch (JwTException $e) {
            throw new UnauthorizedHttpException('jwTauth', $e->getMessage(), $e, $e->getCode());
        }
    }