cent 3.0.0 → 5.0.0
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/CHANGELOG.md +93 -0
- data/MIGRATING.md +305 -0
- data/README.md +695 -169
- data/lib/cent/auto_batch.rb +305 -0
- data/lib/cent/batch.rb +209 -0
- data/lib/cent/broadcast.rb +117 -0
- data/lib/cent/client.rb +604 -230
- data/lib/cent/command.rb +64 -0
- data/lib/cent/endpoints.rb +191 -0
- data/lib/cent/errors.rb +392 -0
- data/lib/cent/generated/methods.rb +4226 -0
- data/lib/cent/generated/proxy_types.rb +1834 -0
- data/lib/cent/generated/types.rb +2844 -0
- data/lib/cent/handler.rb +179 -0
- data/lib/cent/http.rb +236 -32
- data/lib/cent/message.rb +52 -0
- data/lib/cent/pages.rb +165 -0
- data/lib/cent/payload.rb +93 -0
- data/lib/cent/proxy.rb +254 -0
- data/lib/cent/reply.rb +109 -0
- data/lib/cent/retry.rb +53 -0
- data/lib/cent/shared_poll.rb +61 -0
- data/lib/cent/token.rb +560 -0
- data/lib/cent/version.rb +2 -1
- data/lib/cent/wire.rb +222 -0
- data/lib/cent.rb +33 -5
- metadata +38 -56
- data/.github/workflows/main.yml +0 -20
- data/.github/workflows/release.yml +0 -37
- data/.gitignore +0 -20
- data/.rspec +0 -3
- data/.rubocop.yml +0 -13
- data/Gemfile +0 -17
- data/Rakefile +0 -12
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/cent.gemspec +0 -35
- data/lib/cent/error.rb +0 -9
- data/lib/cent/notary.rb +0 -96
data/lib/cent/notary.rb
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'jwt'
|
|
4
|
-
require 'cent/error'
|
|
5
|
-
|
|
6
|
-
module Cent
|
|
7
|
-
# Cent::Notary
|
|
8
|
-
#
|
|
9
|
-
# Handle token generation
|
|
10
|
-
#
|
|
11
|
-
class Notary
|
|
12
|
-
# @param secret [String | OpenSSL::PKey::RSA | OpenSSL::PKey::EC] Secret key for the algorithm of your choice.
|
|
13
|
-
# @param algorithm [String] Specify algorithm(one from HMAC, RSA or ECDSA family). Default is HS256.
|
|
14
|
-
#
|
|
15
|
-
# @example Construct new client instance
|
|
16
|
-
# notary = Cent::Notary.new(secret: 'secret')
|
|
17
|
-
#
|
|
18
|
-
def initialize(secret:, algorithm: 'HS256')
|
|
19
|
-
raise Error, 'Secret can not be nil' if secret.nil?
|
|
20
|
-
|
|
21
|
-
@secret = secret
|
|
22
|
-
@algorithm = algorithm
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Generate connection JWT for the given user
|
|
26
|
-
#
|
|
27
|
-
# @param sub [String]
|
|
28
|
-
# Standard JWT claim which must contain an ID of current application user.
|
|
29
|
-
#
|
|
30
|
-
# @option channel [String]
|
|
31
|
-
# Channel that client tries to subscribe to (string).
|
|
32
|
-
#
|
|
33
|
-
# @param exp [Integer]
|
|
34
|
-
# (default: nil) UNIX timestamp seconds when token will expire.
|
|
35
|
-
#
|
|
36
|
-
# @param info [Hash]
|
|
37
|
-
# (default: {}) This claim is optional - this is additional information about
|
|
38
|
-
# client connection that can be provided for Centrifugo.
|
|
39
|
-
#
|
|
40
|
-
# @example Get user JWT with expiration and extra info
|
|
41
|
-
# notary.issue_connection_token(sub: '1', exp: 3600, info: { 'role' => 'admin' })
|
|
42
|
-
# #=> "eyJhbGciOiJIUzI1NiJ9.eyJzdWIi..."
|
|
43
|
-
#
|
|
44
|
-
# @see (https://centrifugal.github.io/centrifugo/server/authentication/)
|
|
45
|
-
#
|
|
46
|
-
# @return [String]
|
|
47
|
-
#
|
|
48
|
-
def issue_connection_token(sub:, info: nil, exp: nil)
|
|
49
|
-
payload = {
|
|
50
|
-
'sub' => sub,
|
|
51
|
-
'info' => info,
|
|
52
|
-
'exp' => exp
|
|
53
|
-
}.compact
|
|
54
|
-
|
|
55
|
-
JWT.encode(payload, secret, algorithm)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Generate JWT for private channels
|
|
59
|
-
#
|
|
60
|
-
# @param client [String]
|
|
61
|
-
# Client ID which wants to subscribe on channel
|
|
62
|
-
#
|
|
63
|
-
# @option channel [String]
|
|
64
|
-
# Channel that client tries to subscribe to (string).
|
|
65
|
-
#
|
|
66
|
-
# @param exp [Integer]
|
|
67
|
-
# (default: nil) UNIX timestamp seconds when token will expire.
|
|
68
|
-
#
|
|
69
|
-
# @param info [Hash]
|
|
70
|
-
# (default: {}) This claim is optional - this is additional information about
|
|
71
|
-
# client connection that can be provided for Centrifugo.
|
|
72
|
-
#
|
|
73
|
-
# @example Get private channel JWT with expiration and extra info
|
|
74
|
-
# notary.issue_channel_token(client: 'client', channel: 'channel', exp: 3600, info: { 'message' => 'wat' })
|
|
75
|
-
# #=> eyJhbGciOiJIUzI1NiJ9.eyJjbGllbnQiOiJjbG..."
|
|
76
|
-
#
|
|
77
|
-
# @see (https://centrifugal.github.io/centrifugo/server/private_channels/)
|
|
78
|
-
#
|
|
79
|
-
# @return [String]
|
|
80
|
-
#
|
|
81
|
-
def issue_channel_token(client:, channel:, info: nil, exp: nil)
|
|
82
|
-
payload = {
|
|
83
|
-
'client' => client,
|
|
84
|
-
'channel' => channel,
|
|
85
|
-
'info' => info,
|
|
86
|
-
'exp' => exp
|
|
87
|
-
}.compact
|
|
88
|
-
|
|
89
|
-
JWT.encode(payload, secret, algorithm)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
private
|
|
93
|
-
|
|
94
|
-
attr_reader :secret, :algorithm
|
|
95
|
-
end
|
|
96
|
-
end
|