簡體   English   中英

在 Spring Boot 應用程序中生成一個 keycloak 注冊鏈接

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

我正在使用創建/sso/login/sso/logout urls 的keycloak-spring-boot-starter使用 spring boot 來保護 Web 應用程序構建。 但我也想提供一個指向 keycloak 注冊頁面的鏈接 - 但沒有/sso/register鏈接。

我如何實現這個鏈接? 我在 keycloak-adapter 源中找不到實現登錄/注銷資源的位置,因此指出這一點可能就足夠了。

您可以創建自己的注冊鏈接,如下面的代碼;

        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