vendor/codeages/web-lib/src/Auth/Authentication.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Codeages\Weblib\Auth;
use Codeages\Weblib\Error\ErrorCode;
class Authentication
{
/**
* @var KeyProvider
*/
protected $keyProvider;
/**
* @var TokenAlgoFactory
*/
protected $tokenFactory;
protected $tokenHeaderKey = 'Authorization';
public function __construct(KeyProvider $keyProvider, TokenAlgoFactory $tokenFactory = null, array $options = array())
{
$this->keyProvider = $keyProvider;
if (empty($tokenFactory)) {
$tokenFactory = new TokenAlgoFactory();
}
$this->tokenFactory = $tokenFactory;
if (isset($options['token_header_key'])) {
$this->tokenHeaderKey = $options['token_header_key'];
}
}
public function auth($request)
{
$header = $this->getTokenHeader($request);
$header = explode(' ', $header);
if (count($header) !== 2) {
throw new AuthException("Authorization header is invalid.", ErrorCode::INVALID_CREDENTIAL);
}
list($strategy, $token) = $header;
$strategy = $this->tokenFactory->factory($strategy);
$token = $strategy->parse($token);
$key = $this->keyProvider->get($token->keyId);
if (empty($key)) {
throw new AuthException("Key id is not exist.", ErrorCode::INVALID_CREDENTIAL);
}
if ($key->getLimitIps()) {
$ip = $this->getClientIp($request);
if (!in_array($ip, $key->getLimitIps())) {
throw new AuthException("Your ip `{$ip}` is not allowed.", ErrorCode::FORBIDDEN);
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。