authrocket 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48a34e5c646665a7020363a9a8ade5fb317d8699
4
- data.tar.gz: faad858997b34e9c776a1289be6213ab33f6a1a6
3
+ metadata.gz: 9b93720c4868bc866ad26340e6c88fd3b87f9aa9
4
+ data.tar.gz: f4b1767d3c7e684357231ed206130ea84778d3a7
5
5
  SHA512:
6
- metadata.gz: b11966d0c17a23302c3cf9f4eefe409513e0bccc345dbe1f5894b17c674cb3c31def9c2ad54e3a7eacac0f120d12e31054a34b043a93d5e43526909414b91e87
7
- data.tar.gz: ba4dbda5bb51a4a75555c380d2393e719223b0a69d96e2a07ea607f99f7b6983d96d67e5db56ed821669d00e093aa72d5553f82c00bd632bfa42c1b4c3719dfe
6
+ metadata.gz: cc756a62eadb6dc8ce8e8da0f51916f9532e609c1caa4fada2a4d04e3ad4de66fca5cab23e1c338d502d21ae83b949ff9c805515c7dcd7f76596910a5181ee00
7
+ data.tar.gz: 6a9f6617e7c98dad6ff441ddc25792f36e950fd7643943a21d34fe8c4dd9e3fa9c1d041504a171872a8f142ba3779b56ce72e66811b5497be5baa0d8c211f9ac
data/CHANGELOG.md CHANGED
@@ -1,30 +1,63 @@
1
+ #### 2.0.0
2
+
3
+ - NOTE: This version includes breaking changes.
4
+ - Depends on ncore 2.0
5
+ - ncore update changes most method signatures to remove the final api_creds param - use a :credentials key instead:
6
+ Old: User.create(params, api_creds)
7
+ New: User.create(params.merge(credentials: api_creds))
8
+ - As api_creds is not generally needed, this should affect few people
9
+ - No longer depends on 'multi_json', but uses it if available. Defaults to stdlib 'json'.
10
+ - find(nil) now raises RecordNotFound instead of returning nil
11
+ - User.reset_password_with_token signature change:
12
+ Old: reset_password_with_token(username, token, new_pw, new_pw_2, params={}, api_creds)
13
+ New: reset_password_with_token(username: '...', token: '...', password: '...', password_confirmation: '...', ...)
14
+ - Remove previously deprecated Event.validate_token
15
+ - Remove previously deprecated LoginPolicy#enable_logins, #enable_signups, #name_field
16
+ - Remove previously deprecated User#api_key, #last_login_on
17
+ - Add Event#request_data, Session#request_data
18
+ - Remove Event#ip, Session#ip, and Session#client - use #request_data['ip'] or #request_data['client'] instead
19
+ - Add AppHook#email_from_name
20
+ - Add AuthProvider#authorize_token
21
+ - Detect new ko_ API keys
22
+ - Support email verification
23
+ - Add LoginPolicy#redirect_uris
24
+ - Fix issue with older rubies
25
+
1
26
  #### 1.5.0
27
+
2
28
  - Update Event and add Notification
3
29
 
4
30
  #### 1.4.4
31
+
5
32
  - Bump to jwt 1.5
6
33
  - Enforce hmac algorithm for jwt
7
- - Add AuthProvider.min_complexity, .required_chars
34
+ - Add AuthProvider#min_complexity, #required_chars
8
35
 
9
36
  #### 1.4.3
10
- - Add AuthProvider.min_length
37
+
38
+ - Add AuthProvider#min_length
11
39
 
12
40
  #### 1.4.2
13
- - Add AppHook.email_renderer
41
+
42
+ - Add AppHook#email_renderer
14
43
 
15
44
  #### 1.4.1
45
+
16
46
  - Bump to jwt 1.4
17
- - Add AppHook.email_to
47
+ - Add AppHook#email_to
18
48
  - Update AppHook.event_types
19
49
 
20
50
  #### 1.4.0
51
+
21
52
  - Support social auth in AuthProvider and Credential
22
53
 
23
54
  #### 1.3.1
55
+
24
56
  - Add Realm#api_key_minutes
25
57
  - Add Session#client
26
58
 
27
59
  #### 1.3.0
60
+
28
61
  - Add Session resource
29
62
  - Deprecate Event.validate_token - Replaced by Session.from_token and Session.find
30
63
  - Add missing auth_provider.* events
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [AuthRocket](http://authrocket.com/) provides Auth as a Service, making it quick and easy to add signups, logins, a full user management UI, and much more to your app.
4
4
 
5
- This gem works with both Rails and plain Ruby. It will auto-detect Rails and enable a couple Rails-specific features as appropriate.
5
+ This gem works with both Rails and plain Ruby. It will auto-detect Rails and enable Rails-specific features as appropriate.
6
6
 
7
7
 
8
8
  ## Usage
@@ -14,8 +14,7 @@ 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 = org_SAMPLE
18
- AUTHROCKET_API_KEY = key_SAMPLE
17
+ AUTHROCKET_API_KEY = ko_SAMPLE
19
18
  AUTHROCKET_URL = https://api-e1.authrocket.com/v1
20
19
  AUTHROCKET_REALM = rl_SAMPLE # optional
21
20
  AUTHROCKET_JWT_SECRET = jsk_SAMPLE # optional
@@ -29,8 +28,7 @@ By default, AuthRocket automatically loads your credentials from environment var
29
28
  It's possible to configure AuthRocket using a Rails initializer (or other initializaiton code) too.
30
29
 
31
30
  AuthRocket::Api.credentials = {
32
- account: 'org_SAMPLE',
33
- api_key: 'key_SAMPLE',
31
+ api_key: 'ko_SAMPLE',
34
32
  url: 'https://api-e1.authrocket.com/v1',
35
33
  realm: 'rl_SAMPLE',
36
34
  jwt_secret: 'jsk_SAMPLE'
@@ -63,7 +61,6 @@ Let's add a couple methods to your Application Controller, substituting the corr
63
61
 
64
62
  def require_user
65
63
  unless current_user
66
- flash.keep
67
64
  redirect_to LOGIN_URL
68
65
  end
69
66
  end
@@ -84,9 +81,8 @@ Then add login and logout methods:
84
81
  skip_before_filter :require_user
85
82
 
86
83
  def login
87
- flash.keep
88
84
  if params[:token]
89
- if AuthRocket::Session.from_token(params[:token], within: 60.seconds)
85
+ if AuthRocket::Session.from_token(params[:token])
90
86
  session[:ar_token] = params[:token]
91
87
  redirect_to root_path
92
88
  return
data/authrocket.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'authrocket/api/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "authrocket"
8
8
  gem.version = AuthRocket::VERSION
9
- gem.authors = ["thomas morgan"]
9
+ gem.authors = ["AuthRocket Team"]
10
10
  gem.email = ["hello@authrocket.com"]
11
11
  gem.description = %q{AuthRocket client for Ruby.}
12
12
  gem.summary = %q{AuthRocket client for Ruby}
@@ -18,7 +18,9 @@ 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.2'
21
+ gem.required_ruby_version = '>= 1.9'
22
+
23
+ gem.add_dependency 'ncore', '~> 2.0'
22
24
  gem.add_dependency 'jwt', '~> 1.5.0'
23
25
 
24
26
  gem.add_development_dependency "bundler", "~> 1.3"
@@ -1,7 +1,7 @@
1
1
  module AuthRocket
2
2
  include NCore::Builder
3
- Resource.include AuthRocket::Client
4
- SingletonResource.include AuthRocket::Client
3
+ Resource.send :include, AuthRocket::Client
4
+ SingletonResource.send :include, AuthRocket::Client
5
5
 
6
6
  configure do
7
7
  self.default_url = ENV['AUTHROCKET_URL']
@@ -34,7 +34,7 @@ module AuthRocket
34
34
 
35
35
  self.auth_header_prefix = 'X-Authrocket'
36
36
 
37
- self.credentials_error_message = %Q{Missing API credentials or URL. Set default credentials using "AuthRocket::Api.credentials = {api_key: YOUR_API_KEY, account: YOUR_ACCOUNT_ID, url: AR_REGION_URL}"}
37
+ self.credentials_error_message = %Q{Missing API credentials or URL. Set default credentials using "AuthRocket::Api.credentials = {api_key: YOUR_API_KEY, url: AR_REGION_URL}"}
38
38
  end
39
39
 
40
40
 
@@ -57,7 +57,7 @@ module AuthRocket
57
57
  case part
58
58
  when /^jsk_/
59
59
  o[:jwt_secret] = part
60
- when /^key_/
60
+ when /^k(ey|o)_/
61
61
  o[:api_key] = part
62
62
  when /^org_/
63
63
  o[:account] = part
@@ -1,3 +1,3 @@
1
1
  module AuthRocket
2
- VERSION = '1.5.0'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -6,7 +6,8 @@ module AuthRocket
6
6
  has_many :events
7
7
 
8
8
  attr :event_type, :hook_type, :destination
9
- attr :email_from, :email_renderer, :email_subject, :email_template, :email_to, :user_type
9
+ attr :email_from, :email_from_name, :email_renderer, :email_subject
10
+ attr :email_template, :email_to, :user_type
10
11
 
11
12
  def self.event_types
12
13
  %w( app_hook.created app_hook.updated app_hook.deleted
@@ -16,6 +17,7 @@ module AuthRocket
16
17
  org.created org.updated org.deleted
17
18
  realm.created realm.updated realm.deleted
18
19
  user.created user.updated user.deleted
20
+ user.email.verification_requested user.email.verified
19
21
  user.login.succeeded user.login.failed
20
22
  user.password_token.created user.password_token.consumed user.password_token.failed
21
23
  ).sort
@@ -4,16 +4,17 @@ module AuthRocket
4
4
 
5
5
  belongs_to :realm
6
6
 
7
- attr :provider_type, :state
8
- attr :login, :name_field, :signup
7
+ attr :name, :provider_type, :state
8
+ attr :email_verification, :login, :name_field, :password_field, :signup, :signup_mode, :verify
9
9
  attr :min_complexity, :min_length, :required_chars
10
10
  attr :client_id, :client_secret, :scopes
11
11
 
12
12
 
13
13
  # attribs - :redirect_uri - required
14
14
  # - :nonce - optional
15
- def self.authorize_urls(attribs={}, api_creds=nil)
16
- parsed, creds = request(:get, url+'/authorize', api_creds, attribs)
15
+ def self.authorize_urls(attribs={})
16
+ params = parse_request_params(attribs)
17
+ parsed, creds = request(:get, url+'/authorize', params)
17
18
  if parsed[:errors].any?
18
19
  raise Error, parsed[:errors].inspect
19
20
  end
@@ -27,8 +28,9 @@ module AuthRocket
27
28
 
28
29
  # attribs - :redirect_uri - required
29
30
  # - :nonce - optional
30
- def self.authorize_url(auth_provider_id, attribs={}, api_creds=nil)
31
- parsed, creds = request(:get, url+"/#{auth_provider_id}/authorize", api_creds, attribs)
31
+ def self.authorize_url(auth_provider_id, attribs={})
32
+ params = parse_request_params(attribs)
33
+ parsed, creds = request(:get, url+"/#{auth_provider_id}/authorize", params)
32
34
  if parsed[:errors].any?
33
35
  raise Error, parsed[:errors].inspect
34
36
  end
@@ -37,17 +39,27 @@ module AuthRocket
37
39
 
38
40
  # same as self.authorize_url(self.id, ...)
39
41
  def authorize_url(attribs={})
40
- self.class.authorize_url(id, attribs, api_creds)
42
+ params = parse_request_params(attribs).merge credentials: api_creds
43
+ self.class.authorize_url(id, params)
41
44
  end
42
45
 
43
46
  # attribs - :code - required
44
47
  # - :nonce - optional
45
48
  # - :state - required
46
49
  # always returns a new object; check .errors? or .valid? to see how it went
47
- def self.authorize(attribs={}, api_creds=nil)
48
- parsed, creds = request(:post, url+'/authorize', api_creds, attribs)
50
+ def self.authorize(attribs={})
51
+ params = parse_request_params(attribs)
52
+ parsed, creds = request(:post, url+'/authorize', params)
49
53
  User.new(parsed, creds)
50
54
  end
51
55
 
56
+ # attribs - :access_token - required
57
+ # always returns a new object; check .errors? or .valid? to see how it went
58
+ def authorize_token(attribs={})
59
+ params = parse_request_params(attribs)
60
+ parsed, creds = request(:post, url+'/authorize', params)
61
+ User.new parsed, creds
62
+ end
63
+
52
64
  end
53
65
  end
@@ -11,18 +11,14 @@ module AuthRocket
11
11
  belongs_to :user
12
12
  has_many :notifications
13
13
 
14
- attr :event_type, :ip
14
+ attr :event_type
15
15
  attr_datetime :event_at
16
16
 
17
-
18
- # deprecated - use Session.from_token() or Session.find()
19
- def self.validate_token(token, params={}, api_creds=nil)
20
- parsed, creds = request(:get, "#{url}/login/#{CGI.escape token}", api_creds, params)
21
- new(parsed, creds)
22
- rescue RecordNotFound
23
- nil
17
+ def request_data
18
+ self[:request]
24
19
  end
25
20
 
21
+
26
22
  def notifications
27
23
  reload unless @attribs[:notifications]
28
24
  unless @stuffed_event
@@ -7,8 +7,7 @@ module AuthRocket
7
7
 
8
8
  attr :custom_domains, :external_css
9
9
  attr :footer, :header, :login_handler, :name, :primary_domain
10
- attr :signup_handler, :subdomain
11
- attr :enable_logins, :enable_signups, :name_field # deprecated
10
+ attr :redirect_uris, :signup_handler, :subdomain
12
11
  attr :base_domain, :domains # readonly
13
12
 
14
13
  end
@@ -16,7 +16,8 @@ module AuthRocket
16
16
 
17
17
 
18
18
  def reset!(params={})
19
- parsed, _ = request(:post, "#{url}/reset", api_creds, params)
19
+ params = parse_request_params(params).merge credentials: api_creds
20
+ parsed, _ = request(:post, "#{url}/reset", params)
20
21
  load(parsed)
21
22
  errors.empty? ? self : false
22
23
  end
@@ -4,13 +4,17 @@ module AuthRocket
4
4
 
5
5
  belongs_to :user
6
6
 
7
- attr :client, :ip
8
7
  attr :token # readonly
9
8
  attr_datetime :created_at, :expires_at # readonly
10
9
 
10
+ def request_data
11
+ self[:request]
12
+ end
13
+
14
+
11
15
  # 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]
16
+ def self.from_token(token, options={})
17
+ secret = (options[:credentials]||credentials)[:jwt_secret]
14
18
  raise Error, "missing :jwt_secret (or AUTHROCKET_JWT_SECRET)" unless secret
15
19
  return unless token
16
20
 
@@ -22,6 +26,7 @@ module AuthRocket
22
26
 
23
27
  user = User.new({
24
28
  id: jwt['uid'],
29
+ realm_id: jwt['aud'],
25
30
  username: jwt['un'],
26
31
  first_name: jwt['fn'],
27
32
  last_name: jwt['ln'],
@@ -33,11 +38,12 @@ module AuthRocket
33
38
  org_id: m['oid'],
34
39
  org: m['oid'] && Org.new({
35
40
  id: m['oid'],
41
+ realm_id: jwt['aud'],
36
42
  name: m['o'],
37
43
  }),
38
44
  })
39
45
  end,
40
- }, api_creds)
46
+ }, options[:credentials])
41
47
  session = new({
42
48
  id: jwt['tk'],
43
49
  created_at: jwt['iat'],
@@ -45,7 +51,7 @@ module AuthRocket
45
51
  token: token,
46
52
  user_id: jwt['uid'],
47
53
  user: user
48
- }, api_creds)
54
+ }, options[:credentials])
49
55
 
50
56
  session
51
57
  rescue JWT::DecodeError
@@ -8,12 +8,10 @@ module AuthRocket
8
8
  has_many :memberships
9
9
  has_many :sessions
10
10
 
11
- attr :api_key # deprecated
12
- attr :custom, :email, :first_name
11
+ attr :custom, :email, :email_verification, :first_name
13
12
  attr :last_name, :name, :password, :password_confirmation
14
13
  attr :reference, :state, :user_type, :username
15
14
  attr_datetime :created_at, :last_login_at
16
- attr_datetime :last_login_on # deprecated
17
15
 
18
16
 
19
17
  def credentials
@@ -35,35 +33,38 @@ module AuthRocket
35
33
 
36
34
  class << self
37
35
 
38
- def authenticate(username, password, params={}, api_creds=nil)
39
- params = params.merge(password: password)
40
- parsed, creds = request(:post, "#{url}/#{CGI.escape username}/authenticate", api_creds, params)
36
+ def authenticate(username, password, params={})
37
+ params = parse_request_params(params).merge password: password
38
+ parsed, creds = request(:post, "#{url}/#{CGI.escape username}/authenticate", params)
41
39
  if parsed[:errors].any?
42
40
  raise ValidationError, parsed[:errors]
43
41
  end
44
42
  new(parsed, creds)
45
43
  end
46
44
 
47
- def authenticate_key(api_key, params={}, api_creds=nil)
48
- params = params.merge(api_key: api_key)
49
- parsed, creds = request(:post, "#{url}/authenticate_key", api_creds, params)
45
+ def authenticate_key(api_key, params={})
46
+ params = parse_request_params(params).merge api_key: api_key
47
+ parsed, creds = request(:post, "#{url}/authenticate_key", params)
50
48
  if parsed[:errors].any?
51
49
  raise ValidationError, parsed[:errors]
52
50
  end
53
51
  new(parsed, creds)
54
52
  end
55
53
 
56
- def generate_password_token(username, params={}, api_creds=nil)
57
- parsed, creds = request(:post, "#{url}/#{CGI.escape username}/generate_password_token", api_creds, params)
54
+ def generate_password_token(username, params={})
55
+ params = parse_request_params(params)
56
+ parsed, creds = request(:post, "#{url}/#{CGI.escape username}/generate_password_token", params)
58
57
  if parsed[:errors].any?
59
58
  raise ValidationError, parsed[:errors]
60
59
  end
61
60
  new(parsed, creds)
62
61
  end
63
62
 
64
- def reset_password_with_token(username, token, new_pw, new_pw_2, params={}, api_creds=nil)
65
- params = params.with_indifferent_access.merge(user: {token: token, password: new_pw, password_confirmation: new_pw_2})
66
- parsed, creds = request(:post, "#{url}/#{CGI.escape username}/reset_password_with_token", api_creds, params)
63
+ # params - {username: '...', token: '...', password: '...', password_confirmation: '...'}
64
+ def reset_password_with_token(params)
65
+ params = parse_request_params(params, json_root: json_root)
66
+ username = params[json_root].delete(:username) || '--'
67
+ parsed, creds = request(:post, "#{url}/#{CGI.escape username}/reset_password_with_token", params)
67
68
  if parsed[:errors].any?
68
69
  raise ValidationError, parsed[:errors]
69
70
  end
@@ -74,8 +75,23 @@ module AuthRocket
74
75
 
75
76
  # params - {current_password: 'old', password: 'new', password_confirmation: 'new'}
76
77
  def update_password(params)
77
- params = {user: params}
78
- parsed, _ = request(:put, "#{url}/update_password", api_creds, params)
78
+ params = parse_request_params(params, json_root: json_root).merge credentials: api_creds
79
+ parsed, _ = request(:put, "#{url}/update_password", params)
80
+ load(parsed)
81
+ errors.empty? ? self : false
82
+ end
83
+
84
+ def request_email_verification(params={})
85
+ params = parse_request_params(params).merge credentials: api_creds
86
+ parsed, _ = request(:post, "#{url}/request_email_verification", params)
87
+ load(parsed)
88
+ errors.empty? ? self : false
89
+ end
90
+
91
+ # params - {token: '...'}
92
+ def verify_email(params)
93
+ params = parse_request_params(params, json_root: json_root).merge credentials: api_creds
94
+ parsed, _ = request(:post, "#{url}/verify_email", params)
79
95
  load(parsed)
80
96
  errors.empty? ? self : false
81
97
  end
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.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - thomas morgan
7
+ - AuthRocket Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-22 00:00:00.000000000 Z
11
+ date: 2016-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ncore
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '2.0'
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.2'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jwt
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: '0'
113
+ version: '1.9'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.4.3
121
+ rubygems_version: 2.4.8
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: AuthRocket client for Ruby