传统网页集成 Keycloak 作为 OAuth2 的 Client 客户端
Keycloak OAuth2 About 1,294 wordsKeycloak.js
下载链接:https://cdn.jsdelivr.net/npm/keycloak-js
Javascript
<script>
const keycloak = new Keycloak({
url: 'http://localhost:8080',
realm: 'my-realm',
clientId: 'my-client-2'
});
keycloak.init({
onLoad: 'login-required'
}).then(() => {
console.log(`keycloak token: ${keycloak.token}`, keycloak);
}).catch(reason => {
console.error('Failed to initialize keycloak:', reason);
});
</script>
完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="/keycloak.js"></script>
<script>
const keycloak = new Keycloak({
url: 'http://localhost:8080',
realm: 'my-realm',
clientId: 'my-client-2'
});
keycloak.init({
onLoad: 'login-required'
}).then(() => {
console.log(`keycloak token: ${keycloak.token}`, keycloak);
}).catch(reason => {
console.error('Failed to initialize keycloak:', reason);
});
</script>
</head>
<body>
<!--web page-->
</body>
</html>
参考链接
https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter
Views: 771 · Posted: 2023-11-29
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...