@@ -90,14 +90,15 @@ public static function existsValidToken($token_id, $user_id)
9090 *
9191 * @return array
9292 */
93- public static function dirtyDecode ($ access_token )
93+ public static function dirtyDecode ($ access_token, $ claims = [] )
9494 {
9595 $ now = time ();
9696 $ expecting = false ;
9797 $ incorrect = false ;
9898 $ expired = false ;
9999 $ error = false ;
100100 $ errors = array ();
101+ $ decodedToken = array ();
101102 $ token_segments = explode ('. ' , $ access_token );
102103 $ body = (isset ($ token_segments [1 ])) ? $ token_segments [1 ] : null ;
103104
@@ -119,7 +120,7 @@ public static function dirtyDecode($access_token)
119120 $ expired = true ;
120121 }
121122
122- return array (
123+ $ decodedToken = array (
123124 'token_id ' => (isset ($ data ->jti )) ? $ data ->jti : null ,
124125 'user_id ' => (isset ($ data ->sub )) ? $ data ->sub : null ,
125126 'expecting ' => $ expecting ,
@@ -135,6 +136,12 @@ public static function dirtyDecode($access_token)
135136 'errors ' => $ errors ,
136137 'valid ' => ($ expecting || $ incorrect || $ expired || $ error ) ? false : true
137138 );
139+
140+ if (!empty ($ claims )){
141+ $ decodedToken ['claims ' ] = static ::getCustomClaims ($ data , $ claims );
142+ }
143+
144+ return $ decodedToken ;
138145 }
139146
140147 public static function urlDecode ($ input )
@@ -164,4 +171,18 @@ public static function jsonDecode($input)
164171 }
165172 return $ obj ;
166173 }
167- }
174+
175+ public static function getCustomClaims ($ data , $ claims )
176+ {
177+ $ decodedToken = array ();
178+ foreach ($ claims as $ claim ){
179+ foreach ($ data as $ key => $ value ) {
180+ if ($ key == $ claim ) {
181+ $ decodedToken [$ claim ] = (isset ($ claim )) ? $ value : null ;
182+ }
183+ }
184+ }
185+
186+ return $ decodedToken ;
187+ }
188+ }
0 commit comments