sync_attr_with_auth0 0.0.2
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 +7 -0
- data/lib/sync_attr_with_auth0/auth0.rb +38 -0
- data/lib/sync_attr_with_auth0/model.rb +50 -0
- data/lib/sync_attr_with_auth0.rb +4 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b8fd4fe0d8262793df4e430fb322eeabab071710
|
4
|
+
data.tar.gz: 849ec5ec07920f5dcca3d340011493109e1f3f2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb61a603b3c9c88dbe7fb6a4ed63e2735d786a0a9f7a0a478853e1be5de78325c8cd407a71468c88c100a30c951a76f73fd9097bb7a641374be762b127adb0d0
|
7
|
+
data.tar.gz: cc27922b2519fb9444d4582aa2a854879a30451ca949eae6183d2b247140fa6aa7fd02e6d167dd0d180228c921dd24971a9e33b9180079ed9513cedc51f6f3f6
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module SyncAttrWithAuth0
|
2
|
+
module Auth0
|
3
|
+
|
4
|
+
def self.get_access_token
|
5
|
+
payload = {
|
6
|
+
"client_id" => ENV['AUTH0_CLIENT_ID'],
|
7
|
+
"client_secret" => ENV['AUTH0_CLIENT_SECRET'],
|
8
|
+
"grant_type" => "client_credentials"
|
9
|
+
}
|
10
|
+
|
11
|
+
response = SyncAttrWithAuth0::Auth0.make_request(nil, 'post', '/oauth/token', payload)
|
12
|
+
|
13
|
+
response = JSON.parse( response.to_s ) unless response.nil? or response.to_s.empty?
|
14
|
+
|
15
|
+
response['access_token']
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.make_request(access_token, method, path, payload=nil)
|
19
|
+
args = [method, "https://#{ENV['AUTH0_DOMAIN']}#{path}"]
|
20
|
+
|
21
|
+
# The post body wedges in between the request url
|
22
|
+
# and the request headers for POST and PUT methods
|
23
|
+
args << payload if payload
|
24
|
+
|
25
|
+
if access_token
|
26
|
+
args << { content_type: :json, authorization: "Bearer #{access_token}", accept: "application/json" }
|
27
|
+
|
28
|
+
else
|
29
|
+
args << { content_type: :json, accept: "application/json" }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
# Handle variable length arg lists
|
34
|
+
_response = RestClient.send(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SyncAttrWithAuth0
|
2
|
+
module Model
|
3
|
+
extend ::ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def sync_attr_with_auth0(*args)
|
7
|
+
class_attribute :auth0_uid_att
|
8
|
+
class_attribute :auth0_sync_atts
|
9
|
+
|
10
|
+
self.auth0_uid_att = args.shift
|
11
|
+
|
12
|
+
self.auth0_sync_atts ||= []
|
13
|
+
self.auth0_sync_atts += args.shift.collect(&:to_s)
|
14
|
+
|
15
|
+
after_save :sync_attr_with_auth0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def sync_attr_with_auth0
|
20
|
+
# Look for matches between what's changing
|
21
|
+
# and what needs to be transmitted to Auth0
|
22
|
+
matches = ( (self.class.auth0_sync_atts || []) & (self.changes.keys || []) )
|
23
|
+
|
24
|
+
# If we find matches
|
25
|
+
unless matches.empty?
|
26
|
+
|
27
|
+
# Get an access token
|
28
|
+
access_token = SyncAttrWithAuth0::Auth0.get_access_token
|
29
|
+
|
30
|
+
# Figure out what needs to be sent to Auth0
|
31
|
+
changes = {}
|
32
|
+
matches.each do |m|
|
33
|
+
changes[m] = self.send(m)
|
34
|
+
end
|
35
|
+
|
36
|
+
# If we actually have changes
|
37
|
+
unless changes.empty?
|
38
|
+
response = SyncAttrWithAuth0::Auth0.make_request(
|
39
|
+
access_token,
|
40
|
+
'patch',
|
41
|
+
"/api/users/#{::URI.escape( self.send(auth0_uid_att) )}/metadata",
|
42
|
+
changes)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
true # don't abort the callback chain
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sync_attr_with_auth0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick McGraw
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Synchronize attributes on a local ActiveRecord user model with the user
|
98
|
+
metadata store on Auth0
|
99
|
+
email: patrick@mcgraw-tech.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/sync_attr_with_auth0.rb
|
105
|
+
- lib/sync_attr_with_auth0/auth0.rb
|
106
|
+
- lib/sync_attr_with_auth0/model.rb
|
107
|
+
homepage: http://rubygems.org/gems/sync_attr_with_auth0
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.4.5
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Synchronize attributes on a local ActiveRecord user model with the user metadata
|
131
|
+
store on Auth0
|
132
|
+
test_files: []
|