Class AuthzClient
- java.lang.Object
- 
- org.keycloak.authorization.client.AuthzClient
 
- 
 public class AuthzClient extends Object This is class serves as an entry point for clients looking for access to Keycloak Authorization Services. When creating a new instances make sure you have a Keycloak Server running at the location specified in the client configuration. The client tries to obtain server configuration by invoking the UMA Discovery Endpoint, usually available from the server at http(s)://{server}:{port}/auth/realms/{realm}/.well-known/uma-configuration. - Author:
- Pedro Igor
 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthorizationResourceauthorization()Creates aAuthorizationResourceinstance which can be used to obtain permissions from the server.AuthorizationResourceauthorization(String accessToken)Creates aAuthorizationResourceinstance which can be used to obtain permissions from the server.AuthorizationResourceauthorization(String userName, String password)Creates aAuthorizationResourceinstance which can be used to obtain permissions from the server.AuthorizationResourceauthorization(String userName, String password, String scope)static AuthzClientcreate()Creates a new instance.static AuthzClientcreate(InputStream configStream)Creates a new instance.static AuthzClientcreate(Configuration configuration)Creates a new instance.ConfigurationgetConfiguration()Obtains the client configurationServerConfigurationgetServerConfiguration()Returns the configuration obtained from the server at the UMA Discovery Endpoint.AccessTokenResponseobtainAccessToken()Obtains an access token using the client credentials.AccessTokenResponseobtainAccessToken(String userName, String password)Obtains an access token using the resource owner credentials.ProtectionResourceprotection()Creates aProtectionResourceinstance which can be used to access the Protection API.ProtectionResourceprotection(String accessToken)Creates aProtectionResourceinstance which can be used to access the Protection API.ProtectionResourceprotection(String userName, String password)Creates aProtectionResourceinstance which can be used to access the Protection API.
 
- 
- 
- 
Method Detail- 
createpublic static AuthzClient create() throws RuntimeException Creates a new instance. This method expects a keycloak.jsonin the classpath, otherwise an exception will be thrown.- Returns:
- a new instance
- Throws:
- RuntimeException- in case there is no- keycloak.jsonfile in the classpath or the file could not be parsed
 
 - 
createpublic static AuthzClient create(InputStream configStream) throws RuntimeException Creates a new instance. - Parameters:
- configStream- the input stream with the configuration data
- Returns:
- a new instance
- Throws:
- RuntimeException
 
 - 
createpublic static AuthzClient create(Configuration configuration) Creates a new instance. - Parameters:
- configuration- the client configuration
- Returns:
- a new instance
 
 - 
protectionpublic ProtectionResource protection() Creates a ProtectionResourceinstance which can be used to access the Protection API.When using this method, the PAT (the access token with the uma_protection scope) is obtained for the client itself, using any of the supported credential types (client/secret, jwt, etc). - Returns:
- a ProtectionResource
 
 - 
protectionpublic ProtectionResource protection(String accessToken) Creates a ProtectionResourceinstance which can be used to access the Protection API.- Parameters:
- accessToken- the PAT (the access token with the uma_protection scope)
- Returns:
- a ProtectionResource
 
 - 
protectionpublic ProtectionResource protection(String userName, String password) Creates a ProtectionResourceinstance which can be used to access the Protection API.When using this method, the PAT (the access token with the uma_protection scope) is obtained for a given user. - Returns:
- a ProtectionResource
 
 - 
authorizationpublic AuthorizationResource authorization() Creates a AuthorizationResourceinstance which can be used to obtain permissions from the server.- Returns:
- a AuthorizationResource
 
 - 
authorizationpublic AuthorizationResource authorization(String accessToken) Creates a AuthorizationResourceinstance which can be used to obtain permissions from the server.- Parameters:
- accessToken- the Access Token that will be used as a bearer to access the token endpoint
- Returns:
- a AuthorizationResource
 
 - 
authorizationpublic AuthorizationResource authorization(String userName, String password) Creates a AuthorizationResourceinstance which can be used to obtain permissions from the server.- Parameters:
- userName- an ID Token or Access Token representing an identity and/or access context
- password-
- Returns:
- a AuthorizationResource
 
 - 
authorizationpublic AuthorizationResource authorization(String userName, String password, String scope) 
 - 
obtainAccessTokenpublic AccessTokenResponse obtainAccessToken() Obtains an access token using the client credentials.- Returns:
- an AccessTokenResponse
 
 - 
obtainAccessTokenpublic AccessTokenResponse obtainAccessToken(String userName, String password) Obtains an access token using the resource owner credentials.- Returns:
- an AccessTokenResponse
 
 - 
getServerConfigurationpublic ServerConfiguration getServerConfiguration() Returns the configuration obtained from the server at the UMA Discovery Endpoint.- Returns:
- the ServerConfiguration
 
 - 
getConfigurationpublic Configuration getConfiguration() Obtains the client configuration- Returns:
- the Configuration
 
 
- 
 
-