Skip to content

Commit

Permalink
Merge pull request #161 from XeroAPI/validate_on_callback
Browse files Browse the repository at this point in the history
Optimise the jwt_validation code
  • Loading branch information
SerKnight authored May 3, 2021
2 parents f7b7d55 + 743bf52 commit 0aebca7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions lib/xero-ruby/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def id_token
end

def decoded_access_token
decode_jwt(@config.access_token)
decode_jwt(@config.access_token, false)
end

def decoded_id_token
decode_jwt(@config.id_token)
decode_jwt(@config.id_token, false)
end

def set_token_set(token_set)
Expand Down Expand Up @@ -166,10 +166,14 @@ def validate_state(params)
return true
end

def decode_jwt(tkn)
jwks_data = JSON.parse(Faraday.get('https://identity.xero.com/.well-known/openid-configuration/jwks').body)
jwk_set = JSON::JWK::Set.new(jwks_data)
JSON::JWT.decode(tkn, jwk_set)
def decode_jwt(tkn, verify=true)
if verify == true
jwks_data = JSON.parse(Faraday.get('https://identity.xero.com/.well-known/openid-configuration/jwks').body)
jwk_set = JSON::JWK::Set.new(jwks_data)
JSON::JWT.decode(tkn, jwk_set)
else
JSON::JWT.decode(tkn, :skip_verification)
end
end

def token_expired?
Expand Down
2 changes: 1 addition & 1 deletion lib/xero-ruby/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
=end

module XeroRuby
VERSION = '2.10.1'
VERSION = '2.10.2'
end

0 comments on commit 0aebca7

Please sign in to comment.