@Immutable public class BearerTokenError extends ErrorObject
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:
| Modifier and Type | Field | Description |
|---|---|---|
static BearerTokenError |
INSUFFICIENT_SCOPE |
The request requires higher privileges than provided by the access
token.
|
static BearerTokenError |
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.
|
static BearerTokenError |
INVALID_TOKEN |
The access token provided is expired, revoked, malformed, or invalid
for other reasons.
|
static BearerTokenError |
MISSING_TOKEN |
The request does not contain an access token.
|
| Constructor | Description |
|---|---|
BearerTokenError(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.
|
| Modifier and Type | Method | Description |
|---|---|---|
BearerTokenError |
appendDescription(String text) |
Appends the specified text to the error description.
|
String |
getRealm() |
Gets the realm.
|
Scope |
getScope() |
Gets the required scope.
|
static boolean |
isCodeWithValidChars(String errorCode) |
Returns
true if the specified error code consists of valid
characters. |
static boolean |
isDescriptionWithValidChars(String errorDescription) |
Returns
true if the specified error description consists of
valid characters. |
static boolean |
isScopeWithValidChars(Scope scope) |
Returns
true if the specified scope consists of valid
characters. |
static BearerTokenError |
parse(String wwwAuth) |
Parses an OAuth 2.0 bearer token error from the specified HTTP
response
WWW-Authenticate header. |
BearerTokenError |
setDescription(String description) |
Sets the error description.
|
BearerTokenError |
setHTTPStatusCode(int httpStatusCode) |
Sets the HTTP status code.
|
BearerTokenError |
setRealm(String realm) |
Sets the realm.
|
BearerTokenError |
setScope(Scope scope) |
Sets the required scope.
|
BearerTokenError |
setURI(URI uri) |
Sets the error page URI.
|
String |
toWWWAuthenticateHeader() |
Returns the
WWW-Authenticate HTTP response header code for
this bearer access token error response. |
equals, getCode, getDescription, getHTTPStatusCode, getURI, hashCode, parse, parse, toJSONObject, toStringpublic static final BearerTokenError MISSING_TOKEN
Example:
HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer
public static final BearerTokenError INVALID_REQUEST
public static final BearerTokenError INVALID_TOKEN
public static final BearerTokenError INSUFFICIENT_SCOPE
public BearerTokenError(String code, String description)
code - The error code, null if not specified.description - The error description, null if not
specified.public BearerTokenError(String code, String description, int httpStatusCode)
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.public BearerTokenError(String code, String description, int httpStatusCode, URI uri, String realm, Scope scope)
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.public static boolean isCodeWithValidChars(String errorCode)
true if the specified error code consists of valid
characters. Values for the "error" and "error_description"
attributes must not include characters outside the set %x20-21 /
%x23-5B / %x5D-7E. See RFC 6750, section 3.errorCode - The error code string.true if the error code string contains valid
characters, else false.public static boolean isDescriptionWithValidChars(String errorDescription)
true if the specified error description consists of
valid characters. Values for the "error" and "error_description"
attributes must not include characters outside the set %x20-21 /
%x23-5B / %x5D-7E. See RFC 6750, section 3.errorDescription - The error description string.true if the error description string contains valid
characters, else false.public static boolean isScopeWithValidChars(Scope scope)
true if the specified scope consists of valid
characters. Values for the "scope" attributes must not include
characters outside the set %x21 / %x23-5B / %x5D-7E. See RFC 6750,
section 3.scope - The scope.true if the scope contains valid characters, else
false.public BearerTokenError setDescription(String description)
ErrorObjectsetDescription in class ErrorObjectdescription - The error description, null if not
specified.public BearerTokenError appendDescription(String text)
ErrorObjectappendDescription in class ErrorObjecttext - The text to append to the error description,
null if not specified.public BearerTokenError setHTTPStatusCode(int httpStatusCode)
ErrorObjectsetHTTPStatusCode in class ErrorObjecthttpStatusCode - The HTTP status code, zero if not specified.public BearerTokenError setURI(URI uri)
ErrorObjectsetURI in class ErrorObjecturi - The error page URI, null if not specified.public BearerTokenError setRealm(String realm)
realm - realm, null if not specified.public Scope getScope()
null if not specified.public BearerTokenError setScope(Scope scope)
scope - The required scope, null if not specified.public String toWWWAuthenticateHeader()
WWW-Authenticate HTTP response header code for
this bearer access token error response.
Example:
Bearer realm="example.com", error="invalid_token", error_description="Invalid access token"
Www-Authenticate header value.public static BearerTokenError parse(String wwwAuth) throws ParseException
WWW-Authenticate header.wwwAuth - The WWW-Authenticate header value to parse.
Must not be null.ParseException - If the WWW-Authenticate header value
couldn't be parsed to a Bearer token error.Copyright © 2018 Connect2id Ltd.. All rights reserved.