について学ぶことができ、ここで使用JWTトークンベースの認証。 私はlaravel authをログイン用にカスタマイズして登録しました。ユーザー登録用のアクセストークンを作成するリクエストをサーバーに送信する方法を作成しました。 私はパスポートを設定して、トゥルーリアル。
protected function sendLoginResponse(Request $request)
{
isset($request->token) ? $token = $request->token : $token = null;//Check if login request contain token
$request->session()->regenerate();
$this->clearLoginAttempts($request);
return $this->authenticated($request, $this->guard()->user())
? $this->StatusCode($token,$this->credentials($request),$status=false) : $this->StatusCode($token,$this->credentials($request),$status=true);
}
そして、私はアクセストークンを要求し、JSONレスポンスとして送信するために、このメソッドを追加しました:: その後、AuthenticatesUsers.php
に私が変更したsendloginResponse
方法応答のようなレジスタのユーザーのための
public function StatusCode($token,$user,$status){
if($token != null && $token != ''){
return ($status == true) ? response()->json(GetToken($user),200) : response()->json(['Message' => 'Failed to log in'],403);
}
function GetToken($userobject)
{
$http = new Client;
$response = $http->post('http://localhost/iranAd/public/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => '1',
'client_secret' => 'xKqNbzcXyjySg20nVuVLw5nk5PAMhFQOQwRTeTjd',
'username' => $userobject['email'],
'password' => $userobject['password'],
'scope' => '',
],
]);
return json_decode((string) $response->getBody(), true);
}
function RefreshToken($token,$userobject)
{
$http = new Client;
$response = $http->post('http://localhost/iranAd/public/oauth/token', [
'form_params' => [
'grant_type' => 'refresh_token',
'refresh_token' => 'refresh_token',
'client_id' => '1',
'client_secret' => 'xKqNbzcXyjySg20nVuVLw5nk5PAMhFQOQwRTeTjd',
'username' => $userobject['email'],
'password' => $userobject['password'],
'scope' => '',
],
]);
return json_decode((string) $response->getBody(), true);
}
return ($status == true) ? response()->json(GetToken($user),200) : response()->json(['Message' => 'Failed to log in'],403);
}
同じ手順。
短縮形で見つけることができる、このいくつかの私は自分のソーシャルネットワークを経由して、私のユーザーに署名したい場合は? FacebookやGoogle Plusのような? JWTもそれを処理していますか? –