001/*
002 * Copyright 2026 Revetware LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.revetsec.oauth;
018
019import org.jspecify.annotations.NonNull;
020import javax.annotation.concurrent.Immutable;
021
022/**
023 * RFC 6750 section 3.1 bearer errors and their recommended HTTP status codes.
024 * Missing credentials use a 401 challenge without an error; application permission decisions select
025 * insufficient_scope. Later releases may add values, so switches need a default branch.
026 *
027 * @author <a href="https://www.revetkn.com">Mark Allen</a>
028 * @since 1.0.0
029 */
030@Immutable
031public enum BearerError {
032        /** The credential presentation is malformed. */
033        INVALID_REQUEST(400, "invalid_request"),
034        /** The presented credential was rejected. */
035        INVALID_TOKEN(401, "invalid_token"),
036        /** The app requires permissions not granted by the token. */
037        INSUFFICIENT_SCOPE(403, "insufficient_scope");
038
039        private final @NonNull Integer statusCode;
040        private final @NonNull String wireValue;
041        BearerError(@NonNull Integer statusCode, @NonNull String wireValue) {
042                this.statusCode = statusCode; this.wireValue = wireValue;
043        }
044        /**
045         * Returns the recommended HTTP status code.
046         * @return the status code
047         * @since 1.0.0
048         */
049        public @NonNull Integer getStatusCode() { return this.statusCode; }
050        /**
051         * Returns the protocol error value.
052         * @return the wire value
053         * @since 1.0.0
054         */
055        public @NonNull String getWireValue() { return this.wireValue; }
056}