-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.php
55 lines (40 loc) · 1.24 KB
/
auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
header('Content-Type: application/json');
require_once ('vendor/autoload.php');
require_once ('utils.php');
use Firebase\JWT\JWT;
$method = strtoupper( $_SERVER['REQUEST_METHOD'] );
if ( $method === 'POST' ) {
$json = file_get_contents('php://input');
// $data=array(
// "usuario" => 'aordonez',
// "email" => 'amethgabriel@hotmail.com'
// );
if(empty($json)){
http_response_code(400);
exit("Autenticación incorrecta. Por favor verifique sus datos.");
}
if(json_decode($json) === null){
http_response_code(400);
exit("Autenticación incorrecta. Por favor verifique sus datos.");
}
$time = time();
$exp_time=$time + 60 * 60 * 24; //Expira en una dia
// echo $json;
$data = array(
'iat' => $time,
'exp' => $exp_time,
'data' => json_decode($json, true)
);
$token = JWT::encode($data,"Asdf1234$");
echo json_encode(array("jwt" => $token));
}elseif( $method === 'GET'){
try {
$jwt=utils::getBearerToken();
$decoded = JWT::decode($jwt, "Asdf1234$", ['HS256']);
echo json_encode($decoded);
} catch (Exception $e) {
echo json_encode($e->getMessage());
}
}
?>