auth0 2.1.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundle/config +2 -0
- data/.gitignore +5 -2
- data/.rspec +3 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +68 -0
- data/auth0.gemspec +11 -10
- data/doc/Auth0/AccessDenied.html +142 -0
- data/doc/Auth0/Api/AuthenticationEndpoints.html +592 -0
- data/doc/Auth0/Api/V1/Clients.html +440 -0
- data/doc/Auth0/Api/V1/Connections.html +506 -0
- data/doc/Auth0/Api/V1/Logs.html +366 -0
- data/doc/Auth0/Api/V1/Rules.html +439 -0
- data/doc/Auth0/Api/V1/Users.html +1617 -0
- data/doc/Auth0/Api/V1.html +188 -0
- data/doc/Auth0/Api/V2/Blacklists.html +268 -0
- data/doc/Auth0/Api/V2/Clients.html +477 -0
- data/doc/Auth0/Api/V2/Jobs.html +277 -0
- data/doc/Auth0/Api/V2/Router.html +109 -0
- data/doc/Auth0/Api/V2/Stats.html +268 -0
- data/doc/Auth0/Api/V2/Users.html +652 -0
- data/doc/Auth0/Api/V2.html +193 -0
- data/doc/Auth0/Api.html +128 -0
- data/doc/Auth0/BadRequest.html +142 -0
- data/doc/Auth0/Client.html +164 -0
- data/doc/Auth0/Exception.html +140 -0
- data/doc/Auth0/InvalidParameter.html +142 -0
- data/doc/Auth0/Mixins/HTTPartyProxy.html +121 -0
- data/doc/Auth0/Mixins/Initializer.html +312 -0
- data/doc/Auth0/Mixins.html +153 -0
- data/doc/Auth0/NotFound.html +143 -0
- data/doc/Auth0/ServerError.html +142 -0
- data/doc/Auth0/Unauthorized.html +143 -0
- data/doc/Auth0/Unsupported.html +142 -0
- data/doc/Auth0/UserIdIsBlank.html +143 -0
- data/doc/Auth0.html +153 -0
- data/doc/Auth0Client.html +163 -0
- data/doc/_index.html +418 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +103 -0
- data/doc/file_list.html +60 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +103 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +435 -0
- data/doc/top-level-namespace.html +114 -0
- data/lib/auth0/api/authentication_endpoints.rb +71 -0
- data/lib/auth0/api/v1/clients.rb +48 -0
- data/lib/auth0/api/v1/connections.rb +51 -0
- data/lib/auth0/api/v1/logs.rb +41 -0
- data/lib/auth0/api/v1/rules.rb +44 -0
- data/lib/auth0/api/v1/users.rb +163 -0
- data/lib/auth0/api/v1.rb +19 -0
- data/lib/auth0/api/v2/blacklists.rb +24 -0
- data/lib/auth0/api/v2/clients.rb +41 -0
- data/lib/auth0/api/v2/jobs.rb +20 -0
- data/lib/auth0/api/v2/stats.rb +24 -0
- data/lib/auth0/api/v2/users.rb +67 -0
- data/lib/auth0/api/v2.rb +17 -0
- data/lib/auth0/client.rb +5 -48
- data/lib/auth0/exception.rb +22 -0
- data/lib/auth0/mixins/httparty_proxy.rb +35 -0
- data/lib/auth0/mixins/initializer.rb +34 -0
- data/lib/auth0/mixins.rb +12 -0
- data/lib/auth0/version.rb +3 -2
- data/lib/auth0.rb +6 -1
- data/lib/auth0_client.rb +3 -0
- data/spec/lib/auth0/api/authentication_endpoints_spec.rb +56 -0
- data/spec/lib/auth0/api/v1/clients_spec.rb +62 -0
- data/spec/lib/auth0/api/v1/connections_spec.rb +62 -0
- data/spec/lib/auth0/api/v1/logs_spec.rb +46 -0
- data/spec/lib/auth0/api/v1/rules_spec.rb +40 -0
- data/spec/lib/auth0/api/v1/users_spec.rb +217 -0
- data/spec/lib/auth0/api/v2/blacklists_spec.rb +24 -0
- data/spec/lib/auth0/api/v2/clients_spec.rb +54 -0
- data/spec/lib/auth0/api/v2/jobs_spec.rb +21 -0
- data/spec/lib/auth0/api/v2/stats_spec.rb +22 -0
- data/spec/lib/auth0/api/v2/users_spec.rb +72 -0
- data/spec/lib/auth0/client_spec.rb +47 -0
- data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +119 -0
- data/spec/lib/auth0_client_spec.rb +8 -0
- data/spec/spec_helper.rb +8 -7
- data/spec/support/dummy_class.rb +7 -0
- data/spec/support/dummy_class_for_proxy.rb +4 -0
- data/spec/support/stub_response.rb +2 -0
- metadata +159 -28
- data/lib/omniauth/strategies/auth0.rb +0 -62
- data/spec/omniauth/strategies/auth0_spec.rb +0 -149
@@ -0,0 +1,51 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
# {https://auth0.com/docs/api#connections}
|
5
|
+
module Connections
|
6
|
+
# {https://auth0.com/docs/api#!#get--api-connections}
|
7
|
+
def connections
|
8
|
+
get("/api/connections")
|
9
|
+
end
|
10
|
+
alias :get_connections :connections
|
11
|
+
|
12
|
+
# {https://auth0.com/docs/api#!#get--api-connections--connection-name-}
|
13
|
+
def connection(connection_name)
|
14
|
+
path = "/api/connections/#{connection_name.to_s}"
|
15
|
+
get(path)
|
16
|
+
end
|
17
|
+
alias :get_connection :connection
|
18
|
+
|
19
|
+
# {https://auth0.com/docs/api#!#delete--api-connections--connection-name-}
|
20
|
+
def delete_connection(connection_name)
|
21
|
+
path = "/api/connections/#{connection_name.to_s}"
|
22
|
+
delete(path)
|
23
|
+
end
|
24
|
+
|
25
|
+
# {https://auth0.com/docs/api#!#post--api-connections}
|
26
|
+
def create_connection(connection_name, strategy, tenant_domain, domain_aliases=nil)
|
27
|
+
path = "/api/connections"
|
28
|
+
request_params = { name: connection_name,
|
29
|
+
strategy: strategy,
|
30
|
+
options: {
|
31
|
+
tenant_domain: tenant_domain,
|
32
|
+
domain_aliases: domain_aliases
|
33
|
+
}
|
34
|
+
}
|
35
|
+
post(path, request_params)
|
36
|
+
end
|
37
|
+
|
38
|
+
# {https://auth0.com/docs/api#!#put--api-connections--connection-name-}
|
39
|
+
def update_connection(connection_name, tenant_domain, status=true)
|
40
|
+
path = "/api/connections/#{connection_name}"
|
41
|
+
request_params = { status: status,
|
42
|
+
options: {
|
43
|
+
tenant_domain: tenant_domain
|
44
|
+
}
|
45
|
+
}
|
46
|
+
put(path, request_params)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
# {https://auth0.com/docs/api#logs}
|
5
|
+
module Logs
|
6
|
+
# {https://auth0.com/docs/api#!#get--api-logs-page--number--per_page--items--sort--field----1-1--fields--fields--exclude_fields-true-false-}
|
7
|
+
#
|
8
|
+
# {https://auth0.com/docs/api#!#get--api-logs-search--criteria-}
|
9
|
+
#
|
10
|
+
# {https://auth0.com/docs/api#!#get--api-logs-from--checkpointId--take--count-}
|
11
|
+
def logs(options={})
|
12
|
+
acceptable_params = %i(take from search_criteria page per_page sort fields exclude_fields)
|
13
|
+
options.reject! do |key,value|
|
14
|
+
if key.nil? ||\
|
15
|
+
value.nil? ||\
|
16
|
+
!acceptable_params.include?(key.to_sym)
|
17
|
+
warn "#{key} is not in acceptable params list: #{acceptable_params}"
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
path= "/api/logs?"+URI.encode_www_form(options)
|
22
|
+
get(path)
|
23
|
+
end
|
24
|
+
|
25
|
+
alias :search_logs :logs
|
26
|
+
|
27
|
+
# {https://auth0.com/docs/api#!#get--api-logs--_id-}
|
28
|
+
def log(id)
|
29
|
+
path = "/api/logs/#{id}"
|
30
|
+
get(path)
|
31
|
+
end
|
32
|
+
|
33
|
+
# {https://auth0.com/docs/api#!#get--api-users--user_id--logs-page--number--per_page--items-}
|
34
|
+
def user_logs(user_id, page=0, per_page=50)
|
35
|
+
path = "/api/users/#{user_id}/logs?page=#{page}&per_page=#{per_page}"
|
36
|
+
get(path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
# https://auth0.com/docs/api#rules
|
5
|
+
module Rules
|
6
|
+
# https://auth0.com/docs/api#!#get--api-rules
|
7
|
+
def rules
|
8
|
+
path = "/api/rules"
|
9
|
+
get(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
alias :get_rules :rules
|
13
|
+
|
14
|
+
# https://auth0.com/docs/api#!#post--api-rules
|
15
|
+
def create_rule(name, script, order=nil,status=true)
|
16
|
+
path = "/api/rules"
|
17
|
+
request_params = { name: name,
|
18
|
+
status: status,
|
19
|
+
script: script,
|
20
|
+
order: order
|
21
|
+
}
|
22
|
+
post(path, request_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
# https://auth0.com/docs/api#!#put--api-rules--rule-name-
|
26
|
+
def update_rule(name, script, order=nil,status=true)
|
27
|
+
path = "/api/rules/#{name}"
|
28
|
+
request_params = {
|
29
|
+
status: status,
|
30
|
+
script: script,
|
31
|
+
order: order
|
32
|
+
}
|
33
|
+
put(path, request_params)
|
34
|
+
end
|
35
|
+
|
36
|
+
# https://auth0.com/docs/api#!#delete--api-rules--rule-name-
|
37
|
+
def delete_rule(name)
|
38
|
+
path = "/api/rules/#{name}"
|
39
|
+
delete(path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
# {https://auth0.com/docs/api#users}
|
5
|
+
module Users
|
6
|
+
# {https://auth0.com/docs/api#!#get--api-users}
|
7
|
+
#
|
8
|
+
# {https://auth0.com/docs/api#!#get--api-users-search--criteria-}
|
9
|
+
def users(search=nil)
|
10
|
+
path = "/api/users"
|
11
|
+
path += "?search=#{search.to_s}" unless search.to_s.empty?
|
12
|
+
get(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
alias :users_search :users
|
16
|
+
alias :get_users :users
|
17
|
+
|
18
|
+
# {https://auth0.com/docs/api#!#get--api-users--user_id-}
|
19
|
+
def user(user_id)
|
20
|
+
path = "/api/users/#{user_id}"
|
21
|
+
get(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
alias :get_user :user
|
25
|
+
|
26
|
+
# {https://auth0.com/docs/api#!#get--api-users--user_id--devices}
|
27
|
+
def user_devices(user_id)
|
28
|
+
path = "/api/users/#{user_id}/devices"
|
29
|
+
get(path)
|
30
|
+
end
|
31
|
+
|
32
|
+
# {https://auth0.com/docs/api#!#get--api-connections--connection--users}
|
33
|
+
# {https://auth0.com/docs/api#!#get--api-connections--connection--users-search--criteria-}
|
34
|
+
def connection_users(connection_name, search=nil)
|
35
|
+
path = "/api/connections/#{connection_name}/users"
|
36
|
+
path += "?search=#{search.to_s}" unless search.to_s.empty?
|
37
|
+
get(path)
|
38
|
+
end
|
39
|
+
|
40
|
+
alias :search_connection_users :connection_users
|
41
|
+
|
42
|
+
# {https://auth0.com/docs/api#!#get--api-enterpriseconnections-users-search--criteria-}
|
43
|
+
def enterpriseconnections_users(search_criteria=nil, per_page=500)
|
44
|
+
path = "/api/enterpriseconnections/users?search=#{search_criteria.to_s}&per_page=#{per_page.to_i.to_s}"
|
45
|
+
get(path)
|
46
|
+
end
|
47
|
+
|
48
|
+
# {https://auth0.com/docs/api#!#get--api-socialconnections-users-search--criteria-}
|
49
|
+
def socialconnections_users(search_criteria=nil, per_page=500)
|
50
|
+
path = "/api/socialconnections/users?search=#{search_criteria.to_s}&per_page=#{per_page.to_i.to_s}"
|
51
|
+
get(path)
|
52
|
+
end
|
53
|
+
|
54
|
+
# {https://auth0.com/docs/api#!#get--api-clients--client-id--users}
|
55
|
+
def client_users(client_id=@client_id)
|
56
|
+
path = "/api/clients/#{client_id}/users"
|
57
|
+
get(path)
|
58
|
+
end
|
59
|
+
|
60
|
+
# {https://auth0.com/docs/api#!#post--api-users}
|
61
|
+
def create_user(email, password, connection_name, request_params={})
|
62
|
+
options = { email: email, password: password, connection: connection_name }
|
63
|
+
request_params.merge!(options)
|
64
|
+
path = "/api/users"
|
65
|
+
post(path, request_params)
|
66
|
+
end
|
67
|
+
|
68
|
+
# {https://auth0.com/docs/api#!#post--api-users--user_id--send_verification_email}
|
69
|
+
def send_verification_email(user_id)
|
70
|
+
path = "/api/users/#{user_id}/send_verification_email"
|
71
|
+
post(path)
|
72
|
+
end
|
73
|
+
|
74
|
+
# {https://auth0.com/docs/api#!#post--api-users--user_id--change_password_ticket}
|
75
|
+
def change_password_ticket(user_id, new_password, result_url=nil)
|
76
|
+
request_params = { "newPassword" => new_password, "resultUrl" => result_url }
|
77
|
+
path = "/api/users/#{user_id}/change_password_ticket"
|
78
|
+
post(path, request_params)
|
79
|
+
end
|
80
|
+
|
81
|
+
# {https://auth0.com/docs/api#!#post--api-users--user_id--verification_ticket}
|
82
|
+
def verification_ticket(user_id, result_url=nil)
|
83
|
+
request_params = {"resultUrl" => result_url}
|
84
|
+
path = "/api/users/#{user_id}/verification_ticket"
|
85
|
+
post(path, request_params)
|
86
|
+
end
|
87
|
+
|
88
|
+
# {https://auth0.com/docs/api#!#post--api-users--user_id--publickey}
|
89
|
+
def create_public_key(user_id, device, public_key)
|
90
|
+
path = "/api/users/#{user_id}/public_key"
|
91
|
+
request_params = { device: device, public_key: public_key }
|
92
|
+
post(path, request_params)
|
93
|
+
end
|
94
|
+
|
95
|
+
# {https://auth0.com/docs/api#!#put--api-users--user_id--email}
|
96
|
+
def update_user_email(user_id, email, verify=true)
|
97
|
+
path = "/api/users/#{user_id}/email"
|
98
|
+
request_params = { email: email, verify: verify }
|
99
|
+
put(path, request_params)
|
100
|
+
end
|
101
|
+
|
102
|
+
# {https://auth0.com/docs/api#!#put--api-users--user_id--metadata}
|
103
|
+
# This will overwrite user's metadata, be really carefull, preffer using patch instead
|
104
|
+
def update_user_metadata(user_id, metadata={})
|
105
|
+
path = "/api/users/#{user_id}/metadata"
|
106
|
+
put(path, metadata)
|
107
|
+
end
|
108
|
+
|
109
|
+
# {https://auth0.com/docs/api#!#put--api-users--user_id--password}
|
110
|
+
def update_user_password(user_id, password, verify=true)
|
111
|
+
path = "/api/users/#{user_id}/password"
|
112
|
+
request_params = { password: password, verify: verify }
|
113
|
+
put(path, request_params)
|
114
|
+
end
|
115
|
+
|
116
|
+
# {https://auth0.com/docs/api#!#put--api-users--email--password}
|
117
|
+
def update_user_password_using_email(email, password, connection_name, verify=true)
|
118
|
+
request_params = {
|
119
|
+
email: email,
|
120
|
+
password: password,
|
121
|
+
connection: connection_name,
|
122
|
+
verify: verify
|
123
|
+
}
|
124
|
+
path = "/api/users/#{email}/password"
|
125
|
+
put(path, request_params)
|
126
|
+
end
|
127
|
+
|
128
|
+
# {https://auth0.com/docs/api#!#patch--api-users--user_id--metadata}
|
129
|
+
def patch_user_metadata(user_id, metadata={})
|
130
|
+
path = "/api/users/#{user_id}/metadata"
|
131
|
+
patch(path, metadata)
|
132
|
+
end
|
133
|
+
|
134
|
+
# {https://auth0.com/docs/api#!#delete--api-users}
|
135
|
+
#
|
136
|
+
# This will remove all your users
|
137
|
+
def delete_users
|
138
|
+
path = "/api/users/"
|
139
|
+
delete(path)
|
140
|
+
end
|
141
|
+
|
142
|
+
# {https://auth0.com/docs/api#!#delete--api-users--user_id-}
|
143
|
+
def delete_user(user_id)
|
144
|
+
raise Auth0::UserIdIsBlank, "if you want to remove all users user delete_users method" if user_id.to_s.empty?
|
145
|
+
path = "/api/users/#{user_id}"
|
146
|
+
delete(path)
|
147
|
+
end
|
148
|
+
|
149
|
+
# {https://auth0.com/docs/api#!#delete--api-users--user_id--refresh_tokens--refresh_token-}
|
150
|
+
def revoke_user_refresh_token(user_id, refresh_token)
|
151
|
+
path = "/api/users/#{user_id}/refresh_tokens/#{refresh_token}"
|
152
|
+
delete(path)
|
153
|
+
end
|
154
|
+
|
155
|
+
# {https://auth0.com/docs/api#!#delete--api-users--user_id--publickey-device--device-}
|
156
|
+
def revoke_user_device_public_key(user_id, device)
|
157
|
+
path = "/api/users/#{user_id}/publickey?device=#{device}"
|
158
|
+
delete(path)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
data/lib/auth0/api/v1.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "auth0/api/v1/users"
|
2
|
+
require "auth0/api/v1/clients"
|
3
|
+
require "auth0/api/v1/connections"
|
4
|
+
require "auth0/api/v1/rules"
|
5
|
+
require "auth0/api/v1/logs"
|
6
|
+
module Auth0
|
7
|
+
# Space for all API calls
|
8
|
+
module Api
|
9
|
+
# {https://auth0.com/docs/api}
|
10
|
+
# Describing current functionality of Auth0 API V1
|
11
|
+
module V1
|
12
|
+
include Auth0::Api::V1::Users
|
13
|
+
include Auth0::Api::V1::Connections
|
14
|
+
include Auth0::Api::V1::Clients
|
15
|
+
include Auth0::Api::V1::Rules
|
16
|
+
include Auth0::Api::V1::Logs
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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
|
+
path = "/api/v2/blacklists/tokens"
|
9
|
+
get(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
# https://auth0.com/docs/apiv2#!/blacklists/post_tokens
|
13
|
+
def add_token_to_blacklist(jti, aud=nil)
|
14
|
+
request_params = {
|
15
|
+
jti: jti,
|
16
|
+
aud: aud
|
17
|
+
}
|
18
|
+
path = "/api/v2/blacklists/tokens"
|
19
|
+
post(path, request_params)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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
|
+
path = "/api/v2/clients"
|
9
|
+
get(path, options)
|
10
|
+
end
|
11
|
+
alias :get_clients :clients
|
12
|
+
|
13
|
+
#https://auth0.com/docs/apiv2#!/clients/post_clients
|
14
|
+
def create_client(name, options={})
|
15
|
+
request_params = Hash[options.map{|(k,v)| [k.to_sym,v]}]
|
16
|
+
request_params[:name] = name
|
17
|
+
path = "/api/v2/clients"
|
18
|
+
post(path, request_params)
|
19
|
+
end
|
20
|
+
|
21
|
+
#https://auth0.com/docs/apiv2#!/clients/get_clients_by_id
|
22
|
+
def client(client_id, options={})
|
23
|
+
path = "/api/v2/clients/" + client_id.to_s
|
24
|
+
get(path, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
#https://auth0.com/docs/apiv2#!/clients/delete_clients_by_id
|
28
|
+
def delete_client(client_id)
|
29
|
+
path = "/api/v2/clients/" + client_id.to_s
|
30
|
+
delete(path)
|
31
|
+
end
|
32
|
+
|
33
|
+
#https://auth0.com/docs/apiv2#!/clients/patch_clients_by_id
|
34
|
+
def patch_client(client_id, options)
|
35
|
+
path = "/api/v2/clients/" + client_id.to_s
|
36
|
+
patch(path, options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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,24 @@
|
|
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
|
+
path = "/api/v2/stats/active-users"
|
9
|
+
get(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
#https://auth0.com/docs/apiv2#!/stats/get_daily
|
13
|
+
def daily_stats(from, to)
|
14
|
+
path = "/api/v2/stats/daily"
|
15
|
+
request_params = {
|
16
|
+
from: from,
|
17
|
+
to: to
|
18
|
+
}
|
19
|
+
get(path, request_params)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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
|
+
path = "/api/v2/users"
|
18
|
+
get(path, request_params)
|
19
|
+
end
|
20
|
+
alias :get_users :users
|
21
|
+
|
22
|
+
#https://auth0.com/docs/apiv2#!/users/post_users
|
23
|
+
def create_user(name, options={})
|
24
|
+
path = "/api/v2/users"
|
25
|
+
request_params = Hash[options.map{|(k,v)| [k.to_sym,v]}]
|
26
|
+
request_params[:name] = name
|
27
|
+
post(path, request_params)
|
28
|
+
end
|
29
|
+
|
30
|
+
#https://auth0.com/docs/apiv2#!/users/delete_users
|
31
|
+
def delete_users
|
32
|
+
path = "/api/v2/users"
|
33
|
+
delete(path)
|
34
|
+
end
|
35
|
+
|
36
|
+
#https://auth0.com/docs/apiv2#!/users/get_users_by_id
|
37
|
+
def user(user_id, fields: nil, exclude_fields: nil)
|
38
|
+
path = "/api/v2/users/" + user_id.to_s
|
39
|
+
request_params = { fields: fields,
|
40
|
+
exclude_fields: exclude_fields
|
41
|
+
}
|
42
|
+
get(path, request_params)
|
43
|
+
end
|
44
|
+
|
45
|
+
#https://auth0.com/docs/apiv2#!/users/delete_users_by_id
|
46
|
+
def delete_user(user_id)
|
47
|
+
raise Auth0::UserIdIsBlank, "if you want to remove all users user delete_users method" if user_id.to_s.empty?
|
48
|
+
path = "/api/v2/users/" + user_id.to_s
|
49
|
+
delete(path)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
#https://auth0.com/docs/apiv2#!/users/patch_users_by_id
|
54
|
+
def patch_user(user_id, options)
|
55
|
+
path = "/api/v2/users/" + user_id
|
56
|
+
patch(path, options)
|
57
|
+
end
|
58
|
+
|
59
|
+
#https://auth0.com/docs/apiv2#!/users/delete_multifactor_by_provider
|
60
|
+
def delete_user_provider(user_id, provider_name)
|
61
|
+
path = "/api/v2/users/#{user_id}/multifactor/#{provider_name}"
|
62
|
+
delete(path)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/auth0/api/v2.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "auth0/api/v2/clients"
|
2
|
+
require "auth0/api/v2/users"
|
3
|
+
require "auth0/api/v2/blacklists"
|
4
|
+
require "auth0/api/v2/jobs"
|
5
|
+
require "auth0/api/v2/stats"
|
6
|
+
module Auth0
|
7
|
+
module Api
|
8
|
+
# https://auth0.com/docs/apiv2
|
9
|
+
module V2
|
10
|
+
include Auth0::Api::V2::Clients
|
11
|
+
include Auth0::Api::V2::Users
|
12
|
+
include Auth0::Api::V2::Blacklists
|
13
|
+
include Auth0::Api::V2::Jobs
|
14
|
+
include Auth0::Api::V2::Stats
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/auth0/client.rb
CHANGED
@@ -1,50 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class
|
1
|
+
# Main class
|
2
|
+
# All Api calls are suposed to return hashes, but delete actions return strings.
|
3
|
+
class Auth0::Client
|
4
|
+
include Auth0::Mixins
|
4
5
|
include HTTParty
|
5
|
-
base_uri
|
6
|
-
|
7
|
-
def initialize(options)
|
8
|
-
self.class.base_uri "https://#{options[:namespace]}"
|
9
|
-
|
10
|
-
token_reponse = self.class.post("/oauth/token", {
|
11
|
-
body: {
|
12
|
-
'client_id' => options[:client_id],
|
13
|
-
'client_secret' => options[:client_secret],
|
14
|
-
'grant_type' => 'client_credentials'
|
15
|
-
}
|
16
|
-
})
|
17
|
-
|
18
|
-
unless token_reponse.code == 200
|
19
|
-
raise "Error geting the token: #{token_reponse.body}"
|
20
|
-
end
|
21
|
-
|
22
|
-
@token = token_reponse["access_token"]
|
23
|
-
@headers = {
|
24
|
-
"Authorization" => "Bearer #{@token}"
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_connections
|
29
|
-
response = self.class.get("/api/connections", { headers: @headers })
|
30
|
-
response.body
|
31
|
-
end
|
32
|
-
|
33
|
-
def delete_user(id)
|
34
|
-
response = self.class.delete("/api/users/#{id}", { headers: @headers })
|
35
|
-
response.body
|
36
|
-
end
|
37
|
-
|
38
|
-
def delegation(options)
|
39
|
-
response = self.class.post("/delegation", {
|
40
|
-
body: {
|
41
|
-
client_id: options[:client_id],
|
42
|
-
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
43
|
-
id_token: options[:id_token],
|
44
|
-
target: options[:target],
|
45
|
-
scope: "open_id"
|
46
|
-
}
|
47
|
-
})
|
48
|
-
response.body
|
49
|
-
end
|
6
|
+
base_uri "http://auth0.com"
|
50
7
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Auth0
|
2
|
+
# Default exception in namespace of Auth0
|
3
|
+
# if you want to catch all exceptions, then you should use this one.
|
4
|
+
# Network exceptions are not included
|
5
|
+
class Exception < StandardError; end
|
6
|
+
end
|
7
|
+
# exception for unauthorized requests, if you see it, probably Bearer Token is not set correctly
|
8
|
+
class Auth0::Unauthorized < Auth0::Exception; end
|
9
|
+
# exception for not found resource, you query for an unexistent resource, or wrong path
|
10
|
+
class Auth0::NotFound < Auth0::Exception; end
|
11
|
+
# exception for unknown error
|
12
|
+
class Auth0::Unsupported < Auth0::Exception; end
|
13
|
+
# exception for server error
|
14
|
+
class Auth0::ServerError < Auth0::Exception; end
|
15
|
+
# exception for incorrect request, you've sent wrong params
|
16
|
+
class Auth0::BadRequest < Auth0::Exception; end
|
17
|
+
# exception for unset user_id, this might cause removal of all users, or other unexpected bahaviour
|
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
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Mixins
|
3
|
+
# here's the proxy for HTTParty, we're building all request on that gem for now, if you want to feel free to use your own http client
|
4
|
+
module HTTPartyProxy
|
5
|
+
# proxying requests from instance methods to HTTParty class methods
|
6
|
+
%i(get post put patch delete).each do |method|
|
7
|
+
define_method(method) do |path, body={}|
|
8
|
+
safe_path = URI.escape(path)
|
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
|
15
|
+
response_body =
|
16
|
+
begin
|
17
|
+
JSON.parse(result.body.to_s)
|
18
|
+
rescue JSON::ParserError
|
19
|
+
result.body
|
20
|
+
end
|
21
|
+
case result.code
|
22
|
+
when 200...226 then response_body
|
23
|
+
when 400 then raise Auth0::BadRequest, response_body
|
24
|
+
when 401 then raise Auth0::Unauthorized, response_body
|
25
|
+
when 403 then raise Auth0::AccessDenied, response_body
|
26
|
+
when 404 then raise Auth0::NotFound, response_body
|
27
|
+
when 500 then raise Auth0::ServerError, response_body
|
28
|
+
else
|
29
|
+
raise Auth0::Unsupported, response_body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Auth0
|
2
|
+
module Mixins
|
3
|
+
# Help class where Auth0::Client initialization described
|
4
|
+
module Initializer
|
5
|
+
# Default initialization mechanism, moved here to keep Auth0::Client clear
|
6
|
+
# accepts hash as parameter
|
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
|
10
|
+
def initialize(config)
|
11
|
+
options = Hash[config.map{|(k,v)| [k.to_sym,v]}]
|
12
|
+
self.class.base_uri "https://#{options[:namespace]}"
|
13
|
+
self.class.headers "Content-Type" => 'application/json'
|
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
|
23
|
+
end
|
24
|
+
self.class.headers "Authorization" => "Bearer #{options[:access_token]}"
|
25
|
+
end
|
26
|
+
|
27
|
+
# including initializer in top of klass
|
28
|
+
def self.included(klass)
|
29
|
+
klass.send :prepend, Initializer
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|