Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


传统网页集成 Keycloak 作为 OAuth2 的 Client 客户端

Keycloak OAuth2 大约 1294 字

Keycloak.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

阅读 197 · 发布于 2023-11-29

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批