atproto_client 0.1.1 → 0.1.2

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: fae0f06cac47326857a9f23ace154e87ed093cfc1354d3e090c7ec451a40569b
4
- data.tar.gz: 5aeaf113c2dc1626dc8432a6b01e53f0522b847fd4202bea3401c001fe658e84
3
+ metadata.gz: cbbb4053b1b25b1d1d3d37a6ae736570dd8d1bd097d69fde6d7868015fa45ac1
4
+ data.tar.gz: 0a8cd5beac57a16b965aa7d5487a4896887d820ed012e7526091e28054111c1a
5
5
  SHA512:
6
- metadata.gz: 91e625cb794c5218b0997fb07034abad8c1e6ff4b8439adea1cd98f33ff38d78e656e68a9ef11c96fc93af4c5b14ae0068990e72e4cb8785c15ebeed15edf936
7
- data.tar.gz: 8c9c66ab87340103a6e90a3ab5f90aef366d32fd6f1e8c099fcc03d760962d10d294234340f7de17ffbb683229c79723aa090f4ce2106ecff11e7847bdd0a748
6
+ metadata.gz: eac347a2e5d30aa247d1ae27c16aa5df76ee581945c0af5c3cb1fe31575332687b662a9105470ed5634c8912b041b83ed36f0fd5ca6248d44fde387918c0ba87
7
+ data.tar.gz: 1711570172c8f61c617784c886386b6f2afe7b71c4435e1e353bab7314e1ae3651c64a661526f27915bfa9494e52c897e913c2bf804b8d01bb826d06280da006
@@ -17,7 +17,7 @@ module AtProto
17
17
  @dpop_handler.make_request(
18
18
  uri.to_s,
19
19
  method,
20
- headers: { 'Authorization' => "Bearer #{@access_token}" },
20
+ headers: { 'Authorization' => "DPoP #{@access_token}" },
21
21
  body: body
22
22
  )
23
23
  rescue TokenExpiredError => e
@@ -3,11 +3,13 @@ module AtProto
3
3
  class DpopHandler
4
4
  # Initialize a new DPoP handler
5
5
  # @param private_key [OpenSSL::PKey::EC, nil] Optional private key for signing tokens
6
- def initialize(private_key = nil)
6
+ # @param access_token [String] Optional access_token
7
+ def initialize(private_key = nil, access_token = nil)
7
8
  @private_key = private_key || generate_private_key
8
9
  @current_nonce = nil
9
10
  @nonce_mutex = Mutex.new
10
11
  @token_mutex = Mutex.new
12
+ @access_token = access_token
11
13
  end
12
14
 
13
15
  # Generates a DPoP token for a request
@@ -72,6 +74,15 @@ module AtProto
72
74
  exp: Time.now.to_i + 120
73
75
  }
74
76
 
77
+ # Ajout du hachage du token d'accès si fourni
78
+ if @access_token
79
+ token_str = @access_token.to_s
80
+ sha256 = OpenSSL::Digest.new('SHA256')
81
+ hash_bytes = sha256.digest(token_str)
82
+ ath = Base64.urlsafe_encode64(hash_bytes, padding: false)
83
+ payload[:ath] = ath
84
+ end
85
+
75
86
  payload[:nonce] = nonce if nonce
76
87
 
77
88
  JWT.encode(payload, @private_key, 'ES256', { typ: 'dpop+jwt', alg: 'ES256', jwk: jwk })
@@ -59,11 +59,9 @@ module AtProto
59
59
 
60
60
  def handle_response(response)
61
61
  case response.code.to_i
62
- when 400
62
+ when 400..499
63
63
  body = JSON.parse(response.body)
64
64
  response.error! if body['error'] == 'use_dpop_nonce'
65
- when 401
66
- body = JSON.parse(response.body)
67
65
  raise TokenExpiredError if body['error'] == 'TokenExpiredError'
68
66
 
69
67
  raise AuthError, "Unauthorized: #{body['error']}"
@@ -1,3 +1,3 @@
1
1
  module AtProto
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atproto_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - frabr