passkeys-rails 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2eb3101d4ecba95639b4cc95adfa6a86939b7bdc3e6db0e3c26ed9e154d9fa97
4
- data.tar.gz: 86cc744ced315cb5a662743f2cbf44fa20a05f7fbe444103b62a82281b009edd
3
+ metadata.gz: c1967aeb595e4864973402bf8108fe5a56b668678b8ed56aafbc403b164c628d
4
+ data.tar.gz: c96c2cd39bedbc138c1cd35248432d9cf7626c5a96007b91981741eb6f56e478
5
5
  SHA512:
6
- metadata.gz: f2b55ac5a4aea2f969ab32cff126f6cab53f2a0b819a998668d58b794231a4f6ca378247af0e2561fbf0062760ea0724641c36b4915c2bd2a9f24aedf2909a23
7
- data.tar.gz: 115f5c9c098da302f13d45e6871ae0152a8bd454d4d5281effc29afcc7e1dfacf0b838322bb55ff5f9b17caf2f846917e1596c0f8e4fc8a525bf710e986e7a5f
6
+ metadata.gz: 3eb9182122196e3c94b5ebb78b0984785c39fb194b6d7f5f95432eb63e53482be0190fe24bc2af914a38377ee1a82df80932b11c16f918d155fdbaa731b5a052
7
+ data.tar.gz: e16475967c805796248fb3188667456e31fd833f841b98d16c28a6b5964e59170d349a018580a5e1ab312f18f7a9f7f16693b612d70d97f6ce91a5a77a9e5db4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/passkeys-rails.svg?cachebust=4)](https://badge.fury.io/rb/passkeys-rails)
1
+ [![Gem Version](https://badge.fury.io/rb/passkeys-rails.svg?cachebust=5)](https://badge.fury.io/rb/passkeys-rails)
2
2
  [![Build Status](https://app.travis-ci.com/alliedcode/passkeys-rails.svg?branch=main)](https://travis-ci.org/alliedcode/passkeys-rails)
3
3
  [![codecov](https://codecov.io/gh/alliedcode/passkeys-rails/branch/main/graph/badge.svg?token=UHSNJDUL21)](https://codecov.io/gh/alliedcode/passkeys-rails)
4
4
 
@@ -9,21 +9,22 @@ module PasskeysRails
9
9
  end
10
10
 
11
11
  def current_agent
12
- return nil if request.headers['HTTP_X_AUTH'].blank?
13
-
14
- @current_agent ||= validated_auth_token&.success? && validated_auth_token&.agent
12
+ @current_agent ||= (request.headers['HTTP_X_AUTH'].present? &&
13
+ passkey_authentication_result.success? &&
14
+ passkey_authentication_result.agent.registered? &&
15
+ passkey_authentication_result.agent) || nil
15
16
  end
16
17
 
17
18
  def authenticate_passkey!
18
- return if validated_auth_token.success?
19
+ return if current_agent.present?
19
20
 
20
21
  raise PasskeysRails::Error.new(:authentication,
21
22
  code: :unauthorized,
22
23
  message: "You are not authorized to access this resource.")
23
24
  end
24
25
 
25
- def validated_auth_token
26
- @validated_auth_token ||= PasskeysRails::ValidateAuthToken.call(auth_token: request.headers['HTTP_X_AUTH'])
26
+ def passkey_authentication_result
27
+ @passkey_authentication_result ||= PasskeysRails::ValidateAuthToken.call(auth_token: request.headers['HTTP_X_AUTH'])
27
28
  end
28
29
  end
29
30
  end
@@ -5,14 +5,16 @@ module PasskeysRails
5
5
  delegate :username, to: :context
6
6
 
7
7
  def call
8
- agent = create_unregistered_agent
8
+ agent = create_or_replace_unregistered_agent
9
9
 
10
10
  context.options = WebAuthn::Credential.options_for_create(user: { id: agent.webauthn_identifier, name: agent.username })
11
11
  end
12
12
 
13
13
  private
14
14
 
15
- def create_unregistered_agent
15
+ def create_or_replace_unregistered_agent
16
+ Agent.unregistered.where(username:).destroy_all
17
+
16
18
  agent = Agent.create(username:, webauthn_identifier: WebAuthn.generate_user_id)
17
19
 
18
20
  context.fail!(code: :validation_errors, message: agent.errors.full_messages.to_sentence) unless agent.valid?
@@ -1,3 +1,3 @@
1
1
  module PasskeysRails
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.1.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passkeys-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Troy Anderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-23 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails