stormpath-rails 1.1.2.beta → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +22 -0
  5. data/.travis.yml +6 -3
  6. data/Gemfile +10 -3
  7. data/README.md +139 -142
  8. data/Rakefile +9 -9
  9. data/app/assets/stylesheets/stormpath.css.scss +3 -2
  10. data/app/controllers/stormpath/rails/base_controller.rb +25 -6
  11. data/app/controllers/stormpath/rails/change_password/create_controller.rb +68 -0
  12. data/app/controllers/stormpath/rails/change_password/new_controller.rb +38 -0
  13. data/app/controllers/stormpath/rails/forgot_password/create_controller.rb +37 -0
  14. data/app/controllers/stormpath/rails/forgot_password/new_controller.rb +14 -0
  15. data/app/controllers/stormpath/rails/login/create_controller.rb +60 -0
  16. data/app/controllers/stormpath/rails/login/new_controller.rb +20 -0
  17. data/app/controllers/stormpath/rails/logout/create_controller.rb +61 -0
  18. data/app/controllers/stormpath/rails/oauth2/create_controller.rb +82 -0
  19. data/app/controllers/stormpath/rails/oauth2/new_controller.rb +11 -0
  20. data/app/controllers/stormpath/rails/profile/show_controller.rb +15 -0
  21. data/app/controllers/stormpath/rails/register/create_controller.rb +86 -0
  22. data/app/controllers/stormpath/rails/register/new_controller.rb +20 -0
  23. data/app/controllers/stormpath/rails/verify_email/create_controller.rb +37 -0
  24. data/app/controllers/stormpath/rails/verify_email/show_controller.rb +51 -0
  25. data/app/forms/stormpath/rails/login_form.rb +60 -0
  26. data/app/forms/stormpath/rails/registration_form.rb +106 -0
  27. data/app/forms/stormpath/rails/registration_form_fields.rb +71 -0
  28. data/app/helpers/social_helper.rb +2 -1
  29. data/app/serializers/stormpath/rails/account_serializer.rb +32 -0
  30. data/app/serializers/stormpath/rails/form_serializer.rb +37 -0
  31. data/app/serializers/stormpath/rails/login_new_serializer.rb +11 -0
  32. data/app/serializers/stormpath/rails/profile_serializer.rb +71 -0
  33. data/app/serializers/stormpath/rails/registration_form_serializer.rb +11 -0
  34. data/app/services/stormpath/rails/account_from_access_token/local_account_resolution.rb +48 -0
  35. data/app/services/stormpath/rails/account_from_access_token/stormpath_account_resolution.rb +27 -0
  36. data/app/services/stormpath/rails/account_from_access_token.rb +33 -0
  37. data/app/services/stormpath/rails/account_login.rb +28 -0
  38. data/app/services/stormpath/rails/account_login_with_stormpath_token.rb +32 -0
  39. data/app/services/stormpath/rails/client_credentials_authentication.rb +40 -0
  40. data/app/services/stormpath/rails/controller_authentication/from_basic_auth.rb +45 -0
  41. data/app/services/stormpath/rails/controller_authentication/from_bearer_auth.rb +34 -0
  42. data/app/services/stormpath/rails/controller_authentication/from_cookies.rb +71 -0
  43. data/app/services/stormpath/rails/controller_authentication.rb +44 -0
  44. data/app/services/stormpath/rails/delete_access_token.rb +48 -0
  45. data/app/services/stormpath/rails/delete_refresh_token.rb +11 -0
  46. data/app/services/stormpath/rails/forgot_password_token_verification.rb +31 -0
  47. data/app/services/stormpath/rails/password_change.rb +17 -0
  48. data/app/services/stormpath/rails/refresh_token_authentication.rb +28 -0
  49. data/app/services/stormpath/rails/resend_email_verification.rb +33 -0
  50. data/app/services/stormpath/rails/send_password_reset_email.rb +33 -0
  51. data/app/services/stormpath/rails/token_cookie_setter.rb +84 -0
  52. data/app/services/stormpath/rails/verify_email_token.rb +27 -0
  53. data/app/views/{passwords/forgot_change.html.erb → stormpath/rails/change_password/new.html.erb} +4 -10
  54. data/app/views/{passwords/forgot.html.erb → stormpath/rails/forgot_password/new.html.erb} +14 -4
  55. data/app/views/{layouts → stormpath/rails/layouts}/stormpath.html.erb +3 -3
  56. data/app/views/stormpath/rails/login/_form.html.erb +45 -0
  57. data/app/views/stormpath/rails/login/new.html.erb +12 -0
  58. data/app/views/stormpath/rails/register/_form.html.erb +19 -0
  59. data/app/views/{users → stormpath/rails/register}/new.html.erb +3 -3
  60. data/app/views/stormpath/rails/shared/_input.html.erb +15 -0
  61. data/app/views/stormpath/rails/verify_email/new.html.erb +49 -0
  62. data/bin/console +3 -3
  63. data/bin/rails +1 -1
  64. data/bin/rake +2 -2
  65. data/bin/rspec +2 -2
  66. data/config/initializers/assets.rb +3 -1
  67. data/lib/generators/stormpath/install/install_generator.rb +1 -92
  68. data/lib/generators/stormpath/install/templates/default_config.yml +229 -0
  69. data/lib/generators/stormpath/views/USAGE +0 -0
  70. data/lib/generators/stormpath/views/views_generator.rb +2 -2
  71. data/lib/stormpath/rails/client.rb +8 -85
  72. data/lib/stormpath/rails/config/account_store_verification.rb +45 -0
  73. data/lib/stormpath/rails/config/application_resolution.rb +76 -0
  74. data/lib/stormpath/rails/config/dynamic_configuration.rb +50 -0
  75. data/lib/stormpath/rails/config/read_file.rb +35 -0
  76. data/lib/stormpath/rails/configuration.rb +30 -35
  77. data/lib/stormpath/rails/content_type_negotiator.rb +50 -0
  78. data/lib/stormpath/rails/controller.rb +36 -5
  79. data/lib/stormpath/rails/errors/invalid_sptoken_error.rb +9 -0
  80. data/lib/stormpath/rails/errors/no_sptoken_error.rb +13 -0
  81. data/lib/stormpath/rails/router.rb +75 -0
  82. data/lib/stormpath/rails/routing_constraint.rb +9 -0
  83. data/lib/stormpath/rails/social.rb +6 -6
  84. data/lib/stormpath/rails/version.rb +2 -1
  85. data/lib/stormpath/rails.rb +9 -19
  86. data/lib/stormpath-rails.rb +1 -0
  87. data/stormpath-rails.gemspec +13 -11
  88. metadata +96 -54
  89. data/app/controllers/stormpath/rails/omniauth_controller.rb +0 -11
  90. data/app/controllers/stormpath/rails/passwords_controller.rb +0 -56
  91. data/app/controllers/stormpath/rails/sessions_controller.rb +0 -52
  92. data/app/controllers/stormpath/rails/users_controller.rb +0 -65
  93. data/app/views/passwords/edit.html.erb +0 -0
  94. data/app/views/passwords/email_sent.html.erb +0 -15
  95. data/app/views/passwords/forgot_change_failed.html.erb +0 -14
  96. data/app/views/passwords/forgot_complete.html.erb +0 -19
  97. data/app/views/sessions/_facebook_login_form.erb +0 -31
  98. data/app/views/sessions/_form.html.erb +0 -31
  99. data/app/views/sessions/_google_login_form.html.erb +0 -3
  100. data/app/views/sessions/_social_auth.html.erb +0 -7
  101. data/app/views/sessions/new.html.erb +0 -21
  102. data/app/views/users/_form.html.erb +0 -43
  103. data/app/views/users/verification_complete.html.erb +0 -20
  104. data/app/views/users/verification_email_sent.html.erb +0 -15
  105. data/app/views/users/verification_failed.html.erb +0 -14
  106. data/app/views/users/verification_resend.html.erb +0 -14
  107. data/config/routes.rb +0 -16
  108. data/lib/generators/stormpath/install/templates/db/migrate/add_stormpath_to_users.rb +0 -21
  109. data/lib/generators/stormpath/install/templates/db/migrate/create_users.rb +0 -12
  110. data/lib/generators/stormpath/install/templates/stormpath.rb +0 -4
  111. data/lib/generators/stormpath/install/templates/user.rb +0 -3
  112. data/lib/generators/stormpath/routes/routes_generator.rb +0 -23
  113. data/lib/generators/stormpath/routes/templates/routes.rb +0 -5
  114. data/lib/stormpath/rails/account.rb +0 -6
  115. data/lib/stormpath/rails/account_status.rb +0 -28
  116. data/lib/stormpath/rails/authentication.rb +0 -72
  117. data/lib/stormpath/rails/authentication_status.rb +0 -22
  118. data/lib/stormpath/rails/session.rb +0 -37
  119. data/lib/stormpath/rails/user.rb +0 -25
  120. data/lib/stormpath/rails/user_config/api_key.rb +0 -17
  121. data/lib/stormpath/rails/user_config/application.rb +0 -12
  122. data/lib/stormpath/rails/user_config/facebook.rb +0 -16
  123. data/lib/stormpath/rails/user_config/forgot_password.rb +0 -12
  124. data/lib/stormpath/rails/user_config/google.rb +0 -16
  125. data/lib/stormpath/rails/user_config/id_site.rb +0 -13
  126. data/lib/stormpath/rails/user_config/login.rb +0 -13
  127. data/lib/stormpath/rails/user_config/logout.rb +0 -13
  128. data/lib/stormpath/rails/user_config/register.rb +0 -13
  129. data/lib/stormpath/rails/user_config/verify_email.rb +0 -14
  130. data/lib/stormpath/testing/helpers.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85d9877e6a52b149d258babb477ae11df469a485
4
- data.tar.gz: 7a4fa9ff40e5b1e5ed0f4ebc3d01e9759326c650
3
+ metadata.gz: b35ab183b8e11a56b6da21a4f95b952b920b3c6c
4
+ data.tar.gz: e3cc0dab2d8e11e3af290f50f6d4e744aa1545c1
5
5
  SHA512:
6
- metadata.gz: 622fea20e75a13f18b6b99fba6dbfdc751ac687d10462b8d5f55493b653fe19284c7c0ef50aef35b2b1362b3656f2a94ae5ae13a6dc2b4e9a503241e5a22301c
7
- data.tar.gz: 0a8431995cdb3e7ad18d3fbbbab06aa35aab2ccc1f4a1eb2b211a61ddb5fa780dd67b88fabab78fbf8b808ad38756a1a1497a99dc9b78457d7d09c1be7b2e57a
6
+ metadata.gz: 81e2a501c5951115e2849a7da8b8c01d9b6a12a67ce9f13acd43c0b902c719bf76a6e3ba8000a1536bed07115a651e8ffd18aaf232b6a3043af9f8a4f7b88d38
7
+ data.tar.gz: 980da0ea891b40c8f47b778e29a74ad48b425708381783ed6ccf7b2a935a637bdfde32095a60ba915cb4487d6da245bb17585c133c236422f882078ffd3545d6
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ spec/fixtures/vcr_cassettes
11
11
  spec/dummy/db/development.sqlite3
12
12
  spec/dummy/log/development.log
13
13
  spec/dummy/log/test.log
14
+ spec/dummy/tmp
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/2RbTfV9wx59glWwChd9NQC
7
- - secure: fYub1ieRk8lDfSmoZPP3yRdUSUAjYxt/gtyoMPm8iJUYCohzdD0nnVT308ycp0XPIRc87aGTOoH5B8SPnrXKG4RxxsZ6Wn8gW6PtHFoSnflEF7WqrkDkwIFk+RyQT4HVt0nDv5N/sSK10O5F3K5PzZog3GMDiCygzZ80uGhFNhU=
8
- - secure: bMlph5RFUaH5A4Y9kuZOJE16GRRHBMY07VEHSEBCBSbdG0I2cNoOqMpe7DRLrZaVTPDZjF6FJiVt9vtBK7UEz9AQg5Ydqhp9GS+IwwZOnpvDPYRSsDWtrrTvZSgQjDciVrl0juShBuqb2gLEgdcYUivX4f2G4VsSMCbO3rQRwZw=
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: "https://github.com/alexrothenberg/ammeter"
20
- gem 'simplecov', :require => false
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
  [![Build Status](https://travis-ci.org/stormpath/stormpath-rails.svg?branch=master)](https://travis-ci.org/stormpath/stormpath-rails)
2
+ [![Coverage Status](https://coveralls.io/repos/stormpath/stormpath-rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/stormpath/stormpath-rails?branch=master)
3
+ [![Code Climate](https://codeclimate.com/github/stormpath/stormpath-rails/badges/gpa.svg)](https://codeclimate.com/github/stormpath/stormpath-rails)
2
4
 
3
- # Stormpath-Rails-Gem
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
- Add the following line to your Gemfile. Stormpath is currently in beta so it is necessary to include the gem version
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', '~> 1.1.2.beta'
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 install script which will create a migration file and a config file.
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
- Migrate your database
30
- ```ruby
31
- rake db:migrate
32
- ```
35
+ ## Setup
33
36
 
34
- Create a stormpath account if you havent already, and be sure to set up environment variables
37
+ ### Api Key Setup
35
38
 
36
- 'STORMPATH_API_KEY_FILE_LOCATION' should be the location of your apiKey.properties file which you downloaded form stormpaths site
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
- environment variables are set up in you .bashrc file or .zshrc if you use myzsh. So for example this should look something like this
41
+ - STORMPATH_API_KEY_ID
42
+ - STORMPATH_API_KEY_SECRET
40
43
 
41
- ```sh
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
- environment variables can be named differently but the stormpath config file should be edited accordingly
46
+ Example setup:
47
47
 
48
- also make sure that you have a root_path defined in your rails router.rb
48
+ ```sh
49
+ export STORMPATH_API_KEY_ID=6U4HZMHGVHN0U765BGW
50
+ export STORMPATH_API_KEY_SECRET=0e0TuVZKYiPiLTDLNnswEwpPpa5nPv
51
+ ```
49
52
 
50
- ## Configuration
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
- ```ruby
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
- ## Useage
57
+ Create a Stormpath Application throught the Stormpath Admin Console.
62
58
 
63
- ### Helper Methods
59
+ Add the app href **OR** name to your configuration file in config/stormpath.yml:
64
60
 
65
- Use `current_user`, `signed_in?`, `signed_out?` in controllers, views, and helpers. For example:
66
- ```erb
67
- <% if signed_in? %>
68
- <%= current_user.email %>
69
- <%= button_to "Sign out", sign_out_path, method: :delete %>
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
- ### Login
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
- Stormpath Rails automaticly provides route to `/login`. If the attempt is successsfull, the user will be send to the next_uri whcih is by default `/` and create the propper session cookies.
72
+ ### Add Routes
78
73
 
79
- If you wish to change this you can modify login options in configuration file:
74
+ Add `stormpath_rails_routes` to your routes.rb file.
80
75
 
81
76
  ```ruby
82
- Stormpath::Rails.configure do |config|
83
- config.login do |c|
84
- c.login = true
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
- ### Logout
92
- Stormpath Rails automaticly provides route to `/logout`.
83
+ Check below on how to override default routes.
93
84
 
94
- If you wish to change the logout URI or the next_uri, you can provide the following configuration
85
+ ## Configuration
95
86
 
96
- ```ruby
97
- Stormpath::Rails.configure do |config|
98
- config.logout do |c|
99
- c.logout = true
100
- c.uri = '/logout'
101
- c.next_uri = '/'
102
- end
103
- end
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
- ### Verify Email
98
+ ## Usage
107
99
 
108
- By default verify email is disabled. Which means after user fills in the registration form and submits, if his credentials are valid, he will be automaticly logged in without email verification.
100
+ ### HTML & JSON
109
101
 
110
- If you want to enable email verification you can add the following code to the configuration file.
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
- ```ruby
113
- Stormpath::Rails.configure do |config|
114
- config.verify_email do |c|
115
- c.enabled = true
116
- c.uri = '/verify'
117
- c.next_uri = '/'
118
- end
119
- end
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
- If verify email set to enable after user registers he will first receive an email with the link and token with which he can verify his account. uri is the link which is used to verify the account and next_uri is location where user will be redirected after his account has been verified.
118
+ ### Controller private & helper methods.
123
119
 
124
- The email that is sent to the account is configurable through the Stormpath Admin Console.
120
+ The Application Controller gets the `Stormpath::Rails::Controller` module included by default.
121
+ The module provides 4 private controller methods:
125
122
 
126
- ### Forgot Password
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 forgot password is disabled. To enable it add the following code to the configuration file
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
- ```ruby
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
- After the forgot password option has been enabled on the login form there will appear a link for user to reset his password. User first needs to enter an email to which a link will be send. When user clicks on a link he will be redirected to the final form where he can reset his password.
132
+ ## Overriding Stormpath
140
133
 
141
- The email that is sent to the account is configurable through the Stormpath Admin Console.
134
+ ### Controllers
142
135
 
143
- ### ID Site
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
- If you'd like to not worry about building your own registration and login screens at all, you can use Stormpath's new [ID site](https://docs.stormpath.com/guides/using-id-site/) feature. This is a hosted login subdomain which handles authentication for you automatically.
138
+ To override a Stormpath controller, first you need to subclass it:
146
139
 
147
- To make ID Site work in Rails, you need to change stormpath configuration file:
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
- Stormpath::Rails.configure do |config|
151
- config.id_site do |c|
152
- c.enabled = true
153
- c.uri = "/redirect"
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
- When ID Site is enabled any request for `/login` or `/register` will cause a redirect to ID Site. When the user is finished at ID Site they will be redirected to uri which is defined in configuration, by default `/redirect`. Stormpath Rails will handle this request, and then redirect the user to `next_uri`
155
+ List of available controllers:
160
156
 
161
- ### Social Login
157
+ ```ruby
158
+ Stormpath::Rails::Login::NewController
159
+ Stormpath::Rails::Login::CreateController
162
160
 
163
- Stormpath Rails supports social login as well. Currently only Facebook is supported, Providers for: Google, Github and Linkedin are currently in development.
161
+ Stormpath::Rails::Logout::CreateController
164
162
 
165
- In order to enable Facebook login you first you need to create a Facebook application and create a Facebook directory in your stormpath account. More info can be found [here](https://docs.stormpath.com/rest/product-guide/#integrating-with-facebook). After that you need to enable id from storm paths configuration file and provide facebook app_id and app_secret which is provided to you after Facebook app creation.
163
+ Stormpath::Rails::Register::NewController
164
+ Stormpath::Rails::Register::CreateController
166
165
 
167
- ```ruby
168
- Stormpath::Rails.configure do |config|
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
- When user navigates to `/login` he will see a facebook login button. If he is authenticated succesfully he will be redirected back to rails root_path.
169
+ Stormpath::Rails::ForgotPassword::NewController
170
+ Stormpath::Rails::ForgotPassword::CreateController
177
171
 
178
- ## Overriding Stormpath
172
+ Stormpath::Rails::VerifyEmail::ShowController
173
+ Stormpath::Rails::VerifyEmail::CreateController
179
174
 
180
- ### Routes
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
- ```sh
184
- rails generate stormpath:routes
177
+ Stormpath::Rails::Oauth2::NewController
178
+ Stormpath::Rails::Oauth2::CreateController
185
179
  ```
186
180
 
187
- ### Controllers
188
- To override a Stormpath controller, subclass it and update the routes to point to your new controller (see the "Routes" section).
189
- ```ruby
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 stormpath views generator to copy the default views to your application for modification.
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
- app/views/layouts/stormpath.html.erb
203
-
204
- app/views/passwords/edit.html.erb
205
- app/views/passwords/email_sent.html.erb
206
- app/views/passwords/forgot.html.erb
207
- app/views/passwords/forgot_change.html.erb
208
- app/views/passwords/forgot_change_failed.html.erb
209
- app/views/passwords/forgot_complete.html.erb
210
-
211
- app/views/sessions/_facebook_login_form.erb
212
- app/views/sessions/_form.html.erb
213
- app/views/sessions/new.html.erb
214
-
215
- app/views/users/_form.html.erb
216
- app/views/users/new.html.erb
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
- ### Supported Ruby Versions
209
+ ## Development
210
+
211
+ ### Prerequisites
212
+
213
+ If you wish to contribute to the gem, please follow these steps:
224
214
 
225
- * Ruby 2.0.0
226
- * Ruby 2.1
227
- * Ruby 2.2
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
- ### Suported Rails Versions
224
+ ### Specs
230
225
 
231
- above Rails 3.2
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 "rubygems"
2
- require "bundler/setup"
3
- require "bundler/gem_tasks"
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bundler/gem_tasks'
4
4
 
5
- require "rake"
6
- require "rspec/core/rake_task"
5
+ require 'rake'
6
+ require 'rspec/core/rake_task'
7
7
 
8
8
  namespace :dummy do
9
- require_relative "spec/dummy/config/application"
9
+ require_relative 'spec/dummy/config/application'
10
10
  Dummy::Application.load_tasks
11
11
  end
12
12
 
13
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
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 :default => :spec
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
- class Stormpath::Rails::BaseController < ApplicationController
1
+ module Stormpath
2
+ module Rails
3
+ class BaseController < ApplicationController
4
+ include Stormpath::Rails::Controller
2
5
 
3
- layout 'stormpath'
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
- private
10
+ layout 'stormpath/rails/layouts/stormpath'
6
11
 
7
- def set_flash_message(key, message)
8
- flash[key] = message if message.present?
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