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_EXPIRATION_LEEWAY =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ JwtPayload

Returns a new instance of JwtPayload.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shopify_api/auth/jwt_payload.rb', line 18

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.



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

def aud
  @aud
end

#destObject (readonly)

Returns the value of attribute dest.



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

def dest
  @dest
end

#expObject (readonly)

Returns the value of attribute exp.



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

def exp
  @exp
end

#iatObject (readonly)

Returns the value of attribute iat.



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

def iat
  @iat
end

#issObject (readonly)

Returns the value of attribute iss.



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

def iss
  @iss
end

#jtiObject (readonly)

Returns the value of attribute jti.



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

def jti
  @jti
end

#nbfObject (readonly)

Returns the value of attribute nbf.



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

def nbf
  @nbf
end

#sidObject (readonly)

Returns the value of attribute sid.



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

def sid
  @sid
end

#subObject (readonly)

Returns the value of attribute sub.



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

def sub
  @sub
end

Instance Method Details

#==(other) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/shopify_api/auth/jwt_payload.rb', line 58

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



56
# File 'lib/shopify_api/auth/jwt_payload.rb', line 56

alias_method :eql?, :==

#shopObject



42
43
44
# File 'lib/shopify_api/auth/jwt_payload.rb', line 42

def shop
  @dest.gsub("https://", "")
end

#validate_shop(shop) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/shopify_api/auth/jwt_payload.rb', line 48

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