auth0-ruby 0.9.1 → 0.10

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/Gemfile.lock +2 -4
  4. data/auth0.gemspec +0 -1
  5. data/doc/Auth0.html +3 -3
  6. data/doc/Auth0/AccessDenied.html +142 -0
  7. data/doc/Auth0/Api.html +3 -3
  8. data/doc/Auth0/Api/AuthenticationEndpoints.html +3 -7
  9. data/doc/Auth0/Api/V1.html +4 -8
  10. data/doc/Auth0/Api/V1/Clients.html +1 -1
  11. data/doc/Auth0/Api/V1/Connections.html +1 -1
  12. data/doc/Auth0/Api/V1/Logs.html +1 -1
  13. data/doc/Auth0/Api/V1/Rules.html +1 -1
  14. data/doc/Auth0/Api/V1/Users.html +1 -1
  15. data/doc/Auth0/Api/V2.html +193 -0
  16. data/doc/Auth0/Api/V2/Blacklists.html +268 -0
  17. data/doc/Auth0/Api/V2/Clients.html +477 -0
  18. data/doc/Auth0/Api/V2/Jobs.html +277 -0
  19. data/doc/Auth0/Api/V2/Router.html +109 -0
  20. data/doc/Auth0/Api/V2/Stats.html +268 -0
  21. data/doc/Auth0/Api/V2/Users.html +652 -0
  22. data/doc/Auth0/BadRequest.html +1 -1
  23. data/doc/Auth0/Client.html +1 -73
  24. data/doc/Auth0/Exception.html +2 -2
  25. data/doc/Auth0/InvalidParameter.html +142 -0
  26. data/doc/Auth0/Mixins.html +4 -76
  27. data/doc/Auth0/Mixins/HTTPartyProxy.html +1 -1
  28. data/doc/Auth0/Mixins/Initializer.html +20 -14
  29. data/doc/Auth0/NotFound.html +1 -1
  30. data/doc/Auth0/ServerError.html +1 -1
  31. data/doc/Auth0/Unauthorized.html +1 -1
  32. data/doc/Auth0/Unsupported.html +1 -1
  33. data/doc/Auth0/UserIdIsBlank.html +1 -1
  34. data/doc/Auth0Client.html +1 -73
  35. data/doc/_index.html +59 -3
  36. data/doc/class_list.html +1 -1
  37. data/doc/file.README.html +1 -1
  38. data/doc/index.html +1 -1
  39. data/doc/method_list.html +132 -30
  40. data/doc/top-level-namespace.html +1 -1
  41. data/lib/auth0/api/v2.rb +19 -0
  42. data/lib/auth0/api/v2/blacklists.rb +22 -0
  43. data/lib/auth0/api/v2/clients.rb +39 -0
  44. data/lib/auth0/api/v2/jobs.rb +20 -0
  45. data/lib/auth0/api/v2/router.rb +28 -0
  46. data/lib/auth0/api/v2/stats.rb +22 -0
  47. data/lib/auth0/api/v2/users.rb +64 -0
  48. data/lib/auth0/exception.rb +5 -1
  49. data/lib/auth0/mixins.rb +2 -3
  50. data/lib/auth0/mixins/httparty_proxy.rb +7 -1
  51. data/lib/auth0/mixins/initializer.rb +13 -8
  52. data/lib/auth0/version.rb +1 -1
  53. data/spec/lib/auth0/api/v2/blacklists_spec.rb +25 -0
  54. data/spec/lib/auth0/api/v2/clients_spec.rb +55 -0
  55. data/spec/lib/auth0/api/v2/jobs_spec.rb +22 -0
  56. data/spec/lib/auth0/api/v2/stats_spec.rb +23 -0
  57. data/spec/lib/auth0/api/v2/users_spec.rb +73 -0
  58. data/spec/lib/auth0/client_spec.rb +31 -8
  59. data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +60 -1
  60. data/spec/lib/auth0_client_spec.rb +1 -1
  61. data/spec/spec_helper.rb +1 -1
  62. metadata +25 -37
  63. data/doc/Auth0/Mixins/JwtOperations.html +0 -202
  64. data/lib/auth0/mixins/jwt_operations.rb +0 -14
  65. data/spec/lib/auth0/mixins/jwt_operations_spec.rb +0 -31
  66. data/spec/support/stub_class_with_client_secret.rb +0 -7
@@ -105,7 +105,7 @@
105
105
  </div>
106
106
 
107
107
  <div id="footer">
108
- Generated on Wed Feb 4 17:42:51 2015 by
108
+ Generated on Mon Feb 23 01:12:53 2015 by
109
109
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
110
110
  0.8.7.6 (ruby-2.0.0).
111
111
  </div>
@@ -0,0 +1,19 @@
1
+ require "auth0/api/v2/router"
2
+ require "auth0/api/v2/clients"
3
+ require "auth0/api/v2/users"
4
+ require "auth0/api/v2/blacklists"
5
+ require "auth0/api/v2/jobs"
6
+ require "auth0/api/v2/stats"
7
+ module Auth0
8
+ module Api
9
+ # https://auth0.com/docs/apiv2
10
+ module V2
11
+ include Auth0::Api::V2::Router
12
+ include Auth0::Api::V2::Clients
13
+ include Auth0::Api::V2::Users
14
+ include Auth0::Api::V2::Blacklists
15
+ include Auth0::Api::V2::Jobs
16
+ include Auth0::Api::V2::Stats
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # https://auth0.com/docs/apiv2#!/blacklists
5
+ module Blacklists
6
+ # https://auth0.com/docs/apiv2#!/blacklists/get_tokens
7
+ def blacklisted_tokens
8
+ get(path)
9
+ end
10
+
11
+ # https://auth0.com/docs/apiv2#!/blacklists/post_tokens
12
+ def add_token_to_blacklist(jti, aud=nil)
13
+ request_params = {
14
+ jti: jti,
15
+ aud: aud
16
+ }
17
+ post(path, request_params)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ #https://auth0.com/docs/apiv2#!/clients
5
+ module Clients
6
+ #https://auth0.com/docs/apiv2#!/clients/get_clients
7
+ def clients(options={})
8
+ get(path, options)
9
+ end
10
+ alias :get_clients :clients
11
+
12
+ #https://auth0.com/docs/apiv2#!/clients/post_clients
13
+ def create_client(name, options={})
14
+ request_params = Hash[options.map{|(k,v)| [k.to_sym,v]}]
15
+ request_params[:name] = name
16
+ post(path, request_params)
17
+ end
18
+
19
+ #https://auth0.com/docs/apiv2#!/clients/get_clients_by_id
20
+ def client(client_id, options={})
21
+ path = "/api/v2/clients/" + client_id.to_s
22
+ get(path, options)
23
+ end
24
+
25
+ #https://auth0.com/docs/apiv2#!/clients/delete_clients_by_id
26
+ def delete_client(client_id)
27
+ path = "/api/v2/clients/" + client_id.to_s
28
+ delete(path)
29
+ end
30
+
31
+ #https://auth0.com/docs/apiv2#!/clients/patch_clients_by_id
32
+ def patch_client(client_id, options)
33
+ path = "/api/v2/clients/" + client_id.to_s
34
+ patch(path, options)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # https://auth0.com/docs/apiv2#!/jobs
5
+ module Jobs
6
+ #https://auth0.com/docs/apiv2#!/jobs/get_jobs_by_job_id
7
+ def get_job(job_id)
8
+ path = "/api/v2/jobs/#{job_id}"
9
+ get(path)
10
+ end
11
+
12
+ # HTTParty doesn't support multipart upload, will move this functionality to a separate PR
13
+ # https://auth0.com/docs/apiv2#!/jobs/post_users_imports
14
+ def create_job(users_file, connection_name)
15
+ raise NotImplementedError
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # Describing all simple routes
5
+ module Router
6
+ private
7
+ # Building simple routes. mb should be removed
8
+ def path
9
+ routes = {
10
+ blacklisted_tokens: "/api/v2/blacklists/tokens",
11
+ add_token_to_blacklist: "/api/v2/blacklists/tokens",
12
+ clients: "/api/v2/clients",
13
+ get_clients: "/api/v2/clients",
14
+ create_client: "/api/v2/clients",
15
+ active_users: "/api/v2/stats/active-users",
16
+ daily_stats: "/api/v2/stats/daily",
17
+ users: "/api/v2/users",
18
+ get_users: "/api/v2/users",
19
+ create_user: "/api/v2/users",
20
+ delete_users: "/api/v2/users"
21
+ }
22
+ called_method = caller[0][/`.*'/][1..-2]
23
+ routes[called_method.to_sym]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # https://auth0.com/docs/apiv2#!/stats
5
+ module Stats
6
+ #https://auth0.com/docs/apiv2#!/stats/get_active_users
7
+ def active_users
8
+ get(path)
9
+ end
10
+
11
+ #https://auth0.com/docs/apiv2#!/stats/get_daily
12
+ def daily_stats(from, to)
13
+ request_params = {
14
+ from: from,
15
+ to: to
16
+ }
17
+ get(path, request_params)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ #https://auth0.com/docs/apiv2#!/users
5
+ module Users
6
+ #https://auth0.com/docs/apiv2#!/users/get_users
7
+ def users( per_page: nil, page: nil, include_totals: nil, sort: nil, connection: nil, fields: nil, exclude_fields: nil, q: nil )
8
+ request_params = { per_page: per_page,
9
+ page: page,
10
+ include_totals: include_totals,
11
+ sort: sort,
12
+ connection: connection,
13
+ fields: fields,
14
+ exclude_fields: exclude_fields,
15
+ q: q
16
+ }
17
+ get(path, request_params)
18
+ end
19
+ alias :get_users :users
20
+
21
+ #https://auth0.com/docs/apiv2#!/users/post_users
22
+ def create_user(name, options={})
23
+ request_params = Hash[options.map{|(k,v)| [k.to_sym,v]}]
24
+ request_params[:name] = name
25
+ post(path, request_params)
26
+ end
27
+
28
+ #https://auth0.com/docs/apiv2#!/users/delete_users
29
+ def delete_users
30
+ delete(path)
31
+ end
32
+
33
+ #https://auth0.com/docs/apiv2#!/users/get_users_by_id
34
+ def user(user_id, fields: nil, exclude_fields: nil)
35
+ path = "/api/v2/users/" + user_id.to_s
36
+ request_params = { fields: fields,
37
+ exclude_fields: exclude_fields
38
+ }
39
+ get(path, request_params)
40
+ end
41
+
42
+ #https://auth0.com/docs/apiv2#!/users/delete_users_by_id
43
+ def delete_user(user_id)
44
+ raise Auth0::UserIdIsBlank, "if you want to remove all users user delete_users method" if user_id.to_s.empty?
45
+ path = "/api/v2/users/" + user_id.to_s
46
+ delete(path)
47
+ end
48
+
49
+
50
+ #https://auth0.com/docs/apiv2#!/users/patch_users_by_id
51
+ def patch_user(user_id, options)
52
+ path = "/api/v2/users/" + user_id
53
+ patch(path, options)
54
+ end
55
+
56
+ #https://auth0.com/docs/apiv2#!/users/delete_multifactor_by_provider
57
+ def delete_user_provider(user_id, provider_name)
58
+ path = "/api/v2/users/#{user_id}/multifactor/#{provider_name}"
59
+ delete(path)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -15,4 +15,8 @@ class Auth0::ServerError < Auth0::Exception; end
15
15
  # exception for incorrect request, you've sent wrong params
16
16
  class Auth0::BadRequest < Auth0::Exception; end
17
17
  # exception for unset user_id, this might cause removal of all users, or other unexpected bahaviour
18
- class Auth0::UserIdIsBlank < Auth0::Exception; end
18
+ class Auth0::UserIdIsBlank < Auth0::Exception; end
19
+ # Api v2 access denied
20
+ class Auth0::AccessDenied < Auth0::Exception; end
21
+ # Invalid parameter passed, e.g. empty where ID is required
22
+ class Auth0::InvalidParameter < Auth0::Exception; end
@@ -1,13 +1,12 @@
1
1
  require 'httparty'
2
2
  require 'uri'
3
- require "auth0/mixins/initializer"
4
3
  require "auth0/mixins/httparty_proxy"
4
+ require "auth0/mixins/initializer"
5
5
  require "auth0/api/authentication_endpoints"
6
6
  require "auth0/api/v1"
7
+ require "auth0/api/v2"
7
8
  # Collecting dependencies here
8
9
  module Auth0::Mixins
9
10
  include Auth0::Mixins::HTTPartyProxy
10
11
  include Auth0::Mixins::Initializer
11
- include Auth0::Api::AuthenticationEndpoints
12
- include Auth0::Api::V1
13
12
  end
@@ -6,7 +6,12 @@ module Auth0
6
6
  %i(get post put patch delete).each do |method|
7
7
  define_method(method) do |path, body={}|
8
8
  safe_path = URI.escape(path)
9
- result = self.class.send(method, safe_path, body: body.to_json)
9
+ body = body.delete_if {|k,v| v.nil? }
10
+ if method == :get
11
+ result = self.class.send(method, safe_path, query: body)
12
+ else
13
+ result = self.class.send(method, safe_path, body: body.to_json)
14
+ end
10
15
  response_body =
11
16
  begin
12
17
  JSON.parse(result.body.to_s)
@@ -17,6 +22,7 @@ module Auth0
17
22
  when 200...226 then response_body
18
23
  when 400 then raise Auth0::BadRequest, response_body
19
24
  when 401 then raise Auth0::Unauthorized, response_body
25
+ when 403 then raise Auth0::AccessDenied, response_body
20
26
  when 404 then raise Auth0::NotFound, response_body
21
27
  when 500 then raise Auth0::ServerError, response_body
22
28
  else
@@ -5,18 +5,23 @@ module Auth0
5
5
  # Default initialization mechanism, moved here to keep Auth0::Client clear
6
6
  # accepts hash as parameter
7
7
  # you can get all required fields from here: https://auth0.com/docs/auth-api
8
+ #
9
+ # To run using api v2, pass protocols: "v2" when creating a client
8
10
  def initialize(config)
9
11
  options = Hash[config.map{|(k,v)| [k.to_sym,v]}]
10
- self.class.base_uri "https://"+options[:namespace].to_s
12
+ self.class.base_uri "https://#{options[:namespace]}"
11
13
  self.class.headers "Content-Type" => 'application/json'
12
- @client_id = options[:client_id]
13
- @client_secret = options[:client_secret]
14
- @token = obtain_access_token
15
- self.class.headers "Authorization" => "Bearer #{@token}"
16
- if options[:jwt]
17
- require 'auth0/mixins/jwt_operations'
18
- self.class.send(:include, Auth0::Mixins::JwtOperations)
14
+ if options[:protocols].to_s.include?("v2")
15
+ self.extend Auth0::Api::V2
16
+ @token = options[:access_token]
17
+ else
18
+ self.extend Auth0::Api::V1
19
+ self.extend Auth0::Api::AuthenticationEndpoints
20
+ @client_id = options[:client_id]
21
+ @client_secret = options[:client_secret]
22
+ @token = obtain_access_token
19
23
  end
24
+ self.class.headers "Authorization" => "Bearer #{options[:access_token]}"
20
25
  end
21
26
 
22
27
  # including initializer in top of klass
@@ -1,4 +1,4 @@
1
1
  module Auth0
2
2
  # current version of gem
3
- VERSION = "0.9.1"
3
+ VERSION = "0.10"
4
4
  end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+ describe Auth0::Api::V2::Blacklists do
3
+ before :all do
4
+ dummy_instance = DummyClass.new
5
+ dummy_instance.extend(Auth0::Api::V2::Blacklists)
6
+ dummy_instance.extend(Auth0::Api::V2::Router)
7
+ @instance = dummy_instance
8
+ end
9
+
10
+ context ".blacklisted_tokens" do
11
+ it {expect(@instance).to respond_to(:blacklisted_tokens)}
12
+ it "is expected to call /api/v2/blacklists/tokens" do
13
+ expect(@instance).to receive(:get).with("/api/v2/blacklists/tokens")
14
+ expect{@instance.blacklisted_tokens}.not_to raise_error
15
+ end
16
+ end
17
+
18
+ context ".add_token.to_blacklist" do
19
+ it {expect(@instance).to respond_to(:add_token_to_blacklist)}
20
+ it "is expected to call post to /api/v2/blacklists/tokens" do
21
+ expect(@instance).to receive(:post).with("/api/v2/blacklists/tokens", {aud: "aud", jti: "jti"})
22
+ @instance.add_token_to_blacklist("jti", "aud")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+ describe Auth0::Api::V2::Clients do
3
+ before :all do
4
+ dummy_instance = DummyClass.new
5
+ dummy_instance.extend(Auth0::Api::V2::Router)
6
+ dummy_instance.extend(Auth0::Api::V2::Clients)
7
+ @instance = dummy_instance
8
+ end
9
+ context ".clients" do
10
+ it {expect(@instance).to respond_to(:clients)}
11
+ it {expect(@instance).to respond_to(:get_clients)}
12
+ it "is expected to send get request to /api/v2/clients/" do
13
+ expect(@instance).to receive(:get).with("/api/v2/clients", {})
14
+ expect{@instance.clients}.not_to raise_error
15
+ end
16
+ it "is expected to send get request to /api/v2/clients?fields=name&exclude_fields=false" do
17
+ expect(@instance).to receive(:get).with("/api/v2/clients",{exclude_fields: false, fields: [:name]})
18
+ expect{@instance.clients({exclude_fields: false, fields: [:name]})}.not_to raise_error
19
+ end
20
+ end
21
+ context ".client" do
22
+ it {expect(@instance).to respond_to(:client)}
23
+ it "is expected to send get request to /api/v2/clients/1" do
24
+ expect(@instance).to receive(:get).with("/api/v2/clients/1", {})
25
+ expect{@instance.client(1)}.not_to raise_error
26
+ end
27
+ it "is expected to send get request to /api/v2/clients?fields=name&exclude_fields=false" do
28
+ expect(@instance).to receive(:get).with("/api/v2/clients/1",{exclude_fields: false, fields: [:name]})
29
+ expect{@instance.client(1,{exclude_fields: false, fields: [:name]})}.not_to raise_error
30
+ end
31
+ end
32
+
33
+ context ".create_client" do
34
+ it {expect(@instance).to respond_to(:create_client)}
35
+ it "is expected to send post to /api/v2/clients" do
36
+ expect(@instance).to receive(:post).with("/api/v2/clients",{name: "name", opt: "opt"})
37
+ expect{@instance.create_client("name", {name: "/name1", opt: "opt"})}.not_to raise_error
38
+ end
39
+ end
40
+ context ".delete_client" do
41
+ it {expect(@instance).to respond_to(:delete_client)}
42
+ it "is expected to send delete to /api/v2/clients/1" do
43
+ expect(@instance).to receive(:delete).with("/api/v2/clients/1")
44
+ expect{@instance.delete_client("1")}.not_to raise_error
45
+ end
46
+ end
47
+
48
+ context ".patch_client" do
49
+ it {expect(@instance).to respond_to(:patch_client)}
50
+ it "is expected to send patch to /api/v2/clients/1" do
51
+ expect(@instance).to receive(:patch).with("/api/v2/clients/1", {fields: "fields"})
52
+ expect{@instance.patch_client("1", {fields: "fields"})}.not_to raise_error
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+ describe Auth0::Api::V2::Jobs do
3
+ before :all do
4
+ dummy_instance = DummyClass.new
5
+ dummy_instance.extend(Auth0::Api::V2::Router)
6
+ dummy_instance.extend(Auth0::Api::V2::Jobs)
7
+ @instance = dummy_instance
8
+ end
9
+ context ".get_job" do
10
+ it{expect(@instance).to respond_to(:get_job)}
11
+ it "expect client to send get to /api/v2/stats/jobs/3" do
12
+ expect(@instance).to receive(:get).with("/api/v2/jobs/3")
13
+ expect{@instance.get_job(3)}.not_to raise_error
14
+ end
15
+ end
16
+ context ".daily_stats" do
17
+ it{expect(@instance).to respond_to(:create_job)}
18
+ it "expect client to send get to /api/v2/stats/daily" do
19
+ expect{@instance.create_job("file_name","name")}.to raise_error(NotImplementedError)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+ describe Auth0::Api::V2::Stats do
3
+ before :all do
4
+ dummy_instance = DummyClass.new
5
+ dummy_instance.extend(Auth0::Api::V2::Router)
6
+ dummy_instance.extend(Auth0::Api::V2::Stats)
7
+ @instance = dummy_instance
8
+ end
9
+ context ".active_users" do
10
+ it{expect(@instance).to respond_to(:active_users)}
11
+ it "expect client to send get to /api/v2/stats/active-users" do
12
+ expect(@instance).to receive(:get).with("/api/v2/stats/active-users")
13
+ expect{@instance.active_users}.not_to raise_error
14
+ end
15
+ end
16
+ context ".daily_stats" do
17
+ it{expect(@instance).to respond_to(:daily_stats)}
18
+ it "expect client to send get to /api/v2/stats/daily" do
19
+ expect(@instance).to receive(:get).with("/api/v2/stats/daily", {from: "20120222", to: "20151222"})
20
+ expect{@instance.daily_stats("20120222","20151222")}.not_to raise_error
21
+ end
22
+ end
23
+ end