Skip to content

Commit e6fc2bb

Browse files
committed
fix issue with API token auth
1 parent f7bcd33 commit e6fc2bb

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v5.0.3
4+
- Patch API token auth to check user's status
5+
36
## v5.0.2
47
- Bump Ruby to v3.1.4 and use `.ruby-version` in CI
58
- [#3566](https://github.com/DMPRoadmap/roadmap/pull/3566)

‎app/services/api/v1/auth/jwt/authorization_service.rb‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def call
1919

2020
private
2121

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

36-
@api_client = User.where(email: token[:client_id]).first
36+
# Valid if User is active, has permission to use the API and
37+
# the :client_secret matches the token
38+
usr = User.where(email: token[:client_id], active: true, api_token: @client_secret).first
39+
@api_client = usr.present? && usr.can_use_api? ? usr : nil
3740
end
3841
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
3942

0 commit comments

Comments
 (0)