com.nimbusds.oauth2.sdk.token
Class BearerTokenError

java.lang.Object
  extended by com.nimbusds.oauth2.sdk.ErrorObject
      extended by com.nimbusds.oauth2.sdk.token.BearerTokenError

@Immutable
public class BearerTokenError
extends ErrorObject

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:

Version:
$version$ (2013-01-30)
Author:
Vladimir Dzhuvinov

Field Summary
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 Summary
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, URL 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
 String getRealm()
          Gets the realm.
 Scope getScope()
          Gets the required scope.
static BearerTokenError parse(String wwwAuth)
          Parses an OAuth 2.0 bearer token error from the specified HTTP response WWW-Authenticate header.
 BearerTokenError setRealm(String realm)
          Sets the realm.
 BearerTokenError setScope(Scope scope)
          Sets the required scope.
 String toWWWAuthenticateHeader()
          Returns the WWW-Authenticate HTTP response header code for this bearer access token error response.
 
Methods inherited from class com.nimbusds.oauth2.sdk.ErrorObject
appendDescription, equals, getCode, getDescription, getHTTPStatusCode, getURI, hashCode, setDescription, setHTTPStatusCode, setURI, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MISSING_TOKEN

public static final BearerTokenError 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

public static final 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. The HTTP status code is set to 400 (Bad Request).


INVALID_TOKEN

public static final BearerTokenError 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

public static final BearerTokenError INSUFFICIENT_SCOPE
The request requires higher privileges than provided by the access token. The HTTP status code is set to 403 (Forbidden).

Constructor Detail

BearerTokenError

public BearerTokenError(String code,
                        String description)
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

public 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.

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,
                        URL 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 Detail

getRealm

public String getRealm()
Gets the realm.

Returns:
The realm, null if not specified.

setRealm

public BearerTokenError setRealm(String realm)
Sets the realm.

Parameters:
realm - realm, null if not specified.
Returns:
A copy of this error with the specified realm.

getScope

public Scope getScope()
Gets the required scope.

Returns:
The required scope, null if not specified.

setScope

public BearerTokenError setScope(Scope scope)
Sets the required scope.

Parameters:
scope - The required scope, null if not specified.
Returns:
A copy of this error with the specified required scope.

toWWWAuthenticateHeader

public String toWWWAuthenticateHeader()
Returns the 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"
 

Returns:
The Www-Authenticate header value.

parse

public static BearerTokenError parse(String wwwAuth)
                              throws ParseException
Parses an OAuth 2.0 bearer token error from the specified HTTP response WWW-Authenticate header.

Parameters:
wwwAuth - The WWW-Authenticate header value to parse. Must not be null.
Throws:
ParseException - If the WWW-Authenticate header value couldn't be parsed to a Bearer token error.


Copyright © 2013 NimbusDS. All Rights Reserved.