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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shopify_api/auth/jwt_payload.rb', line 24

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"], 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"], T.nilable(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.



19
20
21
# File 'lib/shopify_api/auth/jwt_payload.rb', line 19

def sid
  @sid
end

#subObject (readonly)

Returns the value of attribute sub.



19
20
21
# File 'lib/shopify_api/auth/jwt_payload.rb', line 19

def sub
  @sub
end

Instance Method Details

#==(other) ⇒ Object



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

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



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

alias_method :eql?, :==

#shopObject Also known as: shopify_domain



48
49
50
# File 'lib/shopify_api/auth/jwt_payload.rb', line 48

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

#shopify_user_idObject



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

def shopify_user_id
  @sub.to_i if user_id_sub? && admin_session_token?
end