Skip to content

Commit 8980ab8

Browse files
feat: possibility to disable tls verification (#19)
* feat: possibility to disable tls verification * chore: update readme
1 parent be4cccb commit 8980ab8

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ Replace `YourCustomLoginResponse` with the class name of your custom implementat
7272

7373
Make sure to implement the `LoginResponseHandlerInterface` in your custom response handler class to ensure compatibility.
7474

75+
### Disable TLS Certificate Verification
76+
By default, the package verifies the TLS certificate when making requests to the issuer. If you want to disable TLS certificate verification, you can set the `OIDC_TLS_VERIFY` variable to false in your environment configuration.
77+
7578
## Contributing
7679
If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository of this package.
7780

config/oidc.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,12 @@
7474
* The prefix of the login route.
7575
*/
7676
'prefix' => '',
77-
]
77+
],
78+
79+
/**
80+
* TLS Verify
81+
* Can be disabled for local development.
82+
* Is used in OpenIDConfigurationLoader and in the ServiceProvider for OpenIDConnectClient.
83+
*/
84+
'tls_verify' => env('OIDC_TLS_VERIFY', true),
7885
];

src/OpenIDConfiguration/OpenIDConfigurationLoader.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function __construct(
1313
protected string $issuer,
1414
protected ?Repository $cacheStore = null,
1515
protected int $cacheTtl = 3600,
16+
protected bool $tlsVerify = true,
1617
) {
1718
}
1819

@@ -37,7 +38,12 @@ protected function getConfigurationFromIssuer(): OpenIDConfiguration
3738
{
3839
$url = $this->getOpenIDConfigurationUrl();
3940

40-
$response = Http::get($url);
41+
$pendingRequest = Http::baseUrl($url);
42+
if (!$this->tlsVerify) {
43+
$pendingRequest->withoutVerifying();
44+
}
45+
$response = $pendingRequest->get($url);
46+
4147
if (!$response->successful()) {
4248
throw new OpenIDConfigurationLoaderException(
4349
message: 'Could not load OpenID configuration from issuer',

src/OpenIDConnectServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ protected function registerConfigurationLoader(): void
8686
$app['config']->get('oidc.issuer'),
8787
$app['cache']->store($app['config']->get('oidc.configuration_cache.store')),
8888
$app['config']->get('oidc.configuration_cache.ttl'),
89+
$app['config']->get('oidc.tls_verify') === true,
8990
);
9091
});
9192
}
@@ -109,6 +110,11 @@ protected function registerClient(): void
109110
if (is_array($additionalScopes) && count($additionalScopes) > 0) {
110111
$oidc->addScope($additionalScopes);
111112
}
113+
114+
if ($app['config']->get('oidc.tls_verify') !== true) {
115+
$oidc->setVerifyHost(false);
116+
$oidc->setVerifyPeer(false);
117+
}
112118
return $oidc;
113119
});
114120
}

0 commit comments

Comments
 (0)