atproto_client 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/atproto_client/client.rb +1 -1
- data/lib/atproto_client/dpop_handler.rb +12 -1
- data/lib/atproto_client/request.rb +1 -3
- data/lib/atproto_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbbb4053b1b25b1d1d3d37a6ae736570dd8d1bd097d69fde6d7868015fa45ac1
|
4
|
+
data.tar.gz: 0a8cd5beac57a16b965aa7d5487a4896887d820ed012e7526091e28054111c1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eac347a2e5d30aa247d1ae27c16aa5df76ee581945c0af5c3cb1fe31575332687b662a9105470ed5634c8912b041b83ed36f0fd5ca6248d44fde387918c0ba87
|
7
|
+
data.tar.gz: 1711570172c8f61c617784c886386b6f2afe7b71c4435e1e353bab7314e1ae3651c64a661526f27915bfa9494e52c897e913c2bf804b8d01bb826d06280da006
|
@@ -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
|
-
|
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']}"
|