本文整理汇总了PHP中Illuminate\Http\Request::bearerToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::bearerToken方法的具体用法?PHP Request::bearerToken怎么用?PHP Request::bearerToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::bearerToken方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTokenForRequest
/**
* Get the token for the current request.
*
* @return string
*/
public function getTokenForRequest()
{
$token = $this->request->input($this->inputKey);
if (empty($token)) {
$token = $this->request->bearerToken();
}
return $token;
}
示例2: getTokenForRequest
/**
* Get the token for the current request.
*
* @return string
*/
protected function getTokenForRequest()
{
$token = $this->request->input($this->inputKey);
if (empty($token)) {
$token = $this->request->bearerToken();
}
if (empty($token)) {
$token = $this->request->getPassword();
}
return $token;
}
示例3: authenticate
public function authenticate(Request $request, Route $route)
{
if (!$request->bearerToken() || empty($request->bearerToken())) {
throw new UnauthorizedHttpException('The authentication header was missing or malformed');
}
list($public, $hashed) = explode('.', $request->bearerToken());
$key = APIKey::where('public', $public)->first();
if (!$key) {
throw new AccessDeniedHttpException('Invalid API Key.');
}
// Check for Resource Permissions
if (!empty($request->route()->getName())) {
if (!is_null($key->allowed_ips)) {
$inRange = false;
foreach (json_decode($key->allowed_ips) as $ip) {
if (Range::parse($ip)->contains(new IP($request->ip()))) {
$inRange = true;
break;
}
}
if (!$inRange) {
throw new AccessDeniedHttpException('This IP address <' . $request->ip() . '> does not have permission to use this API key.');
}
}
foreach (APIPermission::where('key_id', $key->id)->get() as &$row) {
if ($row->permission === '*' || $row->permission === $request->route()->getName()) {
$this->permissionAllowed = true;
continue;
}
}
if (!$this->permissionAllowed) {
throw new AccessDeniedHttpException('You do not have permission to access this resource.');
}
}
try {
$decrypted = Crypt::decrypt($key->secret);
} catch (\Illuminate\Contracts\Encryption\DecryptException $ex) {
throw new HttpException('There was an error while attempting to check your secret key.');
}
$this->url = urldecode($request->fullUrl());
if ($this->_generateHMAC($request->getContent(), $decrypted) !== base64_decode($hashed)) {
throw new BadRequestHttpException('The hashed body was not valid. Potential modification of contents in route.');
}
return true;
}
示例4: getTokenFromRequest
/**
* Get the token for the given request.
*
* @param Request $request
* @return Token|string
*/
protected function getTokenFromRequest(Request $request)
{
$bearer = $request->bearerToken();
// First we will check to see if the token is in the request input data or is a bearer
// token on the request. If it is, we will consider this the token, otherwise we'll
// look for the token in the cookies then attempt to validate that it is correct.
if ($token = $request->input('api_token', $bearer)) {
return $token;
}
if ($request->cookie('kodicms_token')) {
return $this->getTokenFromCookie($request);
}
}
示例5: getTokenForRequest
/**
* Get the token for the current request.
*
* @return \Lcobucci\JWT\Token
*/
protected function getTokenForRequest()
{
$token = $this->request->bearerToken();
if (empty($token)) {
return null;
}
try {
$token = (new Parser())->parse($token);
if (!$this->signer->verify($token)) {
return null;
}
} catch (InvalidArgumentException $e) {
return null;
}
return $token;
}
示例6: isAuthenticated
public function isAuthenticated(Request $request)
{
$token = $request->bearerToken();
if (null === $token) {
$token = $request->cookie(config('stormpath.web.accessTokenCookie.name'));
}
if ($token instanceof \Symfony\Component\HttpFoundation\Cookie) {
$token = $token->getValue();
}
try {
(new \Stormpath\Oauth\VerifyAccessToken(app('stormpath.application')))->verify($token);
return true;
} catch (\Exception $re) {
return false;
}
}
示例7: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if (!($token = $request->bearerToken())) {
throw new InvalidTokenAuthorizationHeader();
}
// Validate the vadility of the token
try {
$payload = $this->manager->setRefreshFlow($this->getRefreshFlow())->decode(new Token($token));
} catch (\Exception $e) {
throw new InvalidToken();
}
if (!$this->auth->onceUsingId($payload->get('sub'))) {
throw new InvalidUser();
}
return $next($request);
}
示例8: bearerToken
/**
* Get the bearer token from the request headers.
*
* @return string|null
* @static
*/
public static function bearerToken()
{
return \Illuminate\Http\Request::bearerToken();
}