Package org.keycloak.authentication
Class ConsoleDisplayMode
- java.lang.Object
-
- org.keycloak.authentication.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ConsoleDisplayMode.HeaderBuilder
-
Field Summary
Fields Modifier and Type Field Description protected AuthenticationFlowContext
flowContext
protected ConsoleDisplayMode.HeaderBuilder
header
protected RequiredActionContext
requiredActionContext
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static javax.ws.rs.core.Response
browserContinue(KeycloakSession session, String callback)
Browser is required to continue login.static javax.ws.rs.core.Response
browserRequired(KeycloakSession session)
Browser is required to login.static ConsoleDisplayMode
challenge(AuthenticationFlowContext context)
Build challenge response for authentication flowsstatic ConsoleDisplayMode
challenge(RequiredActionContext context)
Build challenge response for required actionsLoginFormsProvider
form()
Create a theme form pre-populated with challengeprotected LoginFormsProvider
formInternal()
ConsoleDisplayMode.HeaderBuilder
header()
Start building the headerstatic ConsoleDisplayMode.HeaderBuilder
header(AuthenticationFlowContext context)
Build challenge response header only for authentication flowsstatic ConsoleDisplayMode.HeaderBuilder
header(RequiredActionContext context)
Build challenge response header only for required actionsjavax.ws.rs.core.Response
message(String msg, String... params)
Create challenge response with a body generated from localized message.properties of your themejavax.ws.rs.core.Response
response()
Generate response with empty http response bodyjavax.ws.rs.core.Response
text(String text)
Create challenge response with a text message body
-
-
-
Field Detail
-
requiredActionContext
protected RequiredActionContext requiredActionContext
-
flowContext
protected AuthenticationFlowContext flowContext
-
header
protected ConsoleDisplayMode.HeaderBuilder header
-
-
Method Detail
-
browserRequired
public static javax.ws.rs.core.Response browserRequired(KeycloakSession session)
Browser is required to login. This will abort client from doing a console login.- Parameters:
session
-- Returns:
-
browserContinue
public static javax.ws.rs.core.Response browserContinue(KeycloakSession session, String callback)
Browser is required to continue login. This will prompt client on whether to continue with a browser or abort.- Parameters:
session
-callback
-- Returns:
-
challenge
public static ConsoleDisplayMode challenge(RequiredActionContext context)
Build challenge response for required actions- Parameters:
context
-- Returns:
-
challenge
public static ConsoleDisplayMode challenge(AuthenticationFlowContext context)
Build challenge response for authentication flows- Parameters:
context
-- Returns:
-
header
public static ConsoleDisplayMode.HeaderBuilder header(RequiredActionContext context)
Build challenge response header only for required actions- Parameters:
context
-- Returns:
-
header
public static ConsoleDisplayMode.HeaderBuilder header(AuthenticationFlowContext context)
Build challenge response header only for authentication flows- Parameters:
context
-- Returns:
-
form
public LoginFormsProvider form()
Create a theme form pre-populated with challenge- Returns:
-
message
public javax.ws.rs.core.Response message(String msg, String... params)
Create challenge response with a body generated from localized message.properties of your theme- Parameters:
msg
- message idparams
- parameters to use to format the message- Returns:
-
text
public javax.ws.rs.core.Response text(String text)
Create challenge response with a text message body- Parameters:
text
- plain text of http response body- Returns:
-
response
public javax.ws.rs.core.Response response()
Generate response with empty http response body- Returns:
-
formInternal
protected LoginFormsProvider formInternal()
-
header
public ConsoleDisplayMode.HeaderBuilder header()
Start building the header- Returns:
-
-