1
1
<?php
2
+ use Auth0 \SDK \JWTVerifier ;
3
+ use Auth0 \SDK \Auth0Api ;
4
+ use Auth0 \SDK \Exception \CoreException ;
5
+ use Auth0 \SDK \API \Management ;
6
+
2
7
/**
3
8
* Include required sources from composer.
4
9
*/
@@ -54,15 +59,30 @@ function ()
54
59
$ token = str_replace ('Bearer ' , '' , $ authorizationHeader );
55
60
$ secret = '<--!secret--> ' ;
56
61
$ client = '<--!client--> ' ;
57
- $ domain = "<--!forplay.eu.auth0.com--> " ;
62
+ $ domain = '<--!forplay.eu.auth0.com--> ' ;
63
+ $ domainUrl = '<--!https://forplay.eu.auth0.com/--> ' ;
58
64
59
65
$ decodedToken = null ;
60
- $ api = new \Auth0 \SDK \Auth0Api ($ token , $ domain );
66
+ $ auth0Api = new Management ($ token , $ domain );
67
+
68
+ $ verifier = new JWTVerifier (
69
+ [
70
+ 'suported_algs ' => [
71
+ 'RS256 ' ,
72
+ 'HS256 '
73
+ ],
74
+ 'valid_audiences ' => [
75
+ $ client
76
+ ],
77
+ 'authorized_iss ' => [
78
+ $ domainUrl
79
+ ],
80
+ 'client_secret ' => $ secret
81
+ ]);
61
82
62
83
try {
63
- $ decodedToken = \Auth0 \SDK \Auth0JWT::decode ($ token , $ client ,
64
- $ secret );
65
- } catch (\Auth0 \SDK \Exception \CoreException $ e ) {
84
+ $ decodedToken = $ verifier ->verifyAndDecode ($ token );
85
+ } catch (CoreException $ e ) {
66
86
header ('HTTP/1.0 401 Unauthorized ' );
67
87
68
88
/**
@@ -84,8 +104,8 @@ function ()
84
104
}
85
105
86
106
try {
87
- $ user = $ api ->users ->get ($ decodedToken ->sub );
88
- } catch (\ Auth0 \ SDK \ Exception \ CoreException $ e ) {
107
+ $ user = $ auth0Api ->users ->get ($ decodedToken ->sub );
108
+ } catch (CoreException $ e ) {
89
109
header ('HTTP/1.0 401 Unauthorized ' );
90
110
91
111
/**
@@ -111,8 +131,8 @@ function ()
111
131
* and the permissions are validated after based on admin rights.
112
132
*/
113
133
114
- if ($ user ['appMetadata ' ]['roles ' ][0 ] != 'admin ' &&
115
- $ user ['appMetadata ' ]['roles ' ][0 ] != 'superadmin ' &&
134
+ if ($ user ['app_metadata ' ]['roles ' ][0 ] != 'admin ' &&
135
+ $ user ['app_metadata ' ]['roles ' ][0 ] != 'superadmin ' &&
116
136
! strpos ($ requestUri , 'profiles.php ' )) {
117
137
118
138
header ('HTTP/1.0 401 Unauthorized ' );
@@ -152,7 +172,7 @@ function ()
152
172
/**
153
173
* These is the private API save Forplay content and see the log.
154
174
*/
155
- $ router ->match ('POST|GET ' , '(log.*|save.*|imgs.*|google.*|profiles.*) ) ' ,
175
+ $ router ->match ('POST|GET ' , '(log.*|save.*|imgs.*|google.*|profile.* ) ' ,
156
176
function ()
157
177
{
158
178
global $ events ;
0 commit comments