77
88namespace tenup \Maps_Block_Apple ;
99
10- use \ WP_Error as WP_Error ;
11- use \ WP_REST_Response as WP_REST_Response ;
10+ use WP_Error ;
11+ use WP_REST_Response ;
1212use function tenup \Maps_Block_Apple \Settings \get_setting ;
1313
1414define ( 'MAPS_BLOCK_APPLE_VERSION_REST_NAMESPACE ' , 'MapsBlockApple/v1 ' );
@@ -23,11 +23,11 @@ function add_endpoints() {
2323 register_rest_route (
2424 MAPS_BLOCK_APPLE_VERSION_REST_NAMESPACE ,
2525 '/GetJWT ' ,
26- [
26+ array (
2727 'methods ' => 'GET ' ,
2828 'callback ' => __NAMESPACE__ . '\get_jwt ' ,
2929 'permission_callback ' => '__return_true ' ,
30- ]
30+ )
3131 );
3232}
3333
@@ -55,39 +55,39 @@ function get_jwt() {
5555 $ team_id = get_setting ( 'team_id ' );
5656
5757 if ( ! isset ( $ private_key ) || '' === $ private_key ) {
58- return new WP_Error ( 'NoKey ' , 'Missing Private Key ' , [ 'status ' => 401 ] );
58+ return new WP_Error ( 'NoKey ' , 'Missing Private Key ' , array ( 'status ' => 401 ) );
5959 }
6060 if ( ! isset ( $ key_id ) || '' === $ key_id ) {
61- return new WP_Error ( 'NoKey ' , 'Missing Key ID ' , [ 'status ' => 401 ] );
61+ return new WP_Error ( 'NoKey ' , 'Missing Key ID ' , array ( 'status ' => 401 ) );
6262 }
6363 if ( ! isset ( $ team_id ) || '' === $ team_id ) {
64- return new WP_Error ( 'NoKey ' , 'Missing Team ID ' , [ 'status ' => 401 ] );
64+ return new WP_Error ( 'NoKey ' , 'Missing Team ID ' , array ( 'status ' => 401 ) );
6565 }
6666 if ( 10 !== strlen ( $ key_id ) ) {
67- return new WP_Error ( 'InvalidKey ' , 'Invalid Key ID ' , [ 'status ' => 401 ] );
67+ return new WP_Error ( 'InvalidKey ' , 'Invalid Key ID ' , array ( 'status ' => 401 ) );
6868 }
6969 if ( 10 !== strlen ( $ team_id ) ) {
70- return new WP_Error ( 'InvalidKey ' , 'Invalid Team ID ' , [ 'status ' => 401 ] );
70+ return new WP_Error ( 'InvalidKey ' , 'Invalid Team ID ' , array ( 'status ' => 401 ) );
7171 }
7272 if (
7373 0 !== strpos ( $ private_key , '-----BEGIN PRIVATE KEY----- ' )
7474 && ! strpos ( $ private_key , '-----END PRIVATE KEY----- ' )
7575 ) {
76- return new WP_Error ( 'InvalidKey ' , 'Invalid Private Key ' , [ 'status ' => 401 ] );
76+ return new WP_Error ( 'InvalidKey ' , 'Invalid Private Key ' , array ( 'status ' => 401 ) );
7777 }
7878
79- $ header = [
79+ $ header = array (
8080 'alg ' => 'ES256 ' ,
8181 'typ ' => 'JWT ' ,
8282 'kid ' => $ key_id ,
83- ] ;
83+ ) ;
8484
85- $ body = [
85+ $ body = array (
8686 'iss ' => $ team_id ,
8787 'iat ' => time (),
8888 'exp ' => time () + 30 ,
8989 'origin ' => get_fqdn_from_url ( get_site_url () ),
90- ] ;
90+ ) ;
9191
9292 // exlude the origin restriction from the JWT for local environemts
9393 // this is to allow tools like wp-env or browsersync to work since the url
@@ -100,11 +100,11 @@ function get_jwt() {
100100
101101 $ key = openssl_pkey_get_private ( $ private_key );
102102 if ( ! $ key ) {
103- return new WP_Error ( 'InvalidKey ' , 'Invalid Private Key ' , [ 'status ' => 401 ] );
103+ return new WP_Error ( 'InvalidKey ' , 'Invalid Private Key ' , array ( 'status ' => 401 ) );
104104 }
105105
106106 if ( ! openssl_sign ( $ payload , $ signature , $ key , OPENSSL_ALGO_SHA256 ) ) {
107- return new WP_Error ( 'SignError ' , 'Signing Failed ' , [ 'status ' => 500 ] );
107+ return new WP_Error ( 'SignError ' , 'Signing Failed ' , array ( 'status ' => 500 ) );
108108 }
109109
110110 $ response = $ payload . '. ' . encode ( $ signature );
0 commit comments