简体   繁体   English

在 Spring Boot 应用程序中生成一个 keycloak 注册链接

[英]Generate a keycloak register link in a spring boot app

I'm securing a web app build with spring boot with the keycloak-spring-boot-starter which creates me /sso/login and /sso/logout urls.我正在使用创建/sso/login/sso/logout urls 的keycloak-spring-boot-starter使用 spring boot 来保护 Web 应用程序构建。 But I also would like to provide a link to the keycloak registration page - but there is no /sso/register link.但我也想提供一个指向 keycloak 注册页面的链接 - 但没有/sso/register链接。

How do I implement this link?我如何实现这个链接? I could not find the place in the keycloak-adapter sources where the login/logout resource is implemented so a point to that would maybe enough.我在 keycloak-adapter 源中找不到实现登录/注销资源的位置,因此指出这一点可能就足够了。

You can create your own register link like below code ;您可以创建自己的注册链接,如下面的代码;

        String nonce = UUID.randomUUID().toString();
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
    String input = nonce + clientId;
    byte[] check = md.digest(input.getBytes(StandardCharsets.UTF_8));
    String hash = Base64Url.encode(check);

    return KeycloakUriBuilder.fromUri(keycloakEndpoint)
                .path("/realms/{realm-name}/protocol/openid-connect/registrations")
                .queryParam("response_type", "code") // Autherization Code Flow
                .queryParam("scope", "openid") // Add additional scopes if needed
                .queryParam("nonce", nonce)
                .queryParam("hash", hash)
                .queryParam("client_id", clientId)
                .queryParam("redirect_uri", "http://sample.javaspringboot.com/" + "redirect/" + redirectUrl).build(realm).toString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM