zendesk_remote_authentication 0.5.0 → 0.6.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.
- data/VERSION +1 -1
- data/lib/zendesk_remote_authentication.rb +22 -26
- data/zendesk_remote_authentication.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.6.0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'digest/md5'
|
|
2
|
-
require 'active_support'
|
|
2
|
+
require 'active_support'
|
|
3
3
|
|
|
4
4
|
module Zendesk
|
|
5
5
|
class RemoteAuthentication
|
|
@@ -7,12 +7,12 @@ module Zendesk
|
|
|
7
7
|
attr_writer :auth_url, :token
|
|
8
8
|
|
|
9
9
|
def token
|
|
10
|
-
raise ArgumentError.new('
|
|
10
|
+
raise ArgumentError.new('Set your Zendesk token with. Zendesk::RemoteAuthentication.token = <token>') unless @token
|
|
11
11
|
@token
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def auth_url
|
|
15
|
-
raise ArgumentError.new('Zendesk authentication url
|
|
15
|
+
raise ArgumentError.new('Set your Zendesk authentication url with, Zendesk::RemoteAuthentication.auth_url = <token>') unless @auth_url
|
|
16
16
|
@auth_url
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -22,31 +22,27 @@ module Zendesk
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
module RemoteAuthenticationHelper
|
|
25
|
-
#you can either pass username and email or a user object which contains email and username attributes
|
|
26
|
-
def zendesk_remote_authentication_url(params)
|
|
27
|
-
params = params.is_a?(Hash) ? params : convert_user_to_a_hash(params)
|
|
28
|
-
|
|
29
|
-
#TODO: Need a class to validate the params
|
|
30
|
-
raise ArgumentError.new("You must provide name and email address") unless (params[:name] && params[:email])
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
def zendesk_remote_authentication_url(params)
|
|
27
|
+
raise ArgumentError.new("You must provide name and email address") unless (params[:name] && params[:email])
|
|
28
|
+
|
|
29
|
+
timestamp = params[:timestamp] || Time.now.to_i.to_s
|
|
30
|
+
name = params[:name]
|
|
31
|
+
email = params[:email].force_utf8
|
|
32
|
+
external_id = params[:external_id]
|
|
33
|
+
hash = Digest::MD5.hexdigest(name + email + external_id + Token + now)
|
|
34
|
+
back = params[:return_to]
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
auth_params = [
|
|
37
|
+
'?name=' + CGI.escape(name),
|
|
38
|
+
'&email=' + CGI.escape(email),
|
|
39
|
+
'×tamp=' + now,
|
|
40
|
+
'&hash=' + hash,
|
|
41
|
+
'&return_to=' + back
|
|
42
|
+
].join.force_utf8
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def convert_user_to_a_hash(user)
|
|
41
|
-
params = {}
|
|
42
|
-
params[:name] = "#{user.first_name} #{user.last_name}"
|
|
43
|
-
params[:email] = user.email
|
|
44
|
-
params[:external_id] = user.id
|
|
45
|
-
return params
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def generate_authentication_hash(token, params)
|
|
49
|
-
Digest::MD5.hexdigest(params[:name] + params[:email] + params[:external_id] + token + params[:timestamp])
|
|
44
|
+
Zendesk::RemoteAuthentication.auth_url + auth_params
|
|
45
|
+
|
|
50
46
|
end
|
|
51
|
-
|
|
47
|
+
|
|
52
48
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zendesk_remote_authentication
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 7
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 6
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.6.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- James Wachira
|