Skip to content

Commit

Permalink
Fix incorrect PKCE code challenge generation (#452)
Browse files Browse the repository at this point in the history
This PR fixes the PKCE code challenge generation; the correct method the API wants is for us to base64 encode the hex string as opposed to base64 encoding resulting hashed bytearray directly.
  • Loading branch information
mrashed-dev authored Jan 8, 2024
1 parent 6bc2732 commit eaa17a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 6.0.0-beta.4 / TBD
* Fixed list and find scheduled messages
* Fixed incorrect PKCE code challenge generation

### 6.0.0-beta.3 / 2024-01-04
* **BREAKING CHANGE**: Moved grants API out of `Auth` to `NylasClient`
* **BREAKING CHANGE**: Moved `Grants.create()` to `Auth.customAuthentication()`
Expand Down
10 changes: 5 additions & 5 deletions lib/nylas/resources/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit eaa17a0

Please sign in to comment.