-
Notifications
You must be signed in to change notification settings - Fork 482
Make sub and sid jwt claims optional #1369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4bc8538
190fc74
a14a221
a84c930
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,14 @@ class JwtPayload | |
| JWT_EXPIRATION_LEEWAY = JWT_LEEWAY | ||
|
|
||
| sig { returns(String) } | ||
| attr_reader :iss, :dest, :aud, :sub, :jti, :sid | ||
| attr_reader :iss, :dest, :aud, :jti | ||
|
|
||
| sig { returns(Integer) } | ||
| attr_reader :exp, :nbf, :iat | ||
|
|
||
| sig { returns(T.nilable(String)) } | ||
| attr_reader :sub, :sid | ||
|
|
||
| alias_method :expire_at, :exp | ||
|
|
||
| sig { params(token: String).void } | ||
|
|
@@ -30,12 +33,12 @@ def initialize(token) | |
| @iss = T.let(payload_hash["iss"], String) | ||
| @dest = T.let(payload_hash["dest"], String) | ||
| @aud = T.let(payload_hash["aud"], String) | ||
| @sub = T.let(payload_hash["sub"], String) | ||
| @sub = T.let(payload_hash["sub"], T.nilable(String)) | ||
| @exp = T.let(payload_hash["exp"], Integer) | ||
| @nbf = T.let(payload_hash["nbf"], Integer) | ||
| @iat = T.let(payload_hash["iat"], Integer) | ||
| @jti = T.let(payload_hash["jti"], String) | ||
| @sid = T.let(payload_hash["sid"], String) | ||
| @sid = T.let(payload_hash["sid"], T.nilable(String)) | ||
|
|
||
| raise ShopifyAPI::Errors::InvalidJwtTokenError, | ||
| "Session token had invalid API key" unless @aud == Context.api_key | ||
|
|
@@ -47,19 +50,9 @@ def shop | |
| end | ||
| alias_method :shopify_domain, :shop | ||
|
|
||
| sig { returns(Integer) } | ||
| sig { returns(T.nilable(Integer)) } | ||
| def shopify_user_id | ||
| @sub.to_i | ||
| end | ||
|
|
||
| # TODO: Remove before releasing v11 | ||
| sig { params(shop: String).returns(T::Boolean) } | ||
| def validate_shop(shop) | ||
| Context.logger.warn( | ||
| "Deprecation notice: ShopifyAPI::Auth::JwtPayload.validate_shop no longer checks the given shop and always " \ | ||
| "returns true. It will be removed in v11.", | ||
| ) | ||
| true | ||
| @sub.to_i if user_id_sub? && admin_session_token? | ||
| end | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can this work? If the @lizkenyon I think this is the answer to your question here: https://github.com/Shopify/shopify-api-ruby/pull/1346/files#r1831667330 |
||
|
|
||
| alias_method :eql?, :== | ||
|
|
@@ -86,6 +79,16 @@ def decode_token(token, api_secret_key) | |
| rescue JWT::DecodeError => err | ||
| raise ShopifyAPI::Errors::InvalidJwtTokenError, "Error decoding session token: #{err.message}" | ||
| end | ||
|
|
||
| sig { returns(T::Boolean) } | ||
| def admin_session_token? | ||
| @iss.end_with?("/admin") | ||
| end | ||
|
|
||
| sig { returns(T::Boolean) } | ||
| def user_id_sub? | ||
| @sub&.match?(/\A\d+\z/) || false | ||
| end | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.