Class Keycloak
java.lang.Object
net.datenwerke.oidc.client.provider.keycloak.Keycloak
- All Implemented Interfaces:
OidcService,OidcProvider
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
The class used when interacting with the keycloak javascript library.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHiddenAuthField(Container container) The base64 encoded ID token.getLogoutUrl(String redirectUri) Returns the url that needs to be called to terminate the session of the implementing oidc provider containing the redirect uri where the user is redirected to after logout.<T> TThe parsed id token as a JavaScript object.<T> TThe parsed refresh token as a JavaScript object.<T> TThe parsed access token as a JavaScript object.The base64 encoded refresh token.The user id.getToken()The base64 encoded access token that can be sent in the Authorization header in requests to services.booleanIs true if the user is authenticated, false otherwise.booleanReturns true if the token is expired.booleanisTokenExpired(int minValiditySeconds) Returns true if the token has less than minValiditySeconds seconds left before it expires.voidRedirects to the login form on (options is an optional object with redirectUri and/or prompt fields).voidlogin(LoginOptions options) voidlogout()Redirects to the logout url.voidlogout(LogoutOptions options) voidregisterCallback(OidcCallback callback) Register anyOidcCallbackat the implementing oidc provider.voidtryUpdateToken(Runnable runnable) voidupdateToken(int minValiditySeconds, Runnable successCallback) InvokesupdateToken(int, Runnable, Runnable)with null failureCallback.voidupdateToken(int minValiditySeconds, Runnable successCallback, Runnable failureCallback) If the token expires within minValidity seconds the token is refreshed.voidupdateToken(Runnable successCallback) InvokesupdateToken(int, Runnable)withMIN_TOKEN_VALIDITY_SECONDSfor minValiditySeconds.voidupdateTokenAndExecute(int minValiditySeconds, Runnable action) Ensure that the token does not expire in next minValiditySeconds or update token and execute action.voidupdateTokenAndExecute(Runnable action) InvokesupdateTokenAndExecute(int, Runnable)withMIN_TOKEN_VALIDITY_SECONDSfor minValiditySeconds.
-
Field Details
-
TOKEN_FORM_FIELD_NAME
- See Also:
-
-
Constructor Details
-
Keycloak
public Keycloak()
-
-
Method Details
-
isAuthenticated
public boolean isAuthenticated()Is true if the user is authenticated, false otherwise. -
getToken
The base64 encoded access token that can be sent in the Authorization header in requests to services.- Specified by:
getTokenin interfaceOidcProvider- Returns:
- The jwt access token or null if no session.
-
getParsedToken
public <T> T getParsedToken()The parsed access token as a JavaScript object. -
getSubject
The user id. -
getIdToken
The base64 encoded ID token.- Specified by:
getIdTokenin interfaceOidcProvider- Returns:
- the ID token or
nullif no ID token is available
-
getParsedIdToken
public <T> T getParsedIdToken()The parsed id token as a JavaScript object. -
getRefreshToken
The base64 encoded refresh token. -
getParsedRefreshToken
public <T> T getParsedRefreshToken()The parsed refresh token as a JavaScript object. -
login
Redirects to the login form on (options is an optional object with redirectUri and/or prompt fields).- Specified by:
loginin interfaceOidcProvider- Parameters:
locale- The locale to be used on oidc provider login page.
-
login
-
getLogoutUrl
Description copied from interface:OidcProviderReturns the url that needs to be called to terminate the session of the implementing oidc provider containing the redirect uri where the user is redirected to after logout.- Specified by:
getLogoutUrlin interfaceOidcProvider- Parameters:
redirectUri- The redirect uri to be included in the logout url.- Returns:
- The oidc logout url including the redirect uri.
-
logout
public void logout()Redirects to the logout url. -
logout
-
updateToken
If the token expires within minValidity seconds the token is refreshed. If the session status iframe is enabled, the session status is also checked. On failure the tokens are cleared. -
updateToken
InvokesupdateToken(int, Runnable, Runnable)with null failureCallback. -
updateToken
InvokesupdateToken(int, Runnable)withMIN_TOKEN_VALIDITY_SECONDSfor minValiditySeconds. -
updateTokenAndExecute
Ensure that the token does not expire in next minValiditySeconds or update token and execute action. Actions are queued until valid tokens are received and then executed.- Parameters:
minValiditySeconds- the minimum token validity.action- the action to perform once a valid token is present.
-
updateTokenAndExecute
InvokesupdateTokenAndExecute(int, Runnable)withMIN_TOKEN_VALIDITY_SECONDSfor minValiditySeconds.- Parameters:
action- the action to perform once a valid token is present.
-
isTokenExpired
public boolean isTokenExpired(int minValiditySeconds) Returns true if the token has less than minValiditySeconds seconds left before it expires. -
isTokenExpired
public boolean isTokenExpired()Returns true if the token is expired. -
addHiddenAuthField
public void addHiddenAuthField(Container container) -
tryUpdateToken
-