stormpath-rails 1.1.2.beta → 2.0.0
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 +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/.rubocop.yml +22 -0
- data/.travis.yml +6 -3
- data/Gemfile +10 -3
- data/README.md +139 -142
- data/Rakefile +9 -9
- data/app/assets/stylesheets/stormpath.css.scss +3 -2
- data/app/controllers/stormpath/rails/base_controller.rb +25 -6
- data/app/controllers/stormpath/rails/change_password/create_controller.rb +68 -0
- data/app/controllers/stormpath/rails/change_password/new_controller.rb +38 -0
- data/app/controllers/stormpath/rails/forgot_password/create_controller.rb +37 -0
- data/app/controllers/stormpath/rails/forgot_password/new_controller.rb +14 -0
- data/app/controllers/stormpath/rails/login/create_controller.rb +60 -0
- data/app/controllers/stormpath/rails/login/new_controller.rb +20 -0
- data/app/controllers/stormpath/rails/logout/create_controller.rb +61 -0
- data/app/controllers/stormpath/rails/oauth2/create_controller.rb +82 -0
- data/app/controllers/stormpath/rails/oauth2/new_controller.rb +11 -0
- data/app/controllers/stormpath/rails/profile/show_controller.rb +15 -0
- data/app/controllers/stormpath/rails/register/create_controller.rb +86 -0
- data/app/controllers/stormpath/rails/register/new_controller.rb +20 -0
- data/app/controllers/stormpath/rails/verify_email/create_controller.rb +37 -0
- data/app/controllers/stormpath/rails/verify_email/show_controller.rb +51 -0
- data/app/forms/stormpath/rails/login_form.rb +60 -0
- data/app/forms/stormpath/rails/registration_form.rb +106 -0
- data/app/forms/stormpath/rails/registration_form_fields.rb +71 -0
- data/app/helpers/social_helper.rb +2 -1
- data/app/serializers/stormpath/rails/account_serializer.rb +32 -0
- data/app/serializers/stormpath/rails/form_serializer.rb +37 -0
- data/app/serializers/stormpath/rails/login_new_serializer.rb +11 -0
- data/app/serializers/stormpath/rails/profile_serializer.rb +71 -0
- data/app/serializers/stormpath/rails/registration_form_serializer.rb +11 -0
- data/app/services/stormpath/rails/account_from_access_token/local_account_resolution.rb +48 -0
- data/app/services/stormpath/rails/account_from_access_token/stormpath_account_resolution.rb +27 -0
- data/app/services/stormpath/rails/account_from_access_token.rb +33 -0
- data/app/services/stormpath/rails/account_login.rb +28 -0
- data/app/services/stormpath/rails/account_login_with_stormpath_token.rb +32 -0
- data/app/services/stormpath/rails/client_credentials_authentication.rb +40 -0
- data/app/services/stormpath/rails/controller_authentication/from_basic_auth.rb +45 -0
- data/app/services/stormpath/rails/controller_authentication/from_bearer_auth.rb +34 -0
- data/app/services/stormpath/rails/controller_authentication/from_cookies.rb +71 -0
- data/app/services/stormpath/rails/controller_authentication.rb +44 -0
- data/app/services/stormpath/rails/delete_access_token.rb +48 -0
- data/app/services/stormpath/rails/delete_refresh_token.rb +11 -0
- data/app/services/stormpath/rails/forgot_password_token_verification.rb +31 -0
- data/app/services/stormpath/rails/password_change.rb +17 -0
- data/app/services/stormpath/rails/refresh_token_authentication.rb +28 -0
- data/app/services/stormpath/rails/resend_email_verification.rb +33 -0
- data/app/services/stormpath/rails/send_password_reset_email.rb +33 -0
- data/app/services/stormpath/rails/token_cookie_setter.rb +84 -0
- data/app/services/stormpath/rails/verify_email_token.rb +27 -0
- data/app/views/{passwords/forgot_change.html.erb → stormpath/rails/change_password/new.html.erb} +4 -10
- data/app/views/{passwords/forgot.html.erb → stormpath/rails/forgot_password/new.html.erb} +14 -4
- data/app/views/{layouts → stormpath/rails/layouts}/stormpath.html.erb +3 -3
- data/app/views/stormpath/rails/login/_form.html.erb +45 -0
- data/app/views/stormpath/rails/login/new.html.erb +12 -0
- data/app/views/stormpath/rails/register/_form.html.erb +19 -0
- data/app/views/{users → stormpath/rails/register}/new.html.erb +3 -3
- data/app/views/stormpath/rails/shared/_input.html.erb +15 -0
- data/app/views/stormpath/rails/verify_email/new.html.erb +49 -0
- data/bin/console +3 -3
- data/bin/rails +1 -1
- data/bin/rake +2 -2
- data/bin/rspec +2 -2
- data/config/initializers/assets.rb +3 -1
- data/lib/generators/stormpath/install/install_generator.rb +1 -92
- data/lib/generators/stormpath/install/templates/default_config.yml +229 -0
- data/lib/generators/stormpath/views/USAGE +0 -0
- data/lib/generators/stormpath/views/views_generator.rb +2 -2
- data/lib/stormpath/rails/client.rb +8 -85
- data/lib/stormpath/rails/config/account_store_verification.rb +45 -0
- data/lib/stormpath/rails/config/application_resolution.rb +76 -0
- data/lib/stormpath/rails/config/dynamic_configuration.rb +50 -0
- data/lib/stormpath/rails/config/read_file.rb +35 -0
- data/lib/stormpath/rails/configuration.rb +30 -35
- data/lib/stormpath/rails/content_type_negotiator.rb +50 -0
- data/lib/stormpath/rails/controller.rb +36 -5
- data/lib/stormpath/rails/errors/invalid_sptoken_error.rb +9 -0
- data/lib/stormpath/rails/errors/no_sptoken_error.rb +13 -0
- data/lib/stormpath/rails/router.rb +75 -0
- data/lib/stormpath/rails/routing_constraint.rb +9 -0
- data/lib/stormpath/rails/social.rb +6 -6
- data/lib/stormpath/rails/version.rb +2 -1
- data/lib/stormpath/rails.rb +9 -19
- data/lib/stormpath-rails.rb +1 -0
- data/stormpath-rails.gemspec +13 -11
- metadata +96 -54
- data/app/controllers/stormpath/rails/omniauth_controller.rb +0 -11
- data/app/controllers/stormpath/rails/passwords_controller.rb +0 -56
- data/app/controllers/stormpath/rails/sessions_controller.rb +0 -52
- data/app/controllers/stormpath/rails/users_controller.rb +0 -65
- data/app/views/passwords/edit.html.erb +0 -0
- data/app/views/passwords/email_sent.html.erb +0 -15
- data/app/views/passwords/forgot_change_failed.html.erb +0 -14
- data/app/views/passwords/forgot_complete.html.erb +0 -19
- data/app/views/sessions/_facebook_login_form.erb +0 -31
- data/app/views/sessions/_form.html.erb +0 -31
- data/app/views/sessions/_google_login_form.html.erb +0 -3
- data/app/views/sessions/_social_auth.html.erb +0 -7
- data/app/views/sessions/new.html.erb +0 -21
- data/app/views/users/_form.html.erb +0 -43
- data/app/views/users/verification_complete.html.erb +0 -20
- data/app/views/users/verification_email_sent.html.erb +0 -15
- data/app/views/users/verification_failed.html.erb +0 -14
- data/app/views/users/verification_resend.html.erb +0 -14
- data/config/routes.rb +0 -16
- data/lib/generators/stormpath/install/templates/db/migrate/add_stormpath_to_users.rb +0 -21
- data/lib/generators/stormpath/install/templates/db/migrate/create_users.rb +0 -12
- data/lib/generators/stormpath/install/templates/stormpath.rb +0 -4
- data/lib/generators/stormpath/install/templates/user.rb +0 -3
- data/lib/generators/stormpath/routes/routes_generator.rb +0 -23
- data/lib/generators/stormpath/routes/templates/routes.rb +0 -5
- data/lib/stormpath/rails/account.rb +0 -6
- data/lib/stormpath/rails/account_status.rb +0 -28
- data/lib/stormpath/rails/authentication.rb +0 -72
- data/lib/stormpath/rails/authentication_status.rb +0 -22
- data/lib/stormpath/rails/session.rb +0 -37
- data/lib/stormpath/rails/user.rb +0 -25
- data/lib/stormpath/rails/user_config/api_key.rb +0 -17
- data/lib/stormpath/rails/user_config/application.rb +0 -12
- data/lib/stormpath/rails/user_config/facebook.rb +0 -16
- data/lib/stormpath/rails/user_config/forgot_password.rb +0 -12
- data/lib/stormpath/rails/user_config/google.rb +0 -16
- data/lib/stormpath/rails/user_config/id_site.rb +0 -13
- data/lib/stormpath/rails/user_config/login.rb +0 -13
- data/lib/stormpath/rails/user_config/logout.rb +0 -13
- data/lib/stormpath/rails/user_config/register.rb +0 -13
- data/lib/stormpath/rails/user_config/verify_email.rb +0 -14
- data/lib/stormpath/testing/helpers.rb +0 -49
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b35ab183b8e11a56b6da21a4f95b952b920b3c6c
|
|
4
|
+
data.tar.gz: e3cc0dab2d8e11e3af290f50f6d4e744aa1545c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 81e2a501c5951115e2849a7da8b8c01d9b6a12a67ce9f13acd43c0b902c719bf76a6e3ba8000a1536bed07115a651e8ffd18aaf232b6a3043af9f8a4f7b88d38
|
|
7
|
+
data.tar.gz: 980da0ea891b40c8f47b778e29a74ad48b425708381783ed6ccf7b2a935a637bdfde32095a60ba915cb4487d6da245bb17585c133c236422f882078ffd3545d6
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
--color
|
|
1
|
+
--color --format Fivemat
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
LineLength:
|
|
2
|
+
Max: 100
|
|
3
|
+
|
|
4
|
+
Documentation:
|
|
5
|
+
Enabled: False
|
|
6
|
+
|
|
7
|
+
WordArray:
|
|
8
|
+
Enabled: False
|
|
9
|
+
|
|
10
|
+
Style/RedundantBegin:
|
|
11
|
+
Enabled: False
|
|
12
|
+
|
|
13
|
+
AllCops:
|
|
14
|
+
Exclude:
|
|
15
|
+
- 'spec/dummy/db/schema.rb'
|
|
16
|
+
- 'spec/dummy/db/migrate/*'
|
|
17
|
+
|
|
18
|
+
Rails:
|
|
19
|
+
Enabled: true
|
|
20
|
+
|
|
21
|
+
Metrics/AbcSize:
|
|
22
|
+
Max: 20
|
data/.travis.yml
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
rvm:
|
|
3
3
|
- 2.1.5
|
|
4
|
+
before_install:
|
|
5
|
+
- gem install bundler
|
|
4
6
|
env:
|
|
5
7
|
global:
|
|
6
|
-
- STORMPATH_APPLICATION_URL=https://api.stormpath.com/v1/applications/
|
|
7
|
-
- secure:
|
|
8
|
-
- secure:
|
|
8
|
+
- STORMPATH_APPLICATION_URL=https://api.stormpath.com/v1/applications/3nZlLKVMIOPu71YC7TFR0o
|
|
9
|
+
- secure: WJgw02cTjVKwGJMq+n3L8e7uVTK3mnEqxArw2w/X1h4s09XIQM0B2b8PuM/2o01rkQWUfhd6lTLDEsQE916lSS8REJbnbsZ1VyH83yeHL4VgJNaJDHvEAq+iFzHnvtLwWkyWm8fEb7DCnEXXA7M3sGt1girhfs0xfITpXputCHE=
|
|
10
|
+
- secure: JpErPQAz1b/l3rpwt/N9J7SZiy4/UB1DOI+9Kq4OrC9kuq2vUw3VIAKIojqvwy+7OaKAxyWcsx1kQ3BCLOPV/OkORq1/bMpP4SL0/0KYX+WjBWZ+En+gx3aCY3kOLkkVpDS6gD2pulOeHubGNwhDrFLjKFtbuUBfZuEuAGVNnP8=
|
|
11
|
+
- secure: hgaOzbsR8H6i5gYXLpqUTsPsio39aCjaPbMwk5ylbI7HRD91qfQbJwuzsAa7+ocLi6NQ7LBL1xa317mLBO2uqWIhN85sTRIut2bO6S+8cgS7GWikMKnwkgU8gpUdNjGYh0Y8nrgwPDo5PZTv0jyUZNCeEqoa1HhDF3DjTMFrXHA=
|
data/Gemfile
CHANGED
|
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
gem 'sqlite3', '~> 1.3'
|
|
7
|
+
gem 'sass-rails'
|
|
7
8
|
|
|
8
9
|
group :development do
|
|
9
10
|
gem 'pry'
|
|
@@ -15,7 +16,13 @@ group :test do
|
|
|
15
16
|
gem 'factory_girl_rails', '~> 4.5.0'
|
|
16
17
|
gem 'shoulda'
|
|
17
18
|
gem 'webmock'
|
|
18
|
-
gem 'vcr'
|
|
19
|
-
gem 'ammeter', git:
|
|
20
|
-
gem 'simplecov', :
|
|
19
|
+
gem 'vcr', '3.0.1'
|
|
20
|
+
gem 'ammeter', git: 'https://github.com/alexrothenberg/ammeter'
|
|
21
|
+
gem 'simplecov', require: false
|
|
22
|
+
gem 'coveralls', require: false
|
|
23
|
+
gem 'json_matchers'
|
|
24
|
+
gem 'match_json', '0.0.5'
|
|
25
|
+
gem 'capybara'
|
|
26
|
+
gem 'fivemat'
|
|
27
|
+
gem 'timecop'
|
|
21
28
|
end
|
data/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
[](https://travis-ci.org/stormpath/stormpath-rails)
|
|
2
|
+
[](https://coveralls.io/github/stormpath/stormpath-rails?branch=master)
|
|
3
|
+
[](https://codeclimate.com/github/stormpath/stormpath-rails)
|
|
2
4
|
|
|
3
|
-
# Stormpath
|
|
5
|
+
# Stormpath Rails
|
|
4
6
|
|
|
5
7
|
Stormpath is the first easy, secure user management and authentication service for developers. This is the Rails gem to ease integration of its features with any Rails-based application.
|
|
6
8
|
|
|
@@ -8,10 +10,14 @@ Stormpath makes it incredibly simple to add users and user data to your applicat
|
|
|
8
10
|
|
|
9
11
|
## Installation
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
Stormpath Rails officially supports Ruby versions over 2.1.0 and Rails over 4.0.
|
|
14
|
+
|
|
15
|
+
Add the stormpath-rails integration gem to your Gemfile.
|
|
16
|
+
|
|
17
|
+
Stormpath is currently in beta so it is necessary to include the gem version:
|
|
12
18
|
|
|
13
19
|
```ruby
|
|
14
|
-
gem 'stormpath-rails', '~>
|
|
20
|
+
gem 'stormpath-rails', '~> 2.0.0.beta1'
|
|
15
21
|
```
|
|
16
22
|
|
|
17
23
|
Bundle the Gemfile
|
|
@@ -20,212 +26,203 @@ Bundle the Gemfile
|
|
|
20
26
|
bundle install
|
|
21
27
|
```
|
|
22
28
|
|
|
23
|
-
Run the
|
|
29
|
+
Run the generator to insert the config yaml file and the neccessary controller module.
|
|
24
30
|
|
|
25
31
|
```sh
|
|
26
32
|
rails generate stormpath:install
|
|
27
33
|
```
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
```ruby
|
|
31
|
-
rake db:migrate
|
|
32
|
-
```
|
|
35
|
+
## Setup
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
### Api Key Setup
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
'STORMPATH_APPLICATION_HREF' should contain the href to your application, can also be found on stormpahs site
|
|
39
|
+
Create a Stormpath account if you haven't already, and be sure to set up the following environment variables:
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
- STORMPATH_API_KEY_ID
|
|
42
|
+
- STORMPATH_API_KEY_SECRET
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
export STORMPATH_API_KEY_FILE_LOCATION=~/.stormpathKey
|
|
43
|
-
export STORMPATH_APPLICATION_URL=https://api.stormpath.com/v1/applications/12345abc
|
|
44
|
-
```
|
|
44
|
+
Environment variables should be set up in you .bashrc file (or .zshrc if you use myzsh).
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Example setup:
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
```sh
|
|
49
|
+
export STORMPATH_API_KEY_ID=6U4HZMHGVHN0U765BGW
|
|
50
|
+
export STORMPATH_API_KEY_SECRET=0e0TuVZKYiPiLTDLNnswEwpPpa5nPv
|
|
51
|
+
```
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
Override any of these defaults in config/initializers/stormpath.rb
|
|
53
|
+
Alternatively you can use gems such as [Dotenv](https://github.com/bkeepers/dotenv) or [Figaro](https://github.com/laserlemon/figaro) to preload environment variables.
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
Stormpath::Rails.configure do |config|
|
|
55
|
-
config.api_key.file = ENV['STORMPATH_API_KEY_FILE_LOCATION']
|
|
56
|
-
config.application.href = ENV['STORMPATH_APPLICATION_HREF']
|
|
57
|
-
end
|
|
58
|
-
```
|
|
59
|
-
The `STORMPATH_API_KEY_FILE_LOCATION` is the location of your Stormpath API Key file. Information about getting this file is found in the [Ruby Quickstart](http://docs.stormpath.com/ruby/quickstart/). The `STORMPATH_APPLICATION_HREF` represents the Application in Stormpath that is your Rails application. You can get the href from the Stormpath Admin Console or the API.
|
|
55
|
+
### Application Setup
|
|
60
56
|
|
|
61
|
-
|
|
57
|
+
Create a Stormpath Application throught the Stormpath Admin Console.
|
|
62
58
|
|
|
63
|
-
|
|
59
|
+
Add the app href **OR** name to your configuration file in config/stormpath.yml:
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<% else %>
|
|
71
|
-
<%= link_to "Sign in", sign_in_path %>
|
|
72
|
-
<% end %>
|
|
61
|
+
```yaml
|
|
62
|
+
stormpath:
|
|
63
|
+
application:
|
|
64
|
+
href: https://api.stormpath.com/v1/applications/12345abc
|
|
65
|
+
name: null
|
|
73
66
|
```
|
|
74
67
|
|
|
75
|
-
|
|
68
|
+
- Make sure your application has a default account directory.
|
|
69
|
+
|
|
70
|
+
- Make sure that you have the `root_path` defined in your rails `routes.rb`
|
|
76
71
|
|
|
77
|
-
|
|
72
|
+
### Add Routes
|
|
78
73
|
|
|
79
|
-
|
|
74
|
+
Add `stormpath_rails_routes` to your routes.rb file.
|
|
80
75
|
|
|
81
76
|
```ruby
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
c.uri = '/login'
|
|
86
|
-
c.next_uri = '/'
|
|
87
|
-
end
|
|
77
|
+
Rails.application.routes.draw do
|
|
78
|
+
stormpath_rails_routes
|
|
79
|
+
...
|
|
88
80
|
end
|
|
89
81
|
```
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
Stormpath Rails automaticly provides route to `/logout`.
|
|
83
|
+
Check below on how to override default routes.
|
|
93
84
|
|
|
94
|
-
|
|
85
|
+
## Configuration
|
|
95
86
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
87
|
+
The gem is highly configurable through it's configuration file (config/stormpath.yml).
|
|
88
|
+
Currently the only configurations not working are for social logins and ID Site (because they are still not implemented in the gem).
|
|
89
|
+
|
|
90
|
+
You can use embedded ruby (ERB) in the configuration file:
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
stormpath:
|
|
94
|
+
application:
|
|
95
|
+
href: <%= ENV['STORMPATH_APPLICATION_URL'] %>
|
|
104
96
|
```
|
|
105
97
|
|
|
106
|
-
|
|
98
|
+
## Usage
|
|
107
99
|
|
|
108
|
-
|
|
100
|
+
### HTML & JSON
|
|
109
101
|
|
|
110
|
-
|
|
102
|
+
Stormpath Rails responds to two formats: HTML & JSON. You can use it both as an API for building SPA's, mobile applications and as a standalone Rails application that renders HTML.
|
|
111
103
|
|
|
112
|
-
|
|
113
|
-
Stormpath
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
104
|
+
By default the Stormpath integration will respond to JSON and HTML requests.
|
|
105
|
+
If a requested type isn't any of the two, the Stormpath integration will pass on the request, and allow the developer or Rails defaults to handle the response.
|
|
106
|
+
|
|
107
|
+
However if you want use only one of those, modify the configuration file:
|
|
108
|
+
|
|
109
|
+
```yaml
|
|
110
|
+
stormpath:
|
|
111
|
+
web:
|
|
112
|
+
produces:
|
|
113
|
+
- application/json
|
|
114
|
+
- text/html
|
|
120
115
|
```
|
|
116
|
+
If the request does not specify an Accept header, or the preferred content type is `*/*` the Stormpath integration will respond with the first type in the list.
|
|
121
117
|
|
|
122
|
-
|
|
118
|
+
### Controller private & helper methods.
|
|
123
119
|
|
|
124
|
-
The
|
|
120
|
+
The Application Controller gets the `Stormpath::Rails::Controller` module included by default.
|
|
121
|
+
The module provides 4 private controller methods:
|
|
125
122
|
|
|
126
|
-
|
|
123
|
+
- `current_account` - get the current account
|
|
124
|
+
- `signed_in?` - check if the user is signed in.
|
|
125
|
+
- `require_authentication!` - a before filter to stop unauthenticated access.
|
|
126
|
+
- `require_no_authentication!` - a before filter to stop authenticated access (a logged in user shouldn't be able to see the login form).
|
|
127
127
|
|
|
128
|
-
By default
|
|
128
|
+
By default, the `current_account` and `signed_in?` are marked as helper_methods and you can use them in your views.
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
Stormpath::Rails.configure do |config|
|
|
132
|
-
config.verify_email do |c|
|
|
133
|
-
c.enabled = true
|
|
134
|
-
c.uri = '/forgot'
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
```
|
|
130
|
+
If you wish to add these methods to a controller that doesn't inherit from the ApplicationController, just include the `Stormpath::Rails::Controller` module in that controller as well.
|
|
138
131
|
|
|
139
|
-
|
|
132
|
+
## Overriding Stormpath
|
|
140
133
|
|
|
141
|
-
|
|
134
|
+
### Controllers
|
|
142
135
|
|
|
143
|
-
|
|
136
|
+
Since Stormpath controllers are highly configurable, they have lots of configuration code and are not written in a traditional way. A LoginController would usually have two actions - new & create, however in StormpathRails they are separated into two single action controllers - `Stormpath::Rails::Login::NewController` and `Stormpath::Rails::Login::CreateController`. They both respond to a `call` method (action).
|
|
144
137
|
|
|
145
|
-
|
|
138
|
+
To override a Stormpath controller, first you need to subclass it:
|
|
146
139
|
|
|
147
|
-
|
|
140
|
+
```ruby
|
|
141
|
+
class CreateAccountController < Stormpath::Rails::Register::CreateController
|
|
142
|
+
end
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
and update the routes to point to your new controller:
|
|
148
146
|
|
|
149
147
|
```ruby
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
c.next_uri = '/'
|
|
155
|
-
end
|
|
148
|
+
Rails.application.routes.draw do
|
|
149
|
+
stormpath_rails_routes(actions: {
|
|
150
|
+
'register#create' => 'create_account#call'
|
|
151
|
+
})
|
|
156
152
|
end
|
|
157
153
|
```
|
|
158
154
|
|
|
159
|
-
|
|
155
|
+
List of available controllers:
|
|
160
156
|
|
|
161
|
-
|
|
157
|
+
```ruby
|
|
158
|
+
Stormpath::Rails::Login::NewController
|
|
159
|
+
Stormpath::Rails::Login::CreateController
|
|
162
160
|
|
|
163
|
-
Stormpath
|
|
161
|
+
Stormpath::Rails::Logout::CreateController
|
|
164
162
|
|
|
165
|
-
|
|
163
|
+
Stormpath::Rails::Register::NewController
|
|
164
|
+
Stormpath::Rails::Register::CreateController
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
Stormpath::Rails
|
|
169
|
-
config.facebook do |c|
|
|
170
|
-
c.app_id = 'app_id'
|
|
171
|
-
c.app_secret = 'app_secret'
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
```
|
|
166
|
+
Stormpath::Rails::ChangePassword::NewController
|
|
167
|
+
Stormpath::Rails::ChangePassword::CreateController
|
|
175
168
|
|
|
176
|
-
|
|
169
|
+
Stormpath::Rails::ForgotPassword::NewController
|
|
170
|
+
Stormpath::Rails::ForgotPassword::CreateController
|
|
177
171
|
|
|
178
|
-
|
|
172
|
+
Stormpath::Rails::VerifyEmail::ShowController
|
|
173
|
+
Stormpath::Rails::VerifyEmail::CreateController
|
|
179
174
|
|
|
180
|
-
|
|
181
|
-
You can optionally run `rails generate stormpath:routes` to dump a copy of the default routes into your application for modification
|
|
175
|
+
Stormpath::Rails::Profile::ShowController
|
|
182
176
|
|
|
183
|
-
|
|
184
|
-
|
|
177
|
+
Stormpath::Rails::Oauth2::NewController
|
|
178
|
+
Stormpath::Rails::Oauth2::CreateController
|
|
185
179
|
```
|
|
186
180
|
|
|
187
|
-
###
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
class PasswordsController < Stormpath::PasswordsController
|
|
191
|
-
class SessionsController < Stormpath::SessionsController
|
|
192
|
-
class UsersController < Stormpath::UsersController
|
|
193
|
-
```
|
|
181
|
+
### Routes
|
|
182
|
+
|
|
183
|
+
To override routes (while using Stormpath default controllers), please use the configuration file (config/stormpath.yml) and override them there. As usual, to see what the routes are, run `rake routes`.
|
|
194
184
|
|
|
195
185
|
### Views
|
|
196
|
-
You can use the
|
|
186
|
+
You can use the Stormpath views generator to copy the default views to your application for modification:
|
|
197
187
|
```sh
|
|
198
188
|
rails generate stormpath:views
|
|
199
189
|
```
|
|
200
190
|
|
|
201
191
|
```
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
app/views/users/verification_complete.html.erb
|
|
218
|
-
app/views/users/verification_email_sent.html.erb
|
|
219
|
-
app/views/users/verification_failed.html.erb
|
|
220
|
-
app/views/users/verification_resend.html.erb
|
|
192
|
+
stormpath/rails/layouts/stormpath.html.erb
|
|
193
|
+
|
|
194
|
+
stormpath/rails/login/new.html.erb
|
|
195
|
+
stormpath/rails/login/_form.html.erb
|
|
196
|
+
|
|
197
|
+
stormpath/rails/register/new.html.erb
|
|
198
|
+
stormpath/rails/register/_form.html.erb
|
|
199
|
+
|
|
200
|
+
stormpath/rails/change_password/new.html.erb
|
|
201
|
+
|
|
202
|
+
stormpath/rails/forgot_password/new.html.erb
|
|
203
|
+
|
|
204
|
+
stormpath/rails/shared/_input.html.erb
|
|
205
|
+
|
|
206
|
+
stormpath/rails/verify_email/new.html.erb
|
|
221
207
|
```
|
|
222
208
|
|
|
223
|
-
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
### Prerequisites
|
|
212
|
+
|
|
213
|
+
If you wish to contribute to the gem, please follow these steps:
|
|
224
214
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
215
|
+
1. Create a Stormpath Application.
|
|
216
|
+
2. Export the following env variables:
|
|
217
|
+
- STORMPATH_API_KEY_ID
|
|
218
|
+
- STORMPATH_API_KEY_SECRET
|
|
219
|
+
3. Create a Directory and associate it to the app. Make it the default account and group store for the app.
|
|
220
|
+
4. Create a Directory With a Verification Workflow and associate it to the app.
|
|
221
|
+
5. Export the following env variable:
|
|
222
|
+
- STORMPATH_SDK_TEST_DIRECTORY_WITH_VERIFICATION_URL
|
|
228
223
|
|
|
229
|
-
###
|
|
224
|
+
### Specs
|
|
230
225
|
|
|
231
|
-
|
|
226
|
+
Clone the repo & install the dependencies with `bundle install`.
|
|
227
|
+
The suite is written with RSpec, so to run the specs you'll need to execute `rspec`
|
|
228
|
+
The suite uses the [VCR gem](https://github.com/vcr/vcr) to record all the HTTP requests. On first roll it records them and after that all of the tests use the recorded HTTP requests and run under 10 seconds.
|
data/Rakefile
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
4
|
|
|
5
|
-
require
|
|
6
|
-
require
|
|
5
|
+
require 'rake'
|
|
6
|
+
require 'rspec/core/rake_task'
|
|
7
7
|
|
|
8
8
|
namespace :dummy do
|
|
9
|
-
require_relative
|
|
9
|
+
require_relative 'spec/dummy/config/application'
|
|
10
10
|
Dummy::Application.load_tasks
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
APP_RAKEFILE = File.expand_path(
|
|
13
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
|
14
14
|
load 'rails/tasks/engine.rake'
|
|
15
15
|
|
|
16
16
|
Bundler::GemHelper.install_tasks
|
|
17
17
|
|
|
18
|
-
task :
|
|
18
|
+
task default: :spec
|
|
19
19
|
|
|
20
20
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
21
21
|
spec.pattern = 'spec/**/*_spec.rb'
|
|
22
|
-
end
|
|
22
|
+
end
|
|
@@ -124,7 +124,8 @@ p {
|
|
|
124
124
|
font-size: 21px;
|
|
125
125
|
}
|
|
126
126
|
.view input[type="text"],
|
|
127
|
-
.view input[type="password"]
|
|
127
|
+
.view input[type="password"],
|
|
128
|
+
.view input[type="email"] {
|
|
128
129
|
background-color: #f6f6f6;
|
|
129
130
|
height: 45px;
|
|
130
131
|
}
|
|
@@ -280,4 +281,4 @@ p {
|
|
|
280
281
|
}
|
|
281
282
|
.login, .register { display: table; }
|
|
282
283
|
.va-wrapper { display: table-cell; width: 100%; vertical-align: middle; }
|
|
283
|
-
.custom-container { display: table-row; height: 100%; }
|
|
284
|
+
.custom-container { display: table-row; height: 100%; }
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
module Stormpath
|
|
2
|
+
module Rails
|
|
3
|
+
class BaseController < ApplicationController
|
|
4
|
+
include Stormpath::Rails::Controller
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
before_action :setup_accept_header
|
|
7
|
+
skip_before_action :verify_authenticity_token, if: :api_request?
|
|
8
|
+
skip_before_action :verify_authenticity_token, if: :in_development?
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
layout 'stormpath/rails/layouts/stormpath'
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def api_request?
|
|
15
|
+
request.format == :json
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Enable to test with the TCK.
|
|
19
|
+
def in_development?
|
|
20
|
+
::Rails.env.development?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def setup_accept_header
|
|
24
|
+
request.format =
|
|
25
|
+
ContentTypeNegotiator.new(request.headers['HTTP_ACCEPT']).convert_to_symbol
|
|
26
|
+
end
|
|
27
|
+
end
|
|
9
28
|
end
|
|
10
|
-
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module Stormpath
|
|
2
|
+
module Rails
|
|
3
|
+
module ChangePassword
|
|
4
|
+
class CreateController < Stormpath::Rails::BaseController
|
|
5
|
+
def call
|
|
6
|
+
password_change.call
|
|
7
|
+
respond_with_success
|
|
8
|
+
rescue Stormpath::Error => error
|
|
9
|
+
respond_to_stormpath_error(error)
|
|
10
|
+
rescue InvalidSptokenError => error
|
|
11
|
+
respond_with_error(error, stormpath_config.web.change_password.error_uri)
|
|
12
|
+
rescue NoSptokenError => error
|
|
13
|
+
respond_with_error(error, stormpath_config.web.forgot_password.uri)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def password_change
|
|
19
|
+
@password_change ||= PasswordChange.new(params[:sptoken], params[:password])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def respond_with_success
|
|
23
|
+
if stormpath_config.web.change_password.auto_login
|
|
24
|
+
AccountLogin.call(cookies, password_change.account.email, params[:password])
|
|
25
|
+
respond_to_autologin
|
|
26
|
+
else
|
|
27
|
+
respond_without_login
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def respond_to_autologin
|
|
32
|
+
respond_to do |format|
|
|
33
|
+
format.html { redirect_to stormpath_config.web.login.next_uri }
|
|
34
|
+
format.json { render json: AccountSerializer.to_h(password_change.account) }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def respond_without_login
|
|
39
|
+
respond_to do |format|
|
|
40
|
+
format.html { redirect_to stormpath_config.web.change_password.next_uri }
|
|
41
|
+
format.json { render nothing: true, status: 200 }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def respond_to_stormpath_error(error)
|
|
46
|
+
respond_to do |format|
|
|
47
|
+
format.html do
|
|
48
|
+
flash.now[:error] = error.message
|
|
49
|
+
render stormpath_config.web.change_password.view
|
|
50
|
+
end
|
|
51
|
+
format.json do
|
|
52
|
+
render json: { status: error.status, message: error.message }, status: error.status
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def respond_with_error(error, redirect_path)
|
|
58
|
+
respond_to do |format|
|
|
59
|
+
format.html { redirect_to redirect_path }
|
|
60
|
+
format.json do
|
|
61
|
+
render json: { status: error.status, message: error.message }, status: error.status
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Stormpath
|
|
2
|
+
module Rails
|
|
3
|
+
module ChangePassword
|
|
4
|
+
class NewController < Stormpath::Rails::BaseController
|
|
5
|
+
def call
|
|
6
|
+
verify_sptoken
|
|
7
|
+
respond_with_success
|
|
8
|
+
rescue InvalidSptokenError => error
|
|
9
|
+
respond_with_error(error, stormpath_config.web.change_password.error_uri)
|
|
10
|
+
rescue NoSptokenError => error
|
|
11
|
+
respond_with_error(error, stormpath_config.web.forgot_password.uri)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def verify_sptoken
|
|
17
|
+
ForgotPasswordTokenVerification.new(params[:sptoken]).call
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def respond_with_success
|
|
21
|
+
respond_to do |format|
|
|
22
|
+
format.html { render stormpath_config.web.change_password.view }
|
|
23
|
+
format.json { render nothing: true, status: 200 }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def respond_with_error(error, redirect_path)
|
|
28
|
+
respond_to do |format|
|
|
29
|
+
format.html { redirect_to redirect_path }
|
|
30
|
+
format.json do
|
|
31
|
+
render json: { status: error.status, message: error.message }, status: error.status
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|