Reject revoked OAuth tokens in API auth (#1711)

This commit is contained in:
Juan José Mata
2026-05-09 01:39:10 +02:00
committed by GitHub
parent 8abecf8a8d
commit b74014ab42
2 changed files with 18 additions and 1 deletions

View File

@@ -62,7 +62,7 @@ class Api::V1::BaseController < ApplicationController
# Check token validity and scope (read_write includes read access)
has_sufficient_scope = access_token&.scopes&.include?("read") || access_token&.scopes&.include?("read_write")
unless access_token && !access_token.expired? && has_sufficient_scope
unless access_token&.accessible? && has_sufficient_scope
render_json({ error: "unauthorized", message: "Access token is invalid, expired, or missing required scope" }, status: :unauthorized)
return false
end

View File

@@ -60,6 +60,23 @@ class Api::V1::BaseControllerTest < ActionDispatch::IntegrationTest
assert_equal @user.email, response_body["user"]
end
test "should reject revoked access token" do
access_token = Doorkeeper::AccessToken.create!(
application: @oauth_app,
resource_owner_id: @user.id,
scopes: "read"
)
access_token.revoke
get "/api/v1/test", params: {}, headers: {
"Authorization" => "Bearer #{access_token.token}"
}
assert_response :unauthorized
response_body = JSON.parse(response.body)
assert_equal "unauthorized", response_body["error"]
end
test "should reject invalid access token" do
get "/api/v1/test", params: {}, headers: {
"Authorization" => "Bearer invalid_token"