|
|
@@ -86,49 +86,21 @@ class TestController extends Controller
|
|
|
|
|
|
public function test4()
|
|
|
{
|
|
|
- $user = User::query()->first();
|
|
|
+
|
|
|
+ $a = file_get_contents(base_path() . '/private.pem');
|
|
|
+ Cache::forever("privatekey",$a);
|
|
|
$b = file_get_contents(base_path() . '/public.pem');
|
|
|
- $decoded = JWT::decode("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJkYXRhIjp7ImZpZWxkMSI6MSwiZmllbGQyIjoic3RyaW5nIGRhdGEifSwiaXNzIjoiaHR0cDpcL1wvZXhhbXBsZS5vcmciLCJhdWQiOiJodHRwOlwvXC9leGFtcGxlLmNvbSIsImlhdCI6MTYyOTc3NDUxMywiZWF0IjoxNjI5NzgxNzEzfQ.Twl3_KPMLP4Pi4zaGZig8SKhE9M6nZlCI8bVifWjuYIWuqZtlujp35Zvv1oY0GnPIkUmq-PGJZLU96mmT-RTRDL-83sPF2l7PPTeriYMoiKP1r2rsI421BtrgLs0qP7QCPxH5BmHWXAVbwTtnwv8JagKzcZxkZJRH3Lj8blRapumnCk-tMfHz4xiXHIATfMS1I23vhJJLomC-KW4Ou3pjTu6X3HiiUGe9ZBGTu5mHfiKm25dxXO5Fm3JMg2-anLf_Gy6D6D7IQJ5pM5HFEN-HdD7FibeEMraMxbk5B_82L15OjhaoCV7b7ioXNSs2QAdlRfuRgx0XIE_toFwb_152a", $b, ['RS256']);
|
|
|
+ Cache::forever("publickey",$b);
|
|
|
$payload = [
|
|
|
'data' => ['field1' => 1, 'field2' => 'string data'],
|
|
|
"iss" => "http://example.org",
|
|
|
"aud" => "http://example.com",
|
|
|
"iat" => time(),
|
|
|
- "eat" => time() + 7200,
|
|
|
+ "eat" => time() + 172800,
|
|
|
];
|
|
|
- try {
|
|
|
- $token = JWT::encode($payload, $a, 'RS256');
|
|
|
- } catch (\Exception $e) {
|
|
|
- $this->error("HTTP:409,资源异常,无法反馈");
|
|
|
- }
|
|
|
- try {
|
|
|
- $a = file_get_contents("test");
|
|
|
- } catch (\Exception $e) {
|
|
|
- if (strpos($e->getMessage(), "No such file or directory") !== false) $this->error("HTTP:410,服务器异常,资源丢失");
|
|
|
- else $this->error("HTTP:403,访问某些资源失败");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $payload = [
|
|
|
-
|
|
|
- 'data' => ['field1' => 1, 'field2' => 'string data'],
|
|
|
-
|
|
|
- "iss" => "http://example.org",
|
|
|
-
|
|
|
- "aud" => "http://example.com",
|
|
|
-
|
|
|
- "iat" => time(),
|
|
|
-
|
|
|
- "eat" => time() + 7200,
|
|
|
-
|
|
|
- ];
|
|
|
-
|
|
|
- $token = JWT::encode($payload, $a, 'RS256');
|
|
|
-
|
|
|
+ $token = JWT::encode($payload, Cache::get("privatekey"), 'RS256');
|
|
|
echo "Token:\n" . print_r($token, true) . "\n";
|
|
|
-
|
|
|
- $decoded = JWT::decode($token, $b, ['RS256']);
|
|
|
-
|
|
|
+ $decoded = JWT::decode($token, Cache::get("publickey"), ['RS256']);
|
|
|
$decoded_array = (array)$decoded;
|
|
|
|
|
|
echo "Decoded:\n" . print_r($decoded_array, true) . "\n";
|