Skip to content

Commit 190fc74

Browse files
committed
Make shopify_user_id returns the user id if the session is generated from the admin and the sub claim is an user id
1 parent 4bc8538 commit 190fc74

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/shopify_api/auth/jwt_payload.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def shop
4949

5050
sig { returns(T.nilable(Integer)) }
5151
def shopify_user_id
52-
return unless @sub
53-
54-
@sub.tr("^0-9", "").to_i
52+
@sub.to_i if user_id_sub? && admin_session_token?
5553
end
5654

5755
alias_method :eql?, :==
@@ -78,6 +76,16 @@ def decode_token(token, api_secret_key)
7876
rescue JWT::DecodeError => err
7977
raise ShopifyAPI::Errors::InvalidJwtTokenError, "Error decoding session token: #{err.message}"
8078
end
79+
80+
sig { returns(T::Boolean) }
81+
def admin_session_token?
82+
@iss.end_with?("/admin")
83+
end
84+
85+
sig { returns(T::Boolean) }
86+
def user_id_sub?
87+
@sub&.match?(/\A\d+\z/) || false
88+
end
8189
end
8290
end
8391
end

0 commit comments

Comments
 (0)