Skip to content

Commit 92df7f7

Browse files
committed
fix(oauth2): move disable IP adress check
1 parent 53fced6 commit 92df7f7

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

app/Models/OAuth2/ResourceServer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class ResourceServer extends BaseEntity
6666
*/
6767
public function isOwn($ip)
6868
{
69-
if (!config('oauth2.validate_resource_server_ip', true)) return true;
7069

7170
$provided_ips = array_map('trim', explode(',', $ip));
7271
$own_ips = array_map('trim', explode(',', $this->ips));

app/libs/OAuth2/GrantTypes/Strategies/ValidateBearerTokenResourceServerStrategy.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,31 @@ public function validate(AccessToken $access_token, IClient $client)
7878
'resource server is disabled!'
7979
);
8080
}
81-
//check resource server ip address
82-
if (!$resource_server->isOwn($current_ip))
83-
{
84-
throw new BearerTokenDisclosureAttemptException
85-
(
86-
sprintf
81+
if (config('oauth2.validate_resource_server_ip', false)) {
82+
//check resource server ip address
83+
if (!$resource_server->isOwn($current_ip)) {
84+
throw new BearerTokenDisclosureAttemptException
8785
(
88-
'resource server ip (%s) differs from current request ip %s',
89-
$resource_server->getIPAddresses(),
90-
$current_ip
91-
)
92-
);
93-
}
94-
// check if current ip belongs to a registered resource server audience
95-
if (!$this->token_service->checkAccessTokenAudience($access_token, $current_ip))
96-
{
97-
throw new BearerTokenDisclosureAttemptException
98-
(
99-
sprintf
86+
sprintf
87+
(
88+
'resource server ip (%s) differs from current request ip %s',
89+
$resource_server->getIPAddresses(),
90+
$current_ip
91+
)
92+
);
93+
}
94+
// check if current ip belongs to a registered resource server audience
95+
if (!$this->token_service->checkAccessTokenAudience($access_token, $current_ip)) {
96+
throw new BearerTokenDisclosureAttemptException
10097
(
101-
'access token current audience (%s) does not match with current request ip %s',
102-
$access_token->getAudience(),
103-
$current_ip
104-
)
105-
);
98+
sprintf
99+
(
100+
'access token current audience (%s) does not match with current request ip %s',
101+
$access_token->getAudience(),
102+
$current_ip
103+
)
104+
);
105+
}
106106
}
107107
}
108108
}

config/oauth2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
| the request IP and the access token audience.
1212
|
1313
*/
14-
'validate_resource_server_ip' => env('OAUTH2_VALIDATE_RESOURCE_SERVER_IP', true),
14+
'validate_resource_server_ip' => env('OAUTH2_VALIDATE_RESOURCE_SERVER_IP', false),
1515
];

0 commit comments

Comments
 (0)