Skip to content

Add BearerTokenErrors #7823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jzheaux opened this issue Jan 13, 2020 · 0 comments
Closed

Add BearerTokenErrors #7823

jzheaux opened this issue Jan 13, 2020 · 0 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Milestone

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Jan 13, 2020

Because Bearer Token Error handling is based on a spec, there are only a few things that end up changing, depending on the kind of error.

For example, if we have an invalid_request, by default, we will always have a status code of 400, a uri pointing to that reference in the spec, and no scopes listed. Only the description is likely to change.

If we have an invalid_token, then the same is true, just changing the status code.

It would be nice to have a simple class like:

public final class BearerTokenErrors {
    public static BearerTokenError invalidRequest(String message) {
        return new BearerTokenError(
            BearerTokenErrorCode.INVALID_REQUEST,
            HttpStatus.BAD_REQUEST,
            message,
            "https://tools.ietf.org/html/rfc6750#section-3.1");
    }

    public static BearerTokenError invalidToken(String message) { .... }

    public static BearerTokenError insufficientScope(String message, String scope) {
        return new BearerTokenError(
            BearerTokenErrorCode.INSUFFICIENT_SCOPE,
            HttpStatus.FORBIDDEN, 
            message
            "https://tools.ietf.org/html/rfc6750#section-3.1",
            scope);
    }
}

This would clean up code in JwtAuthenticationProvider, DefaultBearerTokenResolver, and several others. Generally, it would also help users to create spec compliant errors.

@jzheaux jzheaux added type: enhancement A general enhancement in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) labels Jan 13, 2020
@jzheaux jzheaux added this to the 5.3.0.RC1 milestone Jan 13, 2020
@jzheaux jzheaux self-assigned this Jan 13, 2020
@jzheaux jzheaux closed this as completed in 7b2fcd1 Feb 4, 2020
jzheaux added a commit that referenced this issue Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant