Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

JWT decode fix #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PATH
specs:
marketingcloudsdk (1.0.0)
json (~> 1.8, >= 1.8.1)
jwt (~> 1.0, >= 1.0.0)
jwt (~> 1.0, >= 1.5.4)
savon (= 2.2.0)

GEM
Expand All @@ -12,56 +12,58 @@ GEM
akami (1.2.2)
gyoku (>= 0.4.0)
nokogiri
builder (3.2.2)
coderay (1.0.9)
diff-lcs (1.2.4)
ffi (1.9.0-x86-mingw32)
formatador (0.2.4)
guard (1.8.2)
builder (3.2.3)
coderay (1.1.1)
diff-lcs (1.3)
ffi (1.9.18)
ffi (1.9.18-x86-mingw32)
formatador (0.2.5)
guard (1.8.3)
formatador (>= 0.2.4)
listen (>= 1.0.0)
listen (~> 1.3)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-rspec (2.0.0)
guard (>= 1.1)
rspec (~> 2.11)
guard-rspec (2.6.0)
guard (>= 1.8)
rspec (~> 2.13)
gyoku (1.0.0)
builder (>= 2.1.2)
httpi (2.0.2)
rack
json (1.8.1)
json (1.8.6)
jwt (1.5.6)
listen (1.3.0)
listen (1.3.1)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
rb-kqueue (>= 0.2)
lumberjack (1.0.4)
lumberjack (1.0.12)
method_source (0.8.2)
mini_portile2 (2.1.0)
nokogiri (1.6.8.1-x86-mingw32)
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
nokogiri (1.7.2-x86-mingw32)
mini_portile2 (~> 2.1.0)
nori (2.1.0)
pry (0.9.10-x86-mingw32)
coderay (~> 1.0.5)
method_source (~> 0.8)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
win32console (~> 1.3)
rack (2.0.1)
rack (2.0.3)
rake (0.9.6)
rb-fsevent (0.9.3)
rb-inotify (0.9.1)
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
rb-kqueue (0.2.0)
rb-kqueue (0.2.5)
ffi (>= 0.5.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.5)
rspec-expectations (2.14.2)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.3)
rspec-mocks (2.99.4)
savon (2.2.0)
akami (~> 1.2.0)
builder (>= 2.1.2)
Expand All @@ -70,14 +72,14 @@ GEM
nokogiri (>= 1.4.0)
nori (~> 2.1.0)
wasabi (~> 3.1.0)
slop (3.4.6)
thor (0.18.1)
slop (3.6.0)
thor (0.19.4)
wasabi (3.1.0)
httpi (~> 2.0)
nokogiri (>= 1.4.0)
win32console (1.3.2-x86-mingw32)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
Expand All @@ -89,4 +91,4 @@ DEPENDENCIES
rspec (~> 2.0)

BUNDLED WITH
1.13.5
1.13.6
18 changes: 12 additions & 6 deletions lib/marketingcloudsdk/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ class Client

def jwt= encoded_jwt
raise 'Require app signature to decode JWT' unless self.signature
decoded_jwt = JWT.decode(encoded_jwt, self.signature, true)
decoded_jwt = JWT.decode(encoded_jwt, self.signature, true)[0]

self.auth_token = decoded_jwt['request']['user']['oauthToken']
self.internal_token = decoded_jwt['request']['user']['internalOauthToken']
self.refresh_token = decoded_jwt['request']['user']['refreshToken']
self.auth_token_expiration = Time.new + decoded_jwt['request']['user']['expiresIn']
self.package_name = decoded_jwt['request']['application']['package']
if decoded_jwt['request']['claimsVersion'] == 2
self.refresh_token = decoded_jwt['request']['rest']['refreshToken']
self.auth_token_expiration = Time.at(decoded_jwt['exp'])
self.package_name = decoded_jwt['request']['application']['package']
else
self.auth_token = decoded_jwt['request']['user']['oauthToken']
self.internal_token = decoded_jwt['request']['user']['internalOauthToken']
self.refresh_token = decoded_jwt['request']['user']['refreshToken']
self.auth_token_expiration = Time.new + decoded_jwt['request']['user']['expiresIn']
self.package_name = decoded_jwt['request']['application']['package']
end
end

def initialize(params={}, debug=false)
Expand Down
2 changes: 1 addition & 1 deletion marketingcloudsdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Gem::Specification.new do |spec|

spec.add_dependency "savon", "2.2.0"
spec.add_dependency "json", "~>1.8",">= 1.8.1"
spec.add_dependency "jwt", "~>1.0",">= 1.0.0"
spec.add_dependency "jwt", "~>1.0",">= 1.5.4"
end