我正在使用JWT Web令牌系統。我成功地生成了TOKENS。 我在Laravel創建JWT令牌如下是Jwt token was UNIQUE
我正在使用FOLLOWING技術堆棧
- LARAVEL 5.2框架
- JWT (package)
樣品編號
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
class AuthenticateController extends Controller
{
public function authenticate(Request $request)
{
// grab credentials from the request
$credentials = $request->only('email', 'password');
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
}
樣本輸出
我越來越
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ
問題1
是生成的令牌 是獨特的?
JWT令牌如何是獨一無二的,即同樣的道理,在什麼參數令牌是獨一無二的(無論其因頭或載荷或簽名) ? – lakshmaji
標頭有效負載和簽名一起構成一個令牌。如果有人發現整個令牌的一部分,你就沒有真正的安全問題。但標題是一樣的,另外兩個改變。檢查[鏈接](https://jwt.io/)並嘗試更改值並查看會發生什麼 – Norgul
如何讓用戶令牌在成功登錄和註銷之間有效? – lakshmaji