Class: ShopifyAPI::Auth::JwtPayload

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#audObject (readonly)

Returns the value of attribute aud.



13
14
15
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13

def aud
  @aud
end

#destObject (readonly)

Returns the value of attribute dest.



13
14
15
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13

def dest
  @dest
end

#expObject (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

#iatObject (readonly)

Returns the value of attribute iat.



16
17
18
# File 'lib/shopify_api/auth/jwt_payload.rb', line 16

def iat
  @iat
end

#issObject (readonly)

Returns the value of attribute iss.



13
14
15
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13

def iss
  @iss
end

#jtiObject (readonly)

Returns the value of attribute jti.



13
14
15
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13

def jti
  @jti
end

#nbfObject (readonly)

Returns the value of attribute nbf.



16
17
18
# File 'lib/shopify_api/auth/jwt_payload.rb', line 16

def nbf
  @nbf
end

#sidObject (readonly)

Returns the value of attribute sid.



13
14
15
# File 'lib/shopify_api/auth/jwt_payload.rb', line 13

def sid
  @sid
end

#subObject (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?, :==

#shopObject 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_idObject



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