Skip to content

Commit f0f4de8

Browse files
committed
feat: ADD configurable showcases of api curl calls
1 parent 975ed39 commit f0f4de8

File tree

3 files changed

+128
-72
lines changed

3 files changed

+128
-72
lines changed

example-config.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// Client configuration
99
$issuer = "https://example.com/oidc/";
1010
$clientId = "some-client-id";
11-
$clientSecret = "some-client-secret"; // comment if you are using PKCE
11+
$clientSecret = "some-client-secret"; // comment if you are using PKCE
1212
// $pkceCodeChallengeMethod = "S256"; // uncomment to use PKCE
13-
$redirectPage = "refreshtoken.php"; // select between "refreshtoken.php" and "auth.php"
13+
$redirectPage = "refreshtoken.php"; // select between "refreshtoken.php" and "auth.php"
1414
$redirectUrl = "http://localhost/simple-oidc-client-php/" . $redirectPage;
1515
// add scopes as keys and a friendly message of the scope as value
1616
$scopesDefine = array(
@@ -23,10 +23,18 @@
2323
$accessTokenNote = "NOTE: New access tokens expire in 1 hour.";
2424
$manageTokenNote = "You can manage your refresh tokens in the following link: ";
2525
$manageTokens = $issuer . "manage/user/services";
26-
$sessionName = "simple-oidc-client-php"; // This value must be the same with the name of the parent directory
27-
$sessionLifetime = 60 * 60; // must be equal to access token validation time in seconds
26+
$sessionName = "simple-oidc-client-php"; // This value must be the same with the name of the parent directory
27+
$sessionLifetime = 60 * 60; // must be equal to access token validation time in seconds
2828
$bannerText = "";
29-
$bannerType = "info"; // Select one of "info", "warning", "error" or "success"
29+
$bannerType = "info"; // Select one of "info", "warning", "error" or "success"
3030
$allowIntrospection = false;
31-
$enableActiveTokensTable = false; // This option works only for MITREid Connect based OPs
31+
$enableActiveTokensTable = false; // This option works only for MITREid Connect based OPs
3232
$showIdToken = false;
33+
34+
$customAPIs = [
35+
[
36+
'title' => 'To call Perun RPC API, use the following curl command:',
37+
'url' => 'https://idm.ics.muni.cz/oauth/rpc/json/authzResolver/getPerunPrincipal',
38+
'note' => 'NOTE: Full documentation is available at <a href="https://perun-aai.org/documentation/technical-documentation/rpc-api/index.html">perun-aai.org</a>'
39+
]
40+
];

refreshtoken.php

Lines changed: 112 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,121 @@
1-
<?php include(__DIR__ . '/resources/templates/header.php'); ?>
2-
<?php include(__DIR__ . '/resources/controllers/session.php'); ?>
3-
<br>
4-
<main role="main" class="container">
5-
<div class="jumbotron">
6-
<img class="sticky" src="<?php echo $img; ?>" alt="Logo" style="height: 60px; width: 60px; margin-bottom: 20px;">
7-
<h1 style="display: inline;"><?php echo $title; ?></h1>
8-
<p style="margin-bottom: 0px;"><strong>Client ID: </strong> <?php echo $clientId; ?></p>
9-
<?php if (!empty($clientSecret)) {
10-
echo "<p><b>Client Secret: </b> $clientSecret</p>";
11-
}
12-
?>
13-
<br>
1+
<?php include(__DIR__ . '/resources/templates/header.php'); ?>
2+
<?php include(__DIR__ . '/resources/controllers/session.php'); ?>
3+
<br>
4+
<main role="main" class="container">
5+
<div class="jumbotron">
6+
<img class="sticky" src="<?php echo $img; ?>" alt="Logo"
7+
style="height: 60px; width: 60px; margin-bottom: 20px;">
8+
<h1 style="display: inline;">
9+
<?php echo $title; ?>
10+
</h1>
11+
<p style="margin-bottom: 0px;"><strong>Client ID: </strong>
12+
<?php echo $clientId; ?>
13+
</p>
14+
<?php if (!empty($clientSecret)) {
15+
echo "<p><b>Client Secret: </b> $clientSecret</p>";
16+
}
17+
?>
18+
<br>
1419

15-
<?php if ($enableActiveTokensTable) : ?>
20+
<?php if ($enableActiveTokensTable): ?>
1621
<ul class="nav nav-pills">
17-
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#accessTokenMenu">My Access Token</a></li>
18-
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#refreshTokenMenu">My Refresh Tokens</a></li>
22+
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#accessTokenMenu">My Access
23+
Token</a></li>
24+
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#refreshTokenMenu">My Refresh Tokens</a>
25+
</li>
1926
</ul>
20-
<?php endif; ?>
27+
<?php endif; ?>
2128

22-
<div class="tab-content">
23-
<div id="accessTokenMenu" class="tab-pane active">
24-
<?php if ($showIdToken) : ?>
29+
<div class="tab-content">
30+
<div id="accessTokenMenu" class="tab-pane active">
31+
<?php if ($showIdToken): ?>
2532
<div>
2633
<p class="lead" style="margin-bottom: 0px;">ID Token: </p>
27-
<input id="idToken" size=70 type="text" readonly style="cursor: text;" value="<?php echo $idToken; ?>" />
28-
<button id="copy-mAccessT" style="cursor: pointer" class="btn btn-copy btn-primary"><em class="icon-file"></em> Copy</button>
34+
<input id="idToken" size=70 type="text" readonly style="cursor: text;"
35+
value="<?php echo $idToken; ?>" />
36+
<button id="copy-mAccessT" style="cursor: pointer" class="btn btn-copy btn-primary"><em
37+
class="icon-file"></em> Copy</button>
2938
</div>
30-
<?php endif; ?>
39+
<?php endif; ?>
40+
<div>
41+
<p class="lead" style="margin-bottom: 0px;">Access Token: </p>
42+
<input id="accessToken" size=70 type="text" readonly style="cursor: text;"
43+
value="<?php echo $accessToken; ?>" />
44+
<button id="copy-mAccessT" style="cursor: pointer" class="btn btn-copy btn-primary"><em
45+
class="icon-file"></em> Copy</button>
46+
</div>
47+
<div>
48+
<p style="margin-bottom: 0px;">To get the user info use the following curl command: </p>
49+
<input id="curlUserInfo" size=70 type="text" readonly style="cursor: text;"
50+
value="<?php echo getCurlForEndpoint($accessToken, $userInfoEndpoint); ?>" />
51+
<button id="copyCurlUserInfo" style="cursor: pointer" class="btn btn-copy btn-primary"><em
52+
class="icon-file"></em> Copy</button>
53+
</div>
54+
<?php if (!empty($customAPIs)) { ?>
55+
<?php foreach ($customAPIs as $API) { ?>
56+
<div>
57+
<p style="margin-bottom: 0px;">
58+
<?php echo $API["title"]; ?>
59+
</p>
60+
<input id="curlUserInfo" size=70 type="text" readonly style="cursor: text;"
61+
value="<?php echo getCurlForEndpoint($accessToken, $API["url"]); ?>" />
62+
<button id="copyCurlUserInfo" style="cursor: pointer" class="btn btn-copy btn-primary"><em
63+
class="icon-file"></em> Copy</button>
64+
<p>
65+
<?php echo $API["note"]; ?>
66+
</p>
67+
</div>
68+
<?php } ?>
69+
<?php } ?>
70+
<?php if ($allowIntrospection): ?>
3171
<div>
32-
<p class="lead" style="margin-bottom: 0px;">Access Token: </p>
33-
<input id="accessToken" size=70 type="text" readonly style="cursor: text;" value="<?php echo $accessToken; ?>" />
34-
<button id="copy-mAccessT" style="cursor: pointer" class="btn btn-copy btn-primary"><em class="icon-file"></em> Copy</button>
72+
<p style="margin-bottom: 0px;">To introspect the token use the following curl command: </p>
73+
<input id="curlIntrospection" size=70 type="text" readonly style="cursor: text;"
74+
value="<?php echo getCurlIntrospect($accessToken, $introspectionEndpoint, $clientId, $clientSecret); ?>" />
75+
<button id="copyCurlIntrospection" style="cursor: pointer" class="btn btn-copy btn-primary"><em
76+
class="icon-file"></em> Copy</button>
3577
</div>
36-
<div>
37-
<p style="margin-bottom: 0px;">To get the user info use the following curl command: </p>
38-
<input id="curlUserInfo" size=70 type="text" readonly style="cursor: text;" value="<?php echo getCurlUserInfo($accessToken, $userInfoEndpoint); ?>" />
39-
<button id="copyCurlUserInfo" style="cursor: pointer" class="btn btn-copy btn-primary"><em class="icon-file"></em> Copy</button>
78+
<?php endif; ?>
79+
<p>
80+
<?php echo $accessTokenNote; ?>
81+
</p>
82+
<?php if (!empty($refreshToken)) { ?>
83+
<div id="refreshTokenBlock">
84+
<p class="lead" style="margin-bottom: 0px;">Refresh Token: </p>
85+
<input id="refreshToken" size=70 type="text" readonly style="cursor: text;"
86+
value="<?php echo $refreshToken; ?>" />
87+
<button id="copyRefreshToken" style="cursor: pointer" class="btn btn-copy btn-primary"><em
88+
class="icon-file"></em> Copy</button>
89+
<p>
90+
<?php echo $refreshTokenNote; ?>
91+
</p>
4092
</div>
41-
<?php if ($allowIntrospection) : ?>
4293
<div>
43-
<p style="margin-bottom: 0px;">To introspect the token use the following curl command: </p>
44-
<input id="curlIntrospection" size=70 type="text" readonly style="cursor: text;" value="<?php echo getCurlIntrospect($accessToken, $introspectionEndpoint, $clientId, $clientSecret); ?>" />
45-
<button id="copyCurlIntrospection" style="cursor: pointer" class="btn btn-copy btn-primary"><em class="icon-file"></em> Copy</button>
94+
<p style="margin-bottom: 0px;">To generate access tokens from this refresh token use the following
95+
curl command: </p>
96+
<input id="curlRefresh" size=70 type="text" readonly style="cursor: text;"
97+
value="<?php echo getCurlRefresh($refreshToken, $tokenEndpoint, $clientId, $clientSecret, $scopes); ?>" />
98+
<button id="copyCurlRefresh" style="cursor: pointer" class="btn btn-copy btn-primary"><em
99+
class="icon-file"></em> Copy</button>
100+
<p>
101+
<?php echo $accessTokenNote; ?>
102+
</p>
46103
</div>
47-
<?php endif; ?>
48-
<p><?php echo $accessTokenNote; ?></p>
49-
<?php if (!empty($refreshToken)) { ?>
50-
<div id="refreshTokenBlock">
51-
<p class="lead" style="margin-bottom: 0px;">Refresh Token: </p>
52-
<input id="refreshToken" size=70 type="text" readonly style="cursor: text;" value="<?php echo $refreshToken; ?>" />
53-
<button id="copyRefreshToken" style="cursor: pointer" class="btn btn-copy btn-primary"><em class="icon-file"></em> Copy</button>
54-
<p><?php echo $refreshTokenNote; ?></p>
55-
</div>
56-
<div>
57-
<p style="margin-bottom: 0px;">To generate access tokens from this refresh token use the following curl command: </p>
58-
<input id="curlRefresh" size=70 type="text" readonly style="cursor: text;" value="<?php echo getCurlRefresh($refreshToken, $tokenEndpoint, $clientId, $clientSecret, $scopes); ?>" />
59-
<button id="copyCurlRefresh" style="cursor: pointer" class="btn btn-copy btn-primary"><em class="icon-file"></em> Copy</button>
60-
<p><?php echo $accessTokenNote; ?></p>
61-
</div>
62-
<br>
63-
<?php } else { ?>
64-
<form id="createRefreshToken" action="refreshtoken.php" method="POST">
65-
<input type="hidden" name="action" value="create-refresh-token" />
66-
<input class="btn btn-primary" type="submit" value="Create Refresh Token" />
67-
</form>
68-
<?php } ?>
69-
<p><?php echo $manageTokenNote; ?><a target="_blank" class="navbar-brand" href="<?php echo $manageTokens; ?>"><?php echo $manageTokens; ?></a></p>
70-
</div>
71-
<?php if ($enableActiveTokensTable) : ?>
104+
<br>
105+
<?php } else { ?>
106+
<form id="createRefreshToken" action="refreshtoken.php" method="POST">
107+
<input type="hidden" name="action" value="create-refresh-token" />
108+
<input class="btn btn-primary" type="submit" value="Create Refresh Token" />
109+
</form>
110+
<?php } ?>
111+
<p>
112+
<?php echo $manageTokenNote; ?><a target="_blank" class="navbar-brand"
113+
href="<?php echo $manageTokens; ?>">
114+
<?php echo $manageTokens; ?>
115+
</a>
116+
</p>
117+
</div>
118+
<?php if ($enableActiveTokensTable): ?>
72119
<div id="refreshTokenMenu" class="tab-pane fade">
73120
<table class="table table-striped">
74121
<caption>Active Refresh Tokens</caption>
@@ -84,9 +131,10 @@
84131
</tbody>
85132
</table>
86133
</div>
87-
<?php endif; ?>
88-
</div>
89-
134+
<?php endif; ?>
90135
</div>
91-
</main>
92-
<?php include(__DIR__ . '/resources/templates/footer.php'); ?>
136+
137+
</div>
138+
</main>
139+
<?php include(__DIR__ . '/resources/templates/footer.php'); ?>
140+

src/MitreIdConnectUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ function getCurlRefresh($refreshToken, $tokenEndpoint, $clientId, $clientSecret
1717
. "| python -m json.tool;";
1818
}
1919

20-
function getCurlUserInfo($accessToken, $userInfoEndpoint)
20+
function getCurlForEndpoint($accessToken, $endpoint)
2121
{
22-
return "curl ${userInfoEndpoint} "
22+
return "curl ${endpoint} "
2323
. "-H 'Authorization: Bearer ${accessToken}' "
2424
. "-H 'Content-type: application/json' "
2525
. "| python -m json.tool;";

0 commit comments

Comments
 (0)