Skip to content

Commit 96be21d

Browse files
committed
fix: make sub and sid jwt claims optional
The generated session token on the checkout ui extensions doesn't contain: - The `sid` claim - The `sub` claim if the customer is not logged in Making them mandatory causes an `Expected type String, got type NilClass` error
1 parent b2836db commit 96be21d

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

lib/shopify_api/auth/jwt_payload.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def initialize(token)
3030
@iss = T.let(payload_hash["iss"], String)
3131
@dest = T.let(payload_hash["dest"], String)
3232
@aud = T.let(payload_hash["aud"], String)
33-
@sub = T.let(payload_hash["sub"], String)
33+
@sub = T.let(payload_hash["sub"], T.nilable(String))
3434
@exp = T.let(payload_hash["exp"], Integer)
3535
@nbf = T.let(payload_hash["nbf"], Integer)
3636
@iat = T.let(payload_hash["iat"], Integer)
3737
@jti = T.let(payload_hash["jti"], String)
38-
@sid = T.let(payload_hash["sid"], String)
38+
@sid = T.let(payload_hash["sid"], T.nilable(String))
3939

4040
raise ShopifyAPI::Errors::InvalidJwtTokenError,
4141
"Session token had invalid API key" unless @aud == Context.api_key
@@ -52,16 +52,6 @@ def shopify_user_id
5252
@sub.to_i
5353
end
5454

55-
# TODO: Remove before releasing v11
56-
sig { params(shop: String).returns(T::Boolean) }
57-
def validate_shop(shop)
58-
Context.logger.warn(
59-
"Deprecation notice: ShopifyAPI::Auth::JwtPayload.validate_shop no longer checks the given shop and always " \
60-
"returns true. It will be removed in v11.",
61-
)
62-
true
63-
end
64-
6555
alias_method :eql?, :==
6656
sig { params(other: T.nilable(JwtPayload)).returns(T::Boolean) }
6757
def ==(other)

0 commit comments

Comments
 (0)