Package com.nimbusds.oauth2.sdk.auth
Class JWTAuthentication
java.lang.Object
com.nimbusds.oauth2.sdk.auth.ClientAuthentication
com.nimbusds.oauth2.sdk.auth.JWTAuthentication
- Direct Known Subclasses:
ClientSecretJWT,PrivateKeyJWT
Base abstract class for JSON Web Token (JWT) based client authentication at
the Token endpoint.
Related specifications:
- OAuth 2.0 (RFC 6749), section 3.2.1.
- JSON Web Token (JWT) Profile for OAuth 2.0 Client Authentication and Authorization Grants (RFC 7523).
- OpenID Connect Core 1.0, section 9.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe expected client assertion type, corresponding to theclient_assertion_typeparameter. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJWTAuthentication(ClientAuthenticationMethod method, com.nimbusds.jwt.SignedJWT clientAssertion) Creates a new JSON Web Token (JWT) based client authentication. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTo(HTTPRequest httpRequest) Applies the authentication to the specified HTTP request by setting its Authorization header and/or POST entity-body parameters (according to the implemented client authentication method).protected static voidensureClientAssertionType(Map<String, List<String>> params) Ensures the specified parameters map contains an entry with key "client_assertion_type" pointing to a string that equals the expectedCLIENT_ASSERTION_TYPE.com.nimbusds.jwt.SignedJWTGets the client assertion, corresponding to theclient_assertionparameter.Returns the name of the form parameters, if such are used by the authentication method.Gets the client authentication claims set contained in the client assertion JSON Web Token (JWT).static JWTAuthenticationparse(HTTPRequest httpRequest) Parses the specified HTTP request for a JSON Web Token (JWT) based client authentication.protected static com.nimbusds.jwt.SignedJWTparseClientAssertion(Map<String, List<String>> params) Parses the specified parameters map for a client assertion.protected static ClientIDparseClientID(Map<String, List<String>> params) Parses the specified parameters map for an optional client identifier.Returns the parameter representation of this JSON Web Token (JWT) based client authentication.Methods inherited from class com.nimbusds.oauth2.sdk.auth.ClientAuthentication
getClientID, getMethod
-
Field Details
-
CLIENT_ASSERTION_TYPE
The expected client assertion type, corresponding to theclient_assertion_typeparameter. This is a URN string set to "urn:ietf:params:oauth:client-assertion-type:jwt-bearer".- See Also:
-
-
Constructor Details
-
JWTAuthentication
protected JWTAuthentication(ClientAuthenticationMethod method, com.nimbusds.jwt.SignedJWT clientAssertion) Creates a new JSON Web Token (JWT) based client authentication.- Parameters:
method- The client authentication method. Must not benull.clientAssertion- The client assertion, corresponding to theclient_assertionparameter, in the form of a signed JSON Web Token (JWT). Must be signed and notnull.- Throws:
IllegalArgumentException- If the client assertion is not signed or doesn't conform to the expected format.
-
-
Method Details
-
getClientAssertion
Gets the client assertion, corresponding to theclient_assertionparameter.- Returns:
- The client assertion, in the form of a signed JSON Web Token (JWT).
-
getJWTAuthenticationClaimsSet
Gets the client authentication claims set contained in the client assertion JSON Web Token (JWT).- Returns:
- The client authentication claims.
-
getFormParameterNames
Description copied from class:ClientAuthenticationReturns the name of the form parameters, if such are used by the authentication method.- Specified by:
getFormParameterNamesin classClientAuthentication- Returns:
- The form parameter names, empty set if none.
-
toParameters
Returns the parameter representation of this JSON Web Token (JWT) based client authentication. Note that the parameters are notapplication/x-www-form-urlencodedencoded.Parameters map:
"client_assertion" = [serialised-JWT] "client_assertion_type" = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
- Returns:
- The parameters map, with keys "client_assertion" and "client_assertion_type".
-
applyTo
Description copied from class:ClientAuthenticationApplies the authentication to the specified HTTP request by setting its Authorization header and/or POST entity-body parameters (according to the implemented client authentication method).- Specified by:
applyToin classClientAuthentication- Parameters:
httpRequest- The HTTP request. Must not benull.
-
ensureClientAssertionType
protected static void ensureClientAssertionType(Map<String, List<String>> params) throws ParseExceptionEnsures the specified parameters map contains an entry with key "client_assertion_type" pointing to a string that equals the expectedCLIENT_ASSERTION_TYPE. This method is intended to aid parsing of JSON Web Token (JWT) based client authentication objects.- Parameters:
params- The parameters map to check. The parameters must not benullandapplication/x-www-form-urlencodedencoded.- Throws:
ParseException- If expected "client_assertion_type" entry wasn't found.
-
parseClientAssertion
protected static com.nimbusds.jwt.SignedJWT parseClientAssertion(Map<String, List<String>> params) throws ParseExceptionParses the specified parameters map for a client assertion. This method is intended to aid parsing of JSON Web Token (JWT) based client authentication objects.- Parameters:
params- The parameters map to parse. It must contain an entry with key "client_assertion" pointing to a string that represents a signed serialised JSON Web Token (JWT). The parameters must not benullandapplication/x-www-form-urlencodedencoded.- Returns:
- The client assertion as a signed JSON Web Token (JWT).
- Throws:
ParseException- If a "client_assertion" entry couldn't be retrieved from the parameters map.
-
parseClientID
Parses the specified parameters map for an optional client identifier. This method is intended to aid parsing of JSON Web Token (JWT) based client authentication objects.- Parameters:
params- The parameters map to parse. It may contain an entry with key "client_id" pointing to a string that represents the client identifier. The parameters must not benullandapplication/x-www-form-urlencodedencoded.- Returns:
- The client identifier,
nullif not specified.
-
parse
Parses the specified HTTP request for a JSON Web Token (JWT) based client authentication.- Parameters:
httpRequest- The HTTP request to parse. Must not benull.- Returns:
- The JSON Web Token (JWT) based client authentication.
- Throws:
ParseException- If a JSON Web Token (JWT) based client authentication couldn't be retrieved from the HTTP request.
-