本文整理汇总了PHP中Illuminate\Http\Request::header方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::header方法的具体用法?PHP Request::header怎么用?PHP Request::header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: facebook
public function facebook(Request $request)
{
$accessTokenUrl = 'https://graph.facebook.com/v2.5/oauth/access_token';
$graphApiUrl = 'https://graph.facebook.com/v2.5/me';
$params = ['code' => $request->input('code'), 'client_id' => $request->input('clientId'), 'redirect_uri' => $request->input('redirectUri'), 'client_secret' => '76cd1014c10586c33f3e13f03929a221'];
$client = new \GuzzleHttp\Client();
// Step 1. Exchange authorization code for access token.
$accessToken = json_decode($client->get($accessTokenUrl, ['query' => $params])->getBody(), true);
// Step 2. Retrieve profile information about the current user.
$profile = json_decode($client->get($graphApiUrl, ['query' => $accessToken])->getBody(), true);
// Step 3a. If user is already signed in then link accounts.
if ($request->header('Authorization')) {
$user = User::where('facebook', '=', $profile['id']);
if ($user->first()) {
return response()->json(['message' => 'There is already a Facebook account that belongs to you'], 409);
}
$token = explode(' ', $request->header('Authorization'))[1];
$payload = (array) JWT::decode($token, Config::get('jwt.secret'), array('HS256'));
$user = User::find($payload['sub']);
$user->facebook = $profile['id'];
$user->displayName = $user->displayName ?: $profile['name'];
$user->save();
return response()->json(['token' => $this->createToken($user)]);
} else {
$user = User::where('facebook', '=', $profile['id']);
if ($user->first()) {
return response()->json(['token' => $this->createToken($user->first())]);
}
$user = new User();
$user->facebook = $profile['id'];
$user->displayName = $profile['name'];
$user->save();
return response()->json(['token' => $this->createToken($user)]);
}
}
示例2: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$jwt = $request->header('x-auth-jwt');
$key = 'fad';
//env('JWT_KEY');
$decoded = JWT::decode($jwt, $key, array('HS256'));
/*
/*
NOTE: This will now be an object instead of an associative array. To get
an associative array, you will need to cast it as such:
*/
//$decoded_array = (array) $jwt;
/**
* You can add a leeway to account for when there is a clock skew times between
* the signing and verifying servers. It is recommended that this leeway should
* not be bigger than a few minutes.
*
* Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
*/
//JWT::$leeway = 60; // $leeway in seconds
//$decoded = JWT::decode($jwt, $key, array('HS256'));
return $next($request);
//$res = $next($request);
//echo "after http request!";
//return $res;
}
示例3: checkRequest
/**
* Check the request headers.
*
* @param Illuminate\Http\Request $request
* @return void
*/
protected function checkRequest(Request $request)
{
$this->checkAcceptHeader($request->header('accept'));
if (!in_array($request->method(), ['GET', 'OPTIONS'])) {
$this->checkContentTypeHeader($request->header('content-type'));
}
}
示例4: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$access_token = $request->header('access_token');
$refresh_token = $request->header('refresh_token');
if ($access_token == null && $refresh_token == null) {
return response('No Token', 400);
} else {
$verifyAccess = UserTokenModel::find($access_token);
$verifyRefresh = UserRefreshTokenModel::find($refresh_token);
$current_time = time();
// echo(strtotime($verifyAccess->expires)-$current_time .'<br>');
// echo($current_time);
// echo(((strtotime($verifyAccess->expires)-$current_time)<3600)."<br>");
// echo((strtotime($verifyRefresh->expires)-$current_time));
if (count($verifyAccess) > 0) {
if (strtotime($verifyAccess->expires) > $current_time) {
return $next($request);
} else {
return response()->json(['message' => 'Token expired'], 403);
}
} else {
return response()->json(['message' => 'Invalid token'], 403);
}
}
}
示例5: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$token = $request->header('access-token');
$token = isset($token) ? $request->header('access-token') : $request->get('api_token');
if (!$token) {
return response('Unauthorized.', 403);
}
$key = getenv('APP_KEY');
$signer = new Sha256();
$data = new ValidationData();
// It will use the current time to validate (iat, nbf and exp)
$data->setIssuer($request->server('REMOTE_ADDR'));
$data->setAudience($request->server('HTTP_HOST'));
try {
$token = (new Parser())->parse((string) $token);
if (!$token->validate($data)) {
return response('Unauthorized data', 401);
}
if (!$token->verify($signer, $key)) {
return response('Unauthorized sign', 401);
}
putenv("USER=" . $token->getClaim('uid'));
return $next($request);
} catch (\Exception $e) {
return response('Unauthorized: ' . $e->getMessage(), 403);
}
}
示例6: __construct
public function __construct(Request $request)
{
if (!$request->header('App-token')) {
exit;
}
$this->user_id = TokenService::tokenDecrypt($request->header('App-token'));
}
示例7: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->agent->isRobot() || $request->header('user-agent') == '' || !$request->header('user-agent')) {
return redirect($_SERVER['HTTP_REFERER']);
}
return $next($request);
}
示例8: getToken
/**
* Get OTP Session Token.
*
* @return string|exception
*/
protected function getToken()
{
if (!$this->request->hasHeader('X-OTP-SESSION-TOKEN')) {
throw new InvalidTwoFactorSessionToken();
}
return $this->request->header('X-OTP-SESSION-TOKEN');
}
示例9: saveFranchise
public function saveFranchise(Request $request)
{
/* $validator = Validator::make($request->all(), [
'jenis' => 'required|integer',
'namausaha' => 'required|unique:franchises',
'telepon' => 'required',
'alamat' => 'required|max:50'
]);
if ($validator->fails()) {
$message = $validator->errors();
return $this->httpUnprocessableEntity($message);
}
$jenis = $request->input('jenis');
$namausaha = $request->input('namausaha');
$telepon = $request->input('telepon');
$alamat = $request->input('alamat');
$image = $request->input('logo');
*/
$validator = Validator::make($request->all(), ['logo' => 'image|mimes:jpg,jpeg,png|max:2000']);
if ($validator->fails()) {
$message = $validator->errors();
return $this->httpUnprocessableEntity($message);
}
$jenis = $request->header('jenis');
$namausaha = $request->header('namausaha');
$telepon = $request->header('telepon');
$alamat = $request->header('alamat');
$image = $request->file('logo');
$cek = Jenis::where('id', $jenis)->first();
if (empty($cek)) {
return $this->httpUnprocessableEntity('Id jenis tidak valid');
}
$db = new Franchise();
$db->jenis = $jenis;
$db->namausaha = $namausaha;
$db->franchisor_id = $this->userID($request);
$franchisor = new Franchisor();
$franchisor->where('id', $this->userID($request))->update(['alamat' => $alamat, 'telepon' => $telepon]);
if ($image) {
//$image ='data:image/jpeg;base64,' .base64_encode($image);
/*header("Content-type: image/jpeg");
$image = Image::make($image);
$image = $image->response('jpg', 70);*/
$salt = hash('sha256', time() . mt_rand());
$link = substr($salt, 0, 40) . ".png";
$resizedImage = $this->resize($image, 500, 500, $link);
if (!$resizedImage) {
return response()->json(['status' => false, 'msg' => 'gagal'], 204);
}
$db->logo = $link;
$db->logo_url = url('api/logo/' . $link);
}
$db->logo = "avatar.png";
$db->logo_url = url('api/logo/avatar.png');
if ($db->save()) {
return $this->httpCreate();
}
return $this->httpServerError();
}
示例10: tokensMatch
/**
* Determine if the session and input CSRF tokens match.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function tokensMatch($request)
{
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
if (!$token && ($header = $request->header('X-XSRF-TOKEN'))) {
$token = $this->encrypter->decrypt($header);
}
return Str::equals($request->session()->token(), $token);
}
示例11: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->user->authenticateApiV1($request->header('Authorization')) !== false) {
$this->auth->loginUsingId($this->user->authenticateApiV1($request->header('Authorization')));
} else {
return response('Invalid API token.', 401);
}
return $next($request);
}
示例12: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!empty($request->header('credential'))) {
if (Credential::where('key', $request->header('credential'))->count() != 0) {
return $next($request);
}
}
$this->response->error('Not Valid Api Credential', 500);
}
示例13: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$cookieLang = Cookie::get('i18next');
if ($cookieLang) {
App::setLocale($cookieLang);
} elseif ($request->header('Accept-Language')) {
App::setLocale($request->header('Accept-Language'));
}
return $next($request);
}
示例14: validateRequest
public function validateRequest(Request $request)
{
if ($request->header('Accept') != JsonApi::MIME_TYPE) {
throw new \RuntimeException('Invalid Accept header.');
}
if (!empty($request->getContent()) && $request->header('Content-Type') != JsonApi::MIME_TYPE) {
throw new \RuntimeException('Invalid Content-Type header.');
}
return true;
}
示例15: create
/**
* Create a new controller instance.
*
* @return void
*/
public function create(Request $request)
{
$message['to'] = $request->input('to');
$message['from'] = $request->input('from');
$message['body'] = $request->input('body');
$message['accountSid'] = $request->header('X-TWILIO-ACCOUNT-SID');
$message['authToken'] = $request->header('X-TWILIO-AUTH-TOKEN');
$client = new \Services_Twilio($message['accountSid'], $message['authToken']);
$client->account->messages->create(['To' => $message['to'], 'From' => $message['from'], 'Body' => $message['body']]);
exit;
}