Skip to content

Commit

Permalink
Merge pull request #7 from cedarcode/fix_regisration_payload_encoding
Browse files Browse the repository at this point in the history
Fix registration payload encoding
  • Loading branch information
grzuy committed May 21, 2018
2 parents 114732d + 224bde8 commit e065abc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/webauthn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ module WebAuthn
def self.registration_payload
{
publicKey: {
challenge: SecureRandom.random_bytes(16),
challenge: Base64.urlsafe_encode64(SecureRandom.random_bytes(16)),
pubKeyCredParams: [ES256_ALGORITHM],
rp: { name: RP_NAME },
user: { name: USER_NAME, displayName: USER_NAME, id: Base64.encode64(USER_ID) }
user: { name: USER_NAME, displayName: USER_NAME, id: Base64.urlsafe_encode64(USER_ID) }
}
}
end
Expand Down
5 changes: 3 additions & 2 deletions spec/webauthn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
end

it "has a 16 byte length challenge" do
expect(@payload[:publicKey][:challenge].length).to eq(16)
original_challenge = Base64.urlsafe_decode64(@payload[:publicKey][:challenge])
expect(original_challenge.length).to eq(16)
end

it "has public key params" do
Expand All @@ -25,7 +26,7 @@
user_info = @payload[:publicKey][:user]
expect(user_info[:name]).to eq("web-user")
expect(user_info[:displayName]).to eq("web-user")
expect(user_info[:id]).to eq("MQ==\n")
expect(user_info[:id]).to eq("MQ==")
end
end

Expand Down

0 comments on commit e065abc

Please sign in to comment.