Class: ShopifyAPI::Auth::JwtPayload
- Inherits:
-
Object
- Object
- ShopifyAPI::Auth::JwtPayload
- Extended by:
- T::Sig
- Defined in:
- lib/shopify_api/auth/jwt_payload.rb
Constant Summary collapse
- JWT_LEEWAY =
10
- JWT_EXPIRATION_LEEWAY =
JWT_LEEWAY
Instance Attribute Summary collapse
-
#aud ⇒ Object
readonly
Returns the value of attribute aud.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#exp ⇒ Object
(also: #expire_at)
readonly
Returns the value of attribute exp.
-
#iat ⇒ Object
readonly
Returns the value of attribute iat.
-
#iss ⇒ Object
readonly
Returns the value of attribute iss.
-
#jti ⇒ Object
readonly
Returns the value of attribute jti.
-
#nbf ⇒ Object
readonly
Returns the value of attribute nbf.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql? ⇒ Object
-
#initialize(token) ⇒ JwtPayload
constructor
A new instance of JwtPayload.
- #shop ⇒ Object (also: #shopify_domain)
- #shopify_user_id ⇒ Object
- #validate_shop(shop) ⇒ Object
Constructor Details
#initialize(token) ⇒ JwtPayload
Returns a new instance of JwtPayload.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 21 def initialize(token) payload_hash = begin decode_token(token, Context.api_secret_key) rescue ShopifyAPI::Errors::InvalidJwtTokenError raise unless Context.old_api_secret_key decode_token(token, T.must(Context.old_api_secret_key)) end @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) @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) raise ShopifyAPI::Errors::InvalidJwtTokenError, "Session token had invalid API key" unless @aud == Context.api_key end |
Instance Attribute Details
#aud ⇒ Object (readonly)
Returns the value of attribute aud.
13 14 15 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13 def aud @aud end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
13 14 15 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13 def dest @dest end |
#exp ⇒ Object (readonly) Also known as: expire_at
Returns the value of attribute exp.
16 17 18 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 16 def exp @exp end |
#iat ⇒ Object (readonly)
Returns the value of attribute iat.
16 17 18 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 16 def iat @iat end |
#iss ⇒ Object (readonly)
Returns the value of attribute iss.
13 14 15 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13 def iss @iss end |
#jti ⇒ Object (readonly)
Returns the value of attribute jti.
13 14 15 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13 def jti @jti end |
#nbf ⇒ Object (readonly)
Returns the value of attribute nbf.
16 17 18 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 16 def nbf @nbf end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
13 14 15 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13 def sid @sid end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
13 14 15 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13 def sub @sub end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 67 def ==(other) return false unless other iss == other.iss && dest == other.dest && aud == other.aud && sub == other.sub && exp == other.exp && nbf == other.nbf && iat == other.iat && jti == other.jti && sid == other.sid end |
#eql? ⇒ Object
65 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 65 alias_method :eql?, :== |
#shop ⇒ Object Also known as: shopify_domain
45 46 47 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 45 def shop @dest.gsub("https://", "") end |
#shopify_user_id ⇒ Object
51 52 53 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 51 def shopify_user_id @sub.to_i end |
#validate_shop(shop) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/shopify_api/auth/jwt_payload.rb', line 57 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 end |