atproto_client 0.1.0 → 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: e459f2369670aec62ba641789c28a0e06e8c28892c11c490237388a99602f8d3
4
- data.tar.gz: 2795f534c54c0021a027699c6d58fa0f36b33680b80c060be0aff301d7fc3b73
3
+ metadata.gz: cbbb4053b1b25b1d1d3d37a6ae736570dd8d1bd097d69fde6d7868015fa45ac1
4
+ data.tar.gz: 0a8cd5beac57a16b965aa7d5487a4896887d820ed012e7526091e28054111c1a
5
5
  SHA512:
6
- metadata.gz: 92223d17916001ae87453c85de3f4cfb34877f77c11e5ff31991eca0a58b2a744bd21ab3381463e78b4c8a21db816b99887105d7651f9fde4091e25251eb7f5b
7
- data.tar.gz: 6b2fd5552ccfe4239345052892d03af7a36ac26d47536eab9f79b40980e369d8799ed44c0276b6de8f68fcece79e81e782fd0b2710c39ee55bd23b783468d7b0
6
+ metadata.gz: eac347a2e5d30aa247d1ae27c16aa5df76ee581945c0af5c3cb1fe31575332687b662a9105470ed5634c8912b041b83ed36f0fd5ca6248d44fde387918c0ba87
7
+ data.tar.gz: 1711570172c8f61c617784c886386b6f2afe7b71c4435e1e353bab7314e1ae3651c64a661526f27915bfa9494e52c897e913c2bf804b8d01bb826d06280da006
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # ATProto Client
2
2
 
3
3
  Ruby client for the AT Protocol, with support for oauth/dpop authentication. It has been built and tested for bluesky but it should be agnostic of PDS. An omniauth strategy using this layer should appear soon.
4
+ The work is in progress but it should allready work and I'd be happy to have feedbacks.
4
5
 
5
6
  ## Installation
6
7
 
@@ -45,7 +46,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
45
46
 
46
47
  ## Contributing
47
48
 
48
- Bug reports and pull requests are welcome on GitHub at https://github.com/lasercats/atproto_client.
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lasercats/atproto-ruby.
49
50
 
50
51
  ## License
51
52
 
@@ -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.0'
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - frabr
@@ -150,7 +150,7 @@ files:
150
150
  - lib/atproto_client/dpop_handler.rb
151
151
  - lib/atproto_client/request.rb
152
152
  - lib/atproto_client/version.rb
153
- homepage: https://github.com/lasercats/atproto_client
153
+ homepage: https://github.com/lasercats/atproto-ruby
154
154
  licenses:
155
155
  - MIT
156
156
  metadata: {}