Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v5.0.3
- Patch API token auth to check user's status

## v5.0.2
- Bump Ruby to v3.1.4 and use `.ruby-version` in CI
- [#3566](https://github.com/DMPRoadmap/roadmap/pull/3566)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/api/v0/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def authenticate_token
else
@token = token
@user = User.find_by(api_token: token)
# if no user found, return false, otherwise true
!@user.nil? && @user.can_use_api?
@user.present? && @user.active? && @user.can_use_api?
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions app/services/api/v1/auth/jwt/authorization_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def call

private

# Lookup the Client bassed on the client_id embedded in the JWT
# Lookup the Client based on the client_id embedded in the JWT
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
def client
return @api_client if @api_client.present?
Expand All @@ -33,7 +33,10 @@ def client
@api_client = ApiClient.where(client_id: token[:client_id]).first
return @api_client if @api_client.present?

@api_client = User.where(email: token[:client_id]).first
# Valid if User is active, has permission to use the API and
# the :client_secret matches the token
usr = User.where(email: token[:client_id], active: true, api_token: @client_secret).first

@gjacob24 gjacob24 Aug 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronskiba or @momo3404, could one of you check if this fix for v1 works in your local instance please?
I think it needs to be usr = User.where(email: token[:client_id], active: true).first, without the api_token: @client_secret, but I'm not sure.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're correct, the line in the PR with api_token: @client_secret did work in revoking access to the API for the deactivated user when I tested, but it did not allow the user to continue to use the API after they were reactivated. When removing api_token: @client_secret, it worked as expected. Let me know if this is what you saw as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok. I've removed that constraint from the query

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks both!

@api_client = usr.present? && usr.can_use_api? ? usr : nil
end
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity

Expand Down
Loading