Skip to content

Commit 0cb21c2

Browse files
committed
Updating Auth 0 token and API methods
Changing all deprecated methods and now supporting RS256 tokens.
1 parent a05e25f commit 0cb21c2

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version" : "1.0",
44
"require" : {
55
"bramus/router" : "dev-master",
6-
"vlucas/phpdotenv" : "dev-master",
7-
"auth0/auth0-php" : "4.0.11"
6+
"vlucas/phpdotenv" : "2.2.0",
7+
"auth0/auth0-php" : "~4.0.0"
88
},
99
"repositories" : [{
1010
"type" : "composer",

forsecret/oauth.php

+30-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
use Auth0\SDK\JWTVerifier;
3+
use Auth0\SDK\Auth0Api;
4+
use Auth0\SDK\Exception\CoreException;
5+
use Auth0\SDK\API\Management;
6+
27
/**
38
* Include required sources from composer.
49
*/
@@ -54,15 +59,30 @@ function ()
5459
$token = str_replace('Bearer ', '', $authorizationHeader);
5560
$secret = '<--!secret-->';
5661
$client = '<--!client-->';
57-
$domain = "<--!forplay.eu.auth0.com-->";
62+
$domain = '<--!forplay.eu.auth0.com-->';
63+
$domainUrl = '<--!https://forplay.eu.auth0.com/-->';
5864

5965
$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+
]);
6182

6283
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) {
6686
header('HTTP/1.0 401 Unauthorized');
6787

6888
/**
@@ -84,8 +104,8 @@ function ()
84104
}
85105

86106
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) {
89109
header('HTTP/1.0 401 Unauthorized');
90110

91111
/**
@@ -111,8 +131,8 @@ function ()
111131
* and the permissions are validated after based on admin rights.
112132
*/
113133

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' &&
116136
! strpos($requestUri, 'profiles.php')) {
117137

118138
header('HTTP/1.0 401 Unauthorized');
@@ -152,7 +172,7 @@ function ()
152172
/**
153173
* These is the private API save Forplay content and see the log.
154174
*/
155-
$router->match('POST|GET', '(log.*|save.*|imgs.*|google.*|profiles.*))',
175+
$router->match('POST|GET', '(log.*|save.*|imgs.*|google.*|profile.*)',
156176
function ()
157177
{
158178
global $events;

0 commit comments

Comments
 (0)