From e8cdc766ae36675457845fb6f049e4f701c00300 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:17:58 -0500 Subject: [PATCH] convert hashed string to hex before b64 --- lib/nylas/resources/auth.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/nylas/resources/auth.rb b/lib/nylas/resources/auth.rb index 3d3e66e0..e2ed1a51 100644 --- a/lib/nylas/resources/auth.rb +++ b/lib/nylas/resources/auth.rb @@ -171,13 +171,13 @@ def build_query(config) URI.encode_www_form(params) end - # Hashes the secret for PKCE authentication. + # Hash a plain text secret for use in PKCE. # - # @param secret [String] Randomly-generated authentication secret. - # @return [Hash] Hashed authentication secret. + # @param secret [String] The plain text secret to hash. + # @return [String] The hashed secret with base64 encoding (without padding). def hash_pkce_secret(secret) - Digest::SHA256.digest(secret).unpack1("H*") - Base64.strict_encode64(Digest::SHA256.digest(secret)) + sha256_hash = Digest::SHA256.hexdigest(secret) + Base64.urlsafe_encode64(sha256_hash, padding: false) end # Sends the token request to the Nylas API.