33/* Define Namespace */
44namespace RestJS \PhpRestApi \View ;
55
6+ /* Head Allows Section */
7+ header ("Access-Control-Allow-Origin: * " );
8+ header ("Content-Type: application/json; charset=UTF-8 " );
9+ header ("Access-Control-Allow-Methods: POST, GET, PUT, DELETE " );
10+ header ("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With " );
11+
612class Auth {
713
814 public static function accessToken () {
915
10- /* Head Allows Section */
11- header ("Access-Control-Allow-Origin: * " );
12- header ("Content-Type: application/json; charset=UTF-8 " );
13- header ("Access-Control-Allow-Methods: POST, GET, PUT, DELETE " );
14- header ("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With " );
16+ /* Get Headers */
1517 $ headers = getallheaders ();
1618
1719 /* Check Access Token */
1820 if (isset ($ _GET ['access_token ' ])) {
1921
20- if ($ _GET ['access_token ' ] != ACCESS_TOKEN ) {
21- echo json_encode (array ( 'status ' => 'Fail ' , 'error ' => 'Please provide valid access token ' ) );
22+ if ($ _GET ['access_token ' ] != $ _ENV [ ' ACCESS_TOKEN ' ] ) {
23+ echo json_encode ([ 'status ' => 'Fail ' , 'error ' => 'Please provide valid access token ' ] );
2224 die ();
2325 }
2426 }
2527
26- /* Check Authorization */
27- else if (isset ($ headers ['Authorization ' ])) {
28+ /* Check Authorization */
29+ elseif (isset ($ headers ['Authorization ' ])) {
2830
29- if ($ headers ['Authorization ' ] != "Bearer " . ACCESS_TOKEN ) {
30- echo json_encode (array ( 'status ' => 'Fail ' , 'error ' => 'Please provide valid access token ' ) );
31+ if ($ headers ['Authorization ' ] != "Bearer " . $ _ENV [ ' ACCESS_TOKEN ' ] ) {
32+ echo json_encode ([ 'status ' => 'Fail ' , 'error ' => 'Please provide valid access token ' ] );
3133 die ();
3234 }
33- }
35+ }
3436 else {
35- echo json_encode (array ( 'status ' => 'Fail ' , 'error ' => 'Please provide access token ' ) );
37+ echo json_encode ([ 'status ' => 'Fail ' , 'error ' => 'Please provide access token ' ] );
3638 die ();
3739 }
3840 }
39- }
41+ }
0 commit comments