zendesk_remote_auth 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,5 +1,3 @@
1
- Copyright (c) 2009 Tobias Crawley
2
-
3
1
  Permission is hereby granted, free of charge, to any person obtaining
4
2
  a copy of this software and associated documentation files (the
5
3
  "Software"), to deal in the Software without restriction, including
data/README.rdoc CHANGED
@@ -1,13 +1,9 @@
1
1
  = zendesk_remote_auth
2
2
 
3
- zendesk_remote_auth is a simple gem providing help with Zendesk's SSO
4
- functionality (see http://www.zendesk.com/api/remote_authentication).
5
-
6
- == HEY YOU!
3
+ 16/02/2012 Viewbook took over this gem from Tobias Crawley, this is now the official repo for this gem.
7
4
 
8
- Do you actually use this gem? Are you interested in taking it over?
9
- I no longer use this, so don't have a lot of interest in maintaining it.
10
- If you do, get in touch.
5
+ zendesk_remote_auth is a simple gem providing help with Zendesk's SSO
6
+ functionality (see http://www.zendesk.com/support/api/remote-authentication).
11
7
 
12
8
  == Installation and Setup
13
9
 
@@ -18,14 +14,14 @@ If you do, get in touch.
18
14
  You will need to give the gem your token and authentication url,
19
15
  perhaps in an initializer:
20
16
  Zendesk::RemoteAuth.token = 'YOUR-TOKEN'
21
- Zendesk::RemoteAuth.auth_url = 'https://yourcompany.zendesk.com/access/remote/'
17
+ Zendesk::RemoteAuth.auth_url = 'https://domain.zendesk.com/access/remoteauth'
22
18
 
23
19
  and config the gem in environment.rb (if using rails):
24
20
  config.gem 'zendesk_remote_auth'
25
21
 
26
22
  == Usage
27
23
 
28
- Note: The latest release requires ActiveSupport 3.0 or greater.
24
+ Note: The latest release requires ActiveSupport 3.0 or greater.
29
25
 
30
26
  Mixin the Zendesk::RemoteAuthHelper module wherever needed, then call:
31
27
  zendesk_remote_auth_url(:name => 'user name',
@@ -33,7 +29,7 @@ Mixin the Zendesk::RemoteAuthHelper module wherever needed, then call:
33
29
  <optional params>)
34
30
 
35
31
  This will return a url you can redirect the user to to log them in to
36
- your zendesk account.
32
+ your zendesk account.
37
33
 
38
34
  As a convenience, you can pass a user object to zendesk_remote_auth_url:
39
35
  zendesk_remote_auth_url(user)
@@ -44,16 +40,20 @@ an ephemeral object_id, but works well with ActiveRecord and the
44
40
  like). If the user object responds to :zendesk_organization, that will
45
41
  be used as the :organization for the call.
46
42
 
43
+ Same goes for :zendesk_tags, you'll need a string such as:
44
+ "fine looking gentlemen,single"
45
+ And it'll automatically be passed as :tags to Zendesk
46
+
47
47
  This method will generate and include the hash of the parameters for
48
- you if necessary.
48
+ you if necessary.
49
49
 
50
50
  == Example Auth Controller
51
51
 
52
52
  Here is an example controller that handles login and logout for
53
53
  zendesk:
54
54
 
55
- # Uses restful-authentication style auth.
56
- #
55
+ # Uses restful-authentication style auth.
56
+ #
57
57
  # Define the following in routes.rb:
58
58
  # map.with_options :controller => 'zendesk_auth' do |zd|
59
59
  # zd.connect '/zendesk/authorize', :action => 'authorize'
@@ -61,9 +61,9 @@ zendesk:
61
61
  # end
62
62
  class ZendeskAuthController < ApplicationController
63
63
  include Zendesk::RemoteAuthHelper
64
-
64
+
65
65
  skip_before_filter :login_required, :only => :logout
66
-
66
+
67
67
  def authorize
68
68
  redirect_to zendesk_remote_auth_url(current_user)
69
69
  end
@@ -84,13 +84,9 @@ zendesk:
84
84
 
85
85
 
86
86
  == Note on Patches/Pull Requests
87
-
87
+
88
88
  * Fork the project.
89
89
  * Make your feature addition or bug fix.
90
90
  * Add tests for it. This is important so I don't break it in a future version unintentionally.
91
91
  * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
92
92
  * Send me a pull request. Bonus points for topic branches.
93
-
94
- == Copyright
95
-
96
- Copyright (c) 2011 Tobias Crawley. See LICENSE for details.
data/Rakefile CHANGED
@@ -7,9 +7,9 @@ begin
7
7
  gem.name = "zendesk_remote_auth"
8
8
  gem.summary = %Q{Helper for Zendesk SSO/remote authentication}
9
9
  gem.description = %Q{See the README.}
10
- gem.email = "tcrawley@gmail.com"
11
- gem.homepage = "http://github.com/tobias/zendesk_remote_auth"
12
- gem.authors = ["Tobias Crawley"]
10
+ gem.email = "info@viewbook.com"
11
+ gem.homepage = "https://github.com/viewbook/zendesk_remote_auth"
12
+ gem.authors = ["Viewbook"]
13
13
  gem.add_dependency "activesupport", ">= 3.0.0"
14
14
  gem.add_development_dependency "rspec", ">= 2.6.0"
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -40,12 +40,12 @@ module Zendesk
40
40
  # respond_to? at least :email and :name. The :id of the user
41
41
  # object will be used as the :external_id, and if the user
42
42
  # responds to :zendesk_organization, that will be used as the
43
- # :organization.
43
+ # :organization.
44
44
  def zendesk_remote_auth_url(user_or_params)
45
45
  params = user_or_params.is_a?(Hash) ? user_or_params : user_to_params(user_or_params)
46
46
  validate_params(params)
47
47
  params[:timestamp] = Time.now.utc.to_i unless params[:timestamp]
48
- params[:hash] = params[:external_id] ? generate_hash(Zendesk::RemoteAuth.token, params) : ''
48
+ params[:hash] = generate_hash(Zendesk::RemoteAuth.token, params)
49
49
 
50
50
  "#{Zendesk::RemoteAuth.auth_url}?#{params.to_query}"
51
51
  end
@@ -56,7 +56,8 @@ module Zendesk
56
56
  [[:email, :email],
57
57
  [:name, :name],
58
58
  [:external_id, :id],
59
- [:organization, :zendesk_organization]].each do |param, field|
59
+ [:organization, :zendesk_organization],
60
+ [:tags, :zendesk_tags]].each do |param, field|
60
61
  params[param] = user.send(field) if user.respond_to?(field)
61
62
  end
62
63
  params
@@ -67,17 +68,19 @@ module Zendesk
67
68
  raise ArgumentError.new("Required parameter :#{param} not given") unless params[param]
68
69
  end
69
70
  end
70
-
71
+
71
72
  def generate_hash(token, params)
72
- str_to_hash = params[:name].clone
73
- str_to_hash << params[:email]
74
- str_to_hash << params[:external_id].to_s if params[:external_id]
75
- str_to_hash << params[:organization].to_s if params[:organization]
76
- str_to_hash << params[:tags].to_s if params[:tags]
77
- str_to_hash << params[:remote_photo_url].to_s if params[:remote_photo_url]
78
- str_to_hash << token
79
- str_to_hash << params[:timestamp].to_s
80
- Digest::MD5.hexdigest(str_to_hash)
73
+ parts = []
74
+ parts << params[:name]
75
+ parts << params[:email]
76
+ parts << params[:external_id]
77
+ parts << params[:organization]
78
+ parts << params[:tags]
79
+ parts << params[:remote_photo_url]
80
+ parts << token
81
+ parts << params[:timestamp]
82
+ input = parts.join('|')
83
+ Digest::MD5.hexdigest(input)
81
84
  end
82
85
 
83
86
  end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'zendesk_remote_auth'
4
+
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zendesk::RemoteAuth do
4
+
5
+ before(:each) do
6
+ @auth = Object.new
7
+ @auth.extend(Zendesk::RemoteAuthHelper)
8
+ end
9
+
10
+ context 'RemoteAuth' do
11
+ before(:each) do
12
+ Zendesk::RemoteAuth.token = Zendesk::RemoteAuth.auth_url = nil
13
+ end
14
+
15
+ it 'should raise exception if token is not set' do
16
+ lambda{ Zendesk::RemoteAuth.token }.should raise_error(ArgumentError)
17
+ end
18
+
19
+ it 'should return the token without exception if it is set' do
20
+ Zendesk::RemoteAuth.token = 'blah'
21
+ Zendesk::RemoteAuth.token.should == 'blah'
22
+ end
23
+
24
+
25
+ it 'should raise exception if auth_url is not set' do
26
+ lambda { Zendesk::RemoteAuth.auth_url }.should raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'should return the auth_url without exception if it is set' do
30
+ Zendesk::RemoteAuth.auth_url = 'blah'
31
+ Zendesk::RemoteAuth.auth_url.should == 'blah'
32
+ end
33
+ end
34
+
35
+
36
+ context 'url generation' do
37
+ before(:each) do
38
+ Zendesk::RemoteAuth.token = 'the_token'
39
+ Zendesk::RemoteAuth.auth_url = 'the_url'
40
+ @valid_params = { :email => 'test@example.com', :name => 'blah'}
41
+ end
42
+
43
+ context 'required fields' do
44
+ it 'should raise an argument error the name is not provided' do
45
+ lambda {
46
+ @valid_params.delete(:name)
47
+ @auth.zendesk_remote_auth_url(@valid_params)
48
+ }.should raise_error(ArgumentError)
49
+ end
50
+
51
+ it 'should raise an argument error the email is not provided' do
52
+ lambda {
53
+ @valid_params.delete(:email)
54
+ @auth.zendesk_remote_auth_url(@valid_params)
55
+ }.should raise_error(ArgumentError)
56
+ end
57
+
58
+ end
59
+
60
+ it 'should return a url that starts with the auth_url' do
61
+ @auth.zendesk_remote_auth_url(@valid_params)
62
+ end
63
+
64
+ it 'should have a hash param' do
65
+ @auth.zendesk_remote_auth_url(@valid_params).should_not =~ /hash=(&|$)/
66
+ end
67
+
68
+ it 'should have a different hash param if external_id and remote_photo_url provided ' do
69
+ a=@auth.zendesk_remote_auth_url(@valid_params.merge(:external_id => 'id')).match(/(hash=[^&]*)/)[1]
70
+ b=@auth.zendesk_remote_auth_url(@valid_params.merge(:external_id => 'id', :remote_photo_url => 'photo_url')).match(/(hash=[^&]*)/)[1]
71
+ a.should_not == b
72
+ end
73
+
74
+ context 'given a user object' do
75
+ before(:each) do
76
+ @user = mock
77
+ @user.should_receive(:name).and_return('a_name')
78
+ @user.should_receive(:email).and_return('an_email')
79
+ end
80
+
81
+ it 'should pull the name from the user' do
82
+ @auth.zendesk_remote_auth_url(@user).should =~ /name=a_name/
83
+ end
84
+
85
+ it 'should pull the email from the user' do
86
+ @auth.zendesk_remote_auth_url(@user).should =~ /email=an_email/
87
+ end
88
+
89
+ it 'should pull the id from the user' do
90
+ @user.should_receive(:id).and_return('an_id')
91
+ @auth.zendesk_remote_auth_url(@user).should =~ /external_id=an_id/
92
+ end
93
+
94
+ it 'should pull the organization from the user if available' do
95
+ @user.should_receive(:zendesk_organization).and_return('org')
96
+ @auth.zendesk_remote_auth_url(@user).should =~ /organization=org/
97
+ end
98
+
99
+ it 'should pull tags from the user if available' do
100
+ @user.should_receive(:zendesk_tags).and_return('fine looking gentlemen,married')
101
+ @auth.zendesk_remote_auth_url(@user).should =~/tags=fine\+looking\+gentlemen%2Cmarried/
102
+ end
103
+ end
104
+ end
105
+ end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{zendesk_remote_auth}
8
- s.version = "1.1.0"
7
+ s.name = "zendesk_remote_auth"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Tobias Crawley}]
12
- s.date = %q{2011-12-14}
13
- s.description = %q{See the README.}
14
- s.email = %q{tcrawley@gmail.com}
11
+ s.authors = ["Viewbook"]
12
+ s.date = "2012-11-16"
13
+ s.description = "See the README."
14
+ s.email = "info@viewbook.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -23,12 +23,14 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "lib/zendesk_remote_auth.rb",
26
+ "spec/spec_helper.rb",
27
+ "spec/zendesk_remote_auth_spec.rb",
26
28
  "zendesk_remote_auth.gemspec"
27
29
  ]
28
- s.homepage = %q{http://github.com/tobias/zendesk_remote_auth}
29
- s.require_paths = [%q{lib}]
30
- s.rubygems_version = %q{1.8.4}
31
- s.summary = %q{Helper for Zendesk SSO/remote authentication}
30
+ s.homepage = "https://github.com/viewbook/zendesk_remote_auth"
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = "1.8.23"
33
+ s.summary = "Helper for Zendesk SSO/remote authentication"
32
34
 
33
35
  if s.respond_to? :specification_version then
34
36
  s.specification_version = 3
metadata CHANGED
@@ -1,96 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zendesk_remote_auth
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 0
9
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
12
- - Tobias Crawley
7
+ authors:
8
+ - Viewbook
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-12-14 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 3
29
- - 0
30
- - 0
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
31
21
  version: 3.0.0
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 6
44
- - 0
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
45
37
  version: 2.6.0
46
38
  type: :development
47
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
48
46
  description: See the README.
49
- email: tcrawley@gmail.com
47
+ email: info@viewbook.com
50
48
  executables: []
51
-
52
49
  extensions: []
53
-
54
- extra_rdoc_files:
50
+ extra_rdoc_files:
55
51
  - LICENSE
56
52
  - README.rdoc
57
- files:
53
+ files:
58
54
  - .document
59
55
  - LICENSE
60
56
  - README.rdoc
61
57
  - Rakefile
62
58
  - VERSION
63
59
  - lib/zendesk_remote_auth.rb
60
+ - spec/spec_helper.rb
61
+ - spec/zendesk_remote_auth_spec.rb
64
62
  - zendesk_remote_auth.gemspec
65
- has_rdoc: true
66
- homepage: http://github.com/tobias/zendesk_remote_auth
63
+ homepage: https://github.com/viewbook/zendesk_remote_auth
67
64
  licenses: []
68
-
69
65
  post_install_message:
70
66
  rdoc_options: []
71
-
72
- require_paths:
67
+ require_paths:
73
68
  - lib
74
- required_ruby_version: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- segments:
79
- - 0
80
- version: "0"
81
- required_rubygems_version: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
- version: "0"
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
88
81
  requirements: []
89
-
90
82
  rubyforge_project:
91
- rubygems_version: 1.3.6
83
+ rubygems_version: 1.8.23
92
84
  signing_key:
93
85
  specification_version: 3
94
86
  summary: Helper for Zendesk SSO/remote authentication
95
87
  test_files: []
96
-