authrocket 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +15 -16
- data/authrocket.gemspec +2 -1
- data/lib/authrocket.rb +3 -2
- data/lib/authrocket/api/api_config.rb +6 -1
- data/lib/authrocket/api/client.rb +14 -0
- data/lib/authrocket/api/version.rb +1 -1
- data/lib/authrocket/app_hook.rb +1 -0
- data/lib/authrocket/event.rb +1 -0
- data/lib/authrocket/realm.rb +4 -2
- data/lib/authrocket/session.rb +56 -0
- data/lib/authrocket/user.rb +1 -0
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f59945f00ec3c5935d070f1011f55b384227f21a
|
4
|
+
data.tar.gz: b14d874dd31885358b4127c6c6d39bc2d533faac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e694cddf853fc34fcef928cf6b7d41c22a158674779e1f2a1a24024bc3a222a3581e915c4c8c10ae0105826f5842a70f1472292c3647342965cc83dee4b1f2e
|
7
|
+
data.tar.gz: cee76d864e476184378695b702c9d77cac710f81463a2e1cb7ada82ad9348c6b6579184a0149f41a9155a4e1621042b0a394c226a8a77818cc966935082c4e69
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -14,22 +14,26 @@ For installation, add `gem 'authrocket'` to your Gemfile. More details are below
|
|
14
14
|
|
15
15
|
By default, AuthRocket automatically loads your credentials from environment variables. For such hosting environments, including Heroku, just configure these:
|
16
16
|
|
17
|
-
AUTHROCKET_ACCOUNT
|
18
|
-
AUTHROCKET_API_KEY
|
19
|
-
AUTHROCKET_URL
|
20
|
-
AUTHROCKET_REALM
|
17
|
+
AUTHROCKET_ACCOUNT = org_SAMPLE
|
18
|
+
AUTHROCKET_API_KEY = key_SAMPLE
|
19
|
+
AUTHROCKET_URL = https://api-e1.authrocket.com/v1
|
20
|
+
AUTHROCKET_REALM = rl_SAMPLE # optional
|
21
|
+
AUTHROCKET_JWT_SECRET = jsk_SAMPLE # optional
|
21
22
|
|
22
23
|
`AUTHROCKET_URL` must be updated based on what cluster your account is provisioned on.
|
23
24
|
|
24
25
|
`AUTHROCKET_REALM` is optional. If you're using a single Realm, it's easiest to add it here as an application-wide default. If you're using multiple Realms with your app, we recommend leaving it out here and setting it as you go.
|
25
26
|
|
27
|
+
`AUTHROCKET_JWT_SECRET` is optional. It only should be included if you've also specified a single realm via AUTHROCKET_REALM *and* you're using hosted logins or authrocket.js. The tokens returned by both are JWT-compatible and can be verified in-app using a matching secret.
|
28
|
+
|
26
29
|
It's possible to configure AuthRocket using a Rails initializer (or other initializaiton code) too.
|
27
30
|
|
28
31
|
AuthRocket::Api.credentials = {
|
29
32
|
account: 'org_SAMPLE',
|
30
33
|
api_key: 'key_SAMPLE',
|
31
34
|
url: 'https://api-e1.authrocket.com/v1',
|
32
|
-
realm: 'rl_SAMPLE'
|
35
|
+
realm: 'rl_SAMPLE',
|
36
|
+
jwt_secret: 'jsk_SAMPLE'
|
33
37
|
}
|
34
38
|
|
35
39
|
|
@@ -58,18 +62,15 @@ Let's add a couple methods to your Application Controller, substituting the corr
|
|
58
62
|
# shown in the Login Policy details.
|
59
63
|
|
60
64
|
def require_user
|
61
|
-
unless
|
65
|
+
unless current_user
|
62
66
|
flash.keep
|
63
67
|
redirect_to LOGIN_URL
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
71
|
+
helper_method :current_user
|
67
72
|
def current_user
|
68
|
-
@_current_user ||=
|
69
|
-
end
|
70
|
-
|
71
|
-
def current_user_name
|
72
|
-
session[:name]
|
73
|
+
@_current_user ||= AuthRocket::Session.from_token(session[:ar_token]).try(:user)
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
@@ -85,10 +86,8 @@ Then add login and logout methods:
|
|
85
86
|
def login
|
86
87
|
flash.keep
|
87
88
|
if params[:token]
|
88
|
-
if
|
89
|
-
|
90
|
-
session[:ar_user_id] = user.id
|
91
|
-
session[:name] = user.name
|
89
|
+
if AuthRocket::Session.from_token(params[:token], within: 60.seconds)
|
90
|
+
session[:ar_token] = params[:token]
|
92
91
|
redirect_to root_path
|
93
92
|
return
|
94
93
|
end
|
@@ -97,7 +96,7 @@ Then add login and logout methods:
|
|
97
96
|
end
|
98
97
|
|
99
98
|
def logout
|
100
|
-
session[:
|
99
|
+
session[:ar_token] = nil
|
101
100
|
redirect_to root_path, notice: 'You have been logged out.'
|
102
101
|
end
|
103
102
|
end
|
data/authrocket.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_dependency 'ncore', '~> 1.
|
21
|
+
gem.add_dependency 'ncore', '~> 1.2'
|
22
|
+
gem.add_dependency 'jwt', '~> 1.2.0'
|
22
23
|
|
23
24
|
gem.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
gem.add_development_dependency "rake"
|
data/lib/authrocket.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'ncore'
|
2
|
+
require 'jwt'
|
2
3
|
|
3
|
-
%w(version api_config).each do |f|
|
4
|
+
%w(version client api_config).each do |f|
|
4
5
|
require "authrocket/api/#{f}"
|
5
6
|
end
|
6
7
|
|
7
|
-
%w(app_hook auth_provider credential event login_policy membership org realm user user_token).each do |f|
|
8
|
+
%w(app_hook auth_provider credential event login_policy membership org realm session user user_token).each do |f|
|
8
9
|
require "authrocket/#{f}"
|
9
10
|
end
|
10
11
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module AuthRocket
|
2
2
|
include NCore::Builder
|
3
|
+
Resource.include AuthRocket::Client
|
4
|
+
SingletonResource.include AuthRocket::Client
|
3
5
|
|
4
6
|
configure do
|
5
7
|
self.default_url = ENV['AUTHROCKET_URL']
|
@@ -16,7 +18,8 @@ module AuthRocket
|
|
16
18
|
self.credentials = {
|
17
19
|
api_key: ENV['AUTHROCKET_API_KEY'],
|
18
20
|
account: ENV['AUTHROCKET_ACCOUNT'],
|
19
|
-
realm: ENV['AUTHROCKET_REALM']
|
21
|
+
realm: ENV['AUTHROCKET_REALM'],
|
22
|
+
jwt_secret: ENV['AUTHROCKET_JWT_SECRET']
|
20
23
|
}
|
21
24
|
end
|
22
25
|
|
@@ -52,6 +55,8 @@ module AuthRocket
|
|
52
55
|
o = {}
|
53
56
|
[url.password, url.user].each do |part|
|
54
57
|
case part
|
58
|
+
when /^jsk_/
|
59
|
+
o[:jwt_secret] = part
|
55
60
|
when /^key_/
|
56
61
|
o[:api_key] = part
|
57
62
|
when /^org_/
|
data/lib/authrocket/app_hook.rb
CHANGED
@@ -16,6 +16,7 @@ module AuthRocket
|
|
16
16
|
org.* org.created org.updated org.deleted
|
17
17
|
membership.* membership.created membership.updated membership.deleted
|
18
18
|
app_hook.* app_hook.created app_hook.updated app_hook.deleted
|
19
|
+
auth_provider.* auth_provider.created auth_provider.updated auth_provider.deleted
|
19
20
|
login_policy.* login_policy.created login_policy.updated login_policy.deleted
|
20
21
|
).sort
|
21
22
|
end
|
data/lib/authrocket/event.rb
CHANGED
@@ -13,6 +13,7 @@ module AuthRocket
|
|
13
13
|
attr_datetime :event_at
|
14
14
|
|
15
15
|
|
16
|
+
# deprecated - use Session.from_token() or Session.find()
|
16
17
|
def self.validate_token(token, params={}, api_creds=nil)
|
17
18
|
parsed, creds = request(:get, "#{url}/login/#{CGI.escape token}", api_creds, params)
|
18
19
|
new(parsed, creds)
|
data/lib/authrocket/realm.rb
CHANGED
@@ -9,8 +9,10 @@ module AuthRocket
|
|
9
9
|
has_many :orgs
|
10
10
|
has_many :users
|
11
11
|
|
12
|
-
attr :api_key_policy, :api_key_prefix, :custom, :name
|
13
|
-
attr :require_unique_emails, :
|
12
|
+
attr :api_key_policy, :api_key_prefix, :custom, :name # :api_key_minutes
|
13
|
+
attr :jwt_data, :require_unique_emails, :session_minutes, :session_type
|
14
|
+
attr :state, :username_validation_human
|
15
|
+
attr :jwt_secret # readonly
|
14
16
|
|
15
17
|
|
16
18
|
def reset!(params={})
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AuthRocket
|
2
|
+
class Session < Resource
|
3
|
+
crud :all, :find, :create, :delete
|
4
|
+
|
5
|
+
belongs_to :user
|
6
|
+
|
7
|
+
attr :ip
|
8
|
+
attr :token # readonly
|
9
|
+
attr_datetime :created_at, :expires_at # readonly
|
10
|
+
|
11
|
+
# options - :within - (in seconds) Maximum time since the token was originally issued
|
12
|
+
def self.from_token(token, options={}, api_creds=nil)
|
13
|
+
secret = (api_creds||credentials)[:jwt_secret]
|
14
|
+
raise Error, "missing :jwt_secret (or AUTHROCKET_JWT_SECRET)" unless secret
|
15
|
+
return unless token
|
16
|
+
|
17
|
+
jwt, _ = JWT.decode token, secret
|
18
|
+
|
19
|
+
if within = options.delete(:within)
|
20
|
+
return if jwt['iat'] < Time.now.to_i - within
|
21
|
+
end
|
22
|
+
|
23
|
+
user = User.new({
|
24
|
+
id: jwt['uid'],
|
25
|
+
username: jwt['un'],
|
26
|
+
first_name: jwt['fn'],
|
27
|
+
last_name: jwt['ln'],
|
28
|
+
name: jwt['n'],
|
29
|
+
memberships: jwt['m'] && jwt['m'].map do |m|
|
30
|
+
Membership.new({
|
31
|
+
permissions: m['p'],
|
32
|
+
user_id: jwt['uid'],
|
33
|
+
org_id: m['oid'],
|
34
|
+
org: m['oid'] && Org.new({
|
35
|
+
id: m['oid'],
|
36
|
+
name: m['o'],
|
37
|
+
}),
|
38
|
+
})
|
39
|
+
end,
|
40
|
+
}, api_creds)
|
41
|
+
session = new({
|
42
|
+
id: jwt['tk'],
|
43
|
+
created_at: jwt['iat'],
|
44
|
+
expires_at: jwt['exp'],
|
45
|
+
token: token,
|
46
|
+
user_id: jwt['uid'],
|
47
|
+
user: user
|
48
|
+
}, api_creds)
|
49
|
+
|
50
|
+
session
|
51
|
+
rescue JWT::DecodeError, JWT::ExpiredSignature
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/authrocket/user.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authrocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ncore
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jwt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,6 +82,7 @@ files:
|
|
68
82
|
- authrocket.gemspec
|
69
83
|
- lib/authrocket.rb
|
70
84
|
- lib/authrocket/api/api_config.rb
|
85
|
+
- lib/authrocket/api/client.rb
|
71
86
|
- lib/authrocket/api/log_subscriber.rb
|
72
87
|
- lib/authrocket/api/railtie.rb
|
73
88
|
- lib/authrocket/api/version.rb
|
@@ -79,6 +94,7 @@ files:
|
|
79
94
|
- lib/authrocket/membership.rb
|
80
95
|
- lib/authrocket/org.rb
|
81
96
|
- lib/authrocket/realm.rb
|
97
|
+
- lib/authrocket/session.rb
|
82
98
|
- lib/authrocket/user.rb
|
83
99
|
- lib/authrocket/user_token.rb
|
84
100
|
homepage: https://authrocket.com/
|