Package com.nimbusds.oauth2.sdk.token
Class BearerTokenError
java.lang.Object
com.nimbusds.oauth2.sdk.ErrorObject
com.nimbusds.oauth2.sdk.token.TokenSchemeError
com.nimbusds.oauth2.sdk.token.BearerTokenError
- All Implemented Interfaces:
Serializable
OAuth 2.0 bearer token error. Used to indicate that access to a resource
protected by a Bearer access token is denied, due to the request or token
being invalid, or due to the access token having insufficient scope.
Standard bearer access token errors:
Example HTTP response:
HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer realm="example.com", error="invalid_token", error_description="The access token expired"
Related specifications:
- OAuth 2.0 Bearer Token Usage (RFC 6750), section 3.1.
- Hypertext Transfer Protocol (HTTP/1.1): Authentication (RFC 7235), section 4.1.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BearerTokenError
The request requires higher privileges than provided by the access token.static final BearerTokenError
The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.static final BearerTokenError
The access token provided is expired, revoked, malformed, or invalid for other reasons.static final BearerTokenError
The request does not contain an access token. -
Constructor Summary
ConstructorsConstructorDescriptionBearerTokenError
(String code, String description) Creates a new OAuth 2.0 bearer token error with the specified code and description.BearerTokenError
(String code, String description, int httpStatusCode) Creates a new OAuth 2.0 bearer token error with the specified code, description and HTTP status code.BearerTokenError
(String code, String description, int httpStatusCode, URI uri, String realm, Scope scope) Creates a new OAuth 2.0 bearer token error with the specified code, description, HTTP status code, page URI, realm and scope. -
Method Summary
Modifier and TypeMethodDescriptionappendDescription
(String text) Appends the specified text to the error description.static BearerTokenError
Parses an OAuth 2.0 bearer token error from the specified HTTP responseWWW-Authenticate
header.setDescription
(String description) Sets the error description.setHTTPStatusCode
(int httpStatusCode) Sets the HTTP status code.Sets the realm.Sets the required scope.Sets the error page URI.Methods inherited from class com.nimbusds.oauth2.sdk.token.TokenSchemeError
getRealm, getScheme, getScope, isScopeWithValidChars, toWWWAuthenticateHeader
Methods inherited from class com.nimbusds.oauth2.sdk.ErrorObject
equals, getCode, getCustomParams, getDescription, getHTTPStatusCode, getURI, hashCode, isLegal, isLegal, parse, parse, parse, removeIllegalChars, setCustomParams, toHTTPResponse, toJSONObject, toParameters, toString
-
Field Details
-
MISSING_TOKEN
The request does not contain an access token. No error code or description is specified for this error, just the HTTP status code is set to 401 (Unauthorized).Example:
HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer
-
INVALID_REQUEST
The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed. The HTTP status code is set to 400 (Bad Request). -
INVALID_TOKEN
The access token provided is expired, revoked, malformed, or invalid for other reasons. The HTTP status code is set to 401 (Unauthorized). -
INSUFFICIENT_SCOPE
The request requires higher privileges than provided by the access token. The HTTP status code is set to 403 (Forbidden).
-
-
Constructor Details
-
BearerTokenError
Creates a new OAuth 2.0 bearer token error with the specified code and description.- Parameters:
code
- The error code,null
if not specified.description
- The error description,null
if not specified.
-
BearerTokenError
Creates a new OAuth 2.0 bearer token error with the specified code, description and HTTP status code.- Parameters:
code
- The error code,null
if not specified.description
- The error description,null
if not specified.httpStatusCode
- The HTTP status code, zero if not specified.
-
BearerTokenError
public BearerTokenError(String code, String description, int httpStatusCode, URI uri, String realm, Scope scope) Creates a new OAuth 2.0 bearer token error with the specified code, description, HTTP status code, page URI, realm and scope.- Parameters:
code
- The error code,null
if not specified.description
- The error description,null
if not specified.httpStatusCode
- The HTTP status code, zero if not specified.uri
- The error page URI,null
if not specified.realm
- The realm,null
if not specified.scope
- The required scope,null
if not specified.
-
-
Method Details
-
setDescription
Description copied from class:ErrorObject
Sets the error description.- Specified by:
setDescription
in classTokenSchemeError
- Parameters:
description
- The error description,null
if not specified.- Returns:
- A copy of this error with the specified description.
-
appendDescription
Description copied from class:ErrorObject
Appends the specified text to the error description.- Specified by:
appendDescription
in classTokenSchemeError
- Parameters:
text
- The text to append to the error description,null
if not specified.- Returns:
- A copy of this error with the specified appended description.
-
setHTTPStatusCode
Description copied from class:ErrorObject
Sets the HTTP status code.- Specified by:
setHTTPStatusCode
in classTokenSchemeError
- Parameters:
httpStatusCode
- The HTTP status code, zero if not specified.- Returns:
- A copy of this error with the specified HTTP status code.
-
setURI
Description copied from class:ErrorObject
Sets the error page URI.- Specified by:
setURI
in classTokenSchemeError
- Parameters:
uri
- The error page URI,null
if not specified.- Returns:
- A copy of this error with the specified page URI.
-
setRealm
Description copied from class:TokenSchemeError
Sets the realm.- Specified by:
setRealm
in classTokenSchemeError
- Parameters:
realm
- realm,null
if not specified.- Returns:
- A copy of this error with the specified realm.
-
setScope
Description copied from class:TokenSchemeError
Sets the required scope.- Specified by:
setScope
in classTokenSchemeError
- Parameters:
scope
- The required scope,null
if not specified.- Returns:
- A copy of this error with the specified required scope.
-
parse
Parses an OAuth 2.0 bearer token error from the specified HTTP responseWWW-Authenticate
header.- Parameters:
wwwAuth
- TheWWW-Authenticate
header value to parse. Must not benull
.- Returns:
- The bearer token error.
- Throws:
ParseException
- If theWWW-Authenticate
header value couldn't be parsed to a Bearer token error.
-