Skip to content

Commit 1defaa5

Browse files
authored
Revert "Move SPA flows to use code (#11227)" (#11596)
This reverts commit 2287abc.
1 parent 59292a5 commit 1defaa5

File tree

14 files changed

+429
-1737
lines changed

14 files changed

+429
-1737
lines changed

src/Identity/ApiAuthorization.IdentityServer/samples/ApiAuthSample/Controllers/ConfigurationController.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Identity/ApiAuthorization.IdentityServer/samples/ApiAuthSample/Pages/Index.cshtml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@
1414
</head>
1515
<body>
1616
<h1>ApiAuthSample SPA client</h1>
17-
<button id="login" disabled>Login</button>
17+
<button id="login">Login</button>
1818
<button id="logout" disabled>Logout</button>
1919
<button id="call-api" disabled>Call API</button>
2020
<div id="login-result"></div>
2121
<div id="api-result"></div>
2222
<script src="/js/oidc-client.js"></script>
23-
<script src="js/app.js"></script>
24-
<script id="apiauth" type="text/javascript">
25-
initializeApplication();
23+
<script id="apiauth" type="text/javascript" asp-apiauth-parameters="ApiAuthSampleSPA">
24+
let $data = document.querySelector("#apiauth");
25+
let configuration = {};
26+
for (let key in $data.dataset) {
27+
configuration[key] = $data.dataset[key];
28+
}
29+
30+
let mgr = new Oidc.UserManager(configuration);
2631
</script>
32+
<script src="js/app.js"></script>
2733
</body>
2834
</html>
Binary file not shown.

src/Identity/ApiAuthorization.IdentityServer/samples/ApiAuthSample/wwwroot/js/app.js

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
var ids = {
2-
login: 'login',
3-
logout: 'logout',
4-
callApi: 'call-api',
5-
loginResult: 'login-result',
6-
apiResults: 'api-result'
7-
};
8-
9-
let mgr = undefined;
10-
1+

112
function invokeLogin() {
123
// Redirects to the Authorization Server for sign in.
134
return mgr.signinRedirect();
@@ -52,14 +43,19 @@ async function callApi() {
5243

5344
// Code to update the UI
5445

55-
if (window.location.hash || window.location.search) {
56-
initializeApplication()
57-
.then(() => {
58-
handleAuthorizationServerCallback();
59-
window.location.hash = '';
60-
});
46+
if (window.location.hash) {
47+
handleAuthorizationServerCallback();
48+
window.location.hash = '';
6149
}
6250

51+
let ids = {
52+
login: 'login',
53+
logout: 'logout',
54+
callApi: 'call-api',
55+
loginResult: 'login-result',
56+
apiResults: 'api-result'
57+
};
58+
6359
document.onreadystatechange = function () {
6460
if (document.readyState === 'complete') {
6561
let login = document.getElementById(ids.login);
@@ -72,20 +68,6 @@ document.onreadystatechange = function () {
7268
}
7369
};
7470

75-
async function initializeApplication() {
76-
const response = await fetch('_configuration/ApiAuthSampleSPA');
77-
const configuration = await response.json();
78-
mgr = new Oidc.UserManager(configuration);
79-
80-
enableLoginButton();
81-
82-
function enableLoginButton() {
83-
const login = document.querySelector('#login');
84-
login.disabled = false;
85-
}
86-
}
87-
88-
8971
function updateUserUI(user, error) {
9072
let loginResults = document.getElementById(ids.loginResult);
9173
let heading = document.createElement('h2');

0 commit comments

Comments
 (0)