Skip to content

Instantly share code, notes, and snippets.

@lauritzh
Created September 4, 2022 10:57
Show Gist options
  • Save lauritzh/0d68c11b6869b4778e6726488facafc8 to your computer and use it in GitHub Desktop.
Save lauritzh/0d68c11b6869b4778e6726488facafc8 to your computer and use it in GitHub Desktop.
Mocked OIDC Discovery Response
<?php
/*
* (c) Lauritz Holtmann, https://security.lauritz-holtmann.de
*
* Could be for instance launched as follows:
* $ php -S 127.0.0.1:1234
* $ ngrok http 1234
*
* Visit https://something.ngrok.io/oidc_dicovery.php
*/
$issuer = "https://security.lauritz-holtmann.de";
$authorization_endpoint = "https://security.lauritz-holtmann.de/auth";
$token_endpoint = "https://security.lauritz-holtmann.de/token";
$userinfo_endpoint = "https://security.lauritz-holtmann.de/userinfo";
$introspection_endpoint = "https://security.lauritz-holtmann.de/introspection";
$jwks_uri = "https://security.lauritz-holtmann.de/jwks";
$registration_endpoint = "https://security.lauritz-holtmann.de/registration";
$data = array(
"issuer" => $issuer,
"authorization_endpoint" => $authorization_endpoint,
"token_endpoint" => $token_endpoint,
"userinfo_endpoint" => $userinfo_endpoint,
"introspection_endpoint" => $introspection_endpoint,
"jwks_uri" => $jwks_uri,
"registration_endpoint" => $registration_endpoint,
"response_types_supported" => array("code","token id_token"),
"subject_types_supported" => array("public","pairwise"),
"id_token_signing_alg_values_supported" => array("RS256")
);
header('Content-Type: application/json; charset=utf-8');
die(json_encode($data));
@lauritzh
Copy link
Author

If you want to serve the above PHP script using the built-in web server, you may need to create a custom router.php:

<?php
if (preg_match('/openid-configuration$/', $_SERVER['SCRIPT_NAME'])) {
  include(__DIR__ . $_SERVER['SCRIPT_NAME']);
  return;
}

// Default: serve the requested resource as-is.
return false;

You may then launch the server as follows:

$ php -S 127.0.0.1:1234 router.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment