phoenix_rails 0.0.6 → 0.0.7
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/phoenix_rails/channel.rb +0 -56
- data/lib/phoenix_rails/client.rb +0 -6
- data/lib/phoenix_rails/request.rb +3 -4
- data/lib/phoenix_rails.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8268589d0a66612c558723423666c396842f393a
|
4
|
+
data.tar.gz: b4a5ceb4ac3973db76bb278bfb25b54ab327f1a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0087cbbedb81696aa72f95b33979d5553127319f492c8f58ea4bb270ac5bc508cd2748df85fe8ca453382923e2fa8c4a3ed2ad7885829d3bd73a0cdff624cfc0
|
7
|
+
data.tar.gz: e391b20bb4d241b1ca3b1f4eb28479d9f9c75dc423656b09a14a3ccb237923ed53c6e9d26fbe19a35fa6184e44a0b3c3cfceb9080e286b6a1f4cfbf19ef49207
|
@@ -48,62 +48,6 @@ module PhoenixRails
|
|
48
48
|
@client.get("/channels/#{name}/users")[:users]
|
49
49
|
end
|
50
50
|
|
51
|
-
# Compute authentication string required as part of the authentication
|
52
|
-
# endpoint response. Generally the authenticate method should be used in
|
53
|
-
# preference to this one
|
54
|
-
#
|
55
|
-
# @param socket_id [String] Each PhoenixRails socket connection receives a
|
56
|
-
# unique socket_id. This is sent from phoenix.js to your server when
|
57
|
-
# channel authentication is required.
|
58
|
-
# @param custom_string [String] Allows signing additional data
|
59
|
-
# @return [String]
|
60
|
-
#
|
61
|
-
def authentication_string(socket_id, custom_string = nil)
|
62
|
-
validate_socket_id(socket_id)
|
63
|
-
|
64
|
-
unless custom_string.nil? || custom_string.kind_of?(String)
|
65
|
-
raise Error, 'Custom argument must be a string'
|
66
|
-
end
|
67
|
-
|
68
|
-
string_to_sign = [socket_id, name, custom_string].
|
69
|
-
compact.map(&:to_s).join(':')
|
70
|
-
PhoenixRails.logger.debug "Signing #{string_to_sign}"
|
71
|
-
token = @client.authentication_token
|
72
|
-
digest = OpenSSL::Digest::SHA256.new
|
73
|
-
signature = OpenSSL::HMAC.hexdigest(digest, token.secret, string_to_sign)
|
74
|
-
|
75
|
-
return "#{token.key}:#{signature}"
|
76
|
-
end
|
77
|
-
|
78
|
-
# Generate the expected response for an authentication endpoint.
|
79
|
-
#
|
80
|
-
# @example Private channels
|
81
|
-
# render :json => PhoenixRails['private-my_channel'].authenticate(params[:socket_id])
|
82
|
-
#
|
83
|
-
# @example Presence channels
|
84
|
-
# render :json => PhoenixRails['private-my_channel'].authenticate(params[:socket_id], {
|
85
|
-
# :user_id => current_user.id, # => required
|
86
|
-
# :user_info => { # => optional - for example
|
87
|
-
# :name => current_user.name,
|
88
|
-
# :email => current_user.email
|
89
|
-
# }
|
90
|
-
# })
|
91
|
-
#
|
92
|
-
# @param socket_id [String]
|
93
|
-
# @param custom_data [Hash] used for example by private channels
|
94
|
-
#
|
95
|
-
# @return [Hash]
|
96
|
-
#
|
97
|
-
# @private Custom data is sent to server as JSON-encoded string
|
98
|
-
#
|
99
|
-
def authenticate(socket_id, custom_data = nil)
|
100
|
-
custom_data = MultiJson.encode(custom_data) if custom_data
|
101
|
-
auth = authentication_string(socket_id, custom_data)
|
102
|
-
r = {:auth => auth}
|
103
|
-
r[:channel_data] = custom_data if custom_data
|
104
|
-
r
|
105
|
-
end
|
106
|
-
|
107
51
|
private
|
108
52
|
|
109
53
|
def validate_socket_id(socket_id)
|
data/lib/phoenix_rails/client.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'signature'
|
2
|
-
|
3
1
|
module PhoenixRails
|
4
2
|
class Client
|
5
3
|
attr_accessor :scheme, :host, :port, :key, :secret
|
@@ -74,10 +72,6 @@ module PhoenixRails
|
|
74
72
|
post('/events', trigger_params(channels, event_name, data, params))
|
75
73
|
end
|
76
74
|
|
77
|
-
def authentication_token
|
78
|
-
Signature::Token.new(@key, @secret)
|
79
|
-
end
|
80
|
-
|
81
75
|
# @private Construct a net/http http client
|
82
76
|
def http_client
|
83
77
|
@client ||= begin
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'jwt'
|
2
2
|
require 'digest/md5'
|
3
3
|
require 'multi_json'
|
4
4
|
|
@@ -11,9 +11,8 @@ module PhoenixRails
|
|
11
11
|
@head = { 'Content-Type' => 'application/json'}
|
12
12
|
@body = body
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
@params = request.signed_params
|
14
|
+
token = JWT.encode @body, client.secret, 'HS256'
|
15
|
+
@head[:Authorization] = "Bearer #{token}"
|
17
16
|
end
|
18
17
|
|
19
18
|
def send
|
data/lib/phoenix_rails.rb
CHANGED
@@ -10,7 +10,7 @@ module PhoenixRails
|
|
10
10
|
def_delegators :default_client, :scheme, :host, :port, :key, :secret
|
11
11
|
def_delegators :default_client, :scheme=, :host=, :port=, :key=, :secret=
|
12
12
|
|
13
|
-
def_delegators :default_client, :
|
13
|
+
def_delegators :default_client, :url
|
14
14
|
def_delegators :default_client, :encrypted=, :url=
|
15
15
|
def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phoenix_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nguyen Le
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jwt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.5.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.5.0
|
41
55
|
description: Gem for pushing event to a Phoenix server for realtime
|
42
56
|
email: nathanle89@gmail.com
|
43
57
|
executables: []
|