Class ConsoleDisplayMode

  • public class ConsoleDisplayMode
    extends Object
    This class encapsulates a proprietary HTTP challenge protocol designed by keycloak team which is used by text-based console clients to dynamically render and prompt for information in a textual manner. The class is a builder which can build the challenge response (the header and response body). When doing code to token flow in OAuth, server could respond with 401 WWW-Authenticate: X-Text-Form-Challenge callback="http://localhost/..." param="username" label="Username: " mask=false param="password" label="Password: " mask=true Content-Type: text/plain Please login with your username and password The client receives this challenge. It first outputs whatever the text body of the message contains. It will then prompt for username and password using the label values as prompt messages for each parameter. After the input has been entered by the user, the client does a form POST to the callback url with the values of the input parameters entered. The server can challenge with 401 as many times as it wants. The client will look for 302 responses. It will will follow all redirects unless the Location url has an OAuth "code" parameter. If there is a code parameter, then the client will stop and finish the OAuth flow to obtain a token. Any other response code other than 401 or 302 the client should abort with an error message.
    • Method Detail

      • browserRequired

        public static browserRequired​(KeycloakSession session)
        Browser is required to login. This will abort client from doing a console login.
        session -
      • browserContinue

        public static browserContinue​(KeycloakSession session,
                                                                String callback)
        Browser is required to continue login. This will prompt client on whether to continue with a browser or abort.
        session -
        callback -
      • form

        public LoginFormsProvider form()
        Create a theme form pre-populated with challenge
      • message

        public message​(String msg,
                                                 String... params)
        Create challenge response with a body generated from localized of your theme
        msg - message id
        params - parameters to use to format the message
      • text

        public text​(String text)
        Create challenge response with a text message body
        text - plain text of http response body
      • response

        public response()
        Generate response with empty http response body