stormpath-rails 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.gitmodules +3 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/app/controllers/stormpath/rails/register/create_controller.rb +1 -1
- data/docs/Makefile +225 -0
- data/docs/_static/facebook-new-project.png +0 -0
- data/docs/_static/facebook-url-settings.png +0 -0
- data/docs/_static/forgot-change.png +0 -0
- data/docs/_static/forgot-complete.png +0 -0
- data/docs/_static/forgot-email-sent.png +0 -0
- data/docs/_static/forgot-email.png +0 -0
- data/docs/_static/forgot-init.png +0 -0
- data/docs/_static/forgot.png +0 -0
- data/docs/_static/github_create_app.png +0 -0
- data/docs/_static/google-enable-login.png +0 -0
- data/docs/_static/google-new-project.png +0 -0
- data/docs/_static/google-oauth-settings.png +0 -0
- data/docs/_static/id-site-login.png +0 -0
- data/docs/_static/id-site-settings.png +0 -0
- data/docs/_static/id-site-stormpath-config.png +0 -0
- data/docs/_static/linkedin-add-authorized-urls.gif +0 -0
- data/docs/_static/linkedin-add-permissions.gif +0 -0
- data/docs/_static/linkedin-new-application.gif +0 -0
- data/docs/_static/linkedin-permissions-page.png +0 -0
- data/docs/_static/login-page-basic.png +0 -0
- data/docs/_static/login-page-facebook-permissions.png +0 -0
- data/docs/_static/login-page-facebook.png +0 -0
- data/docs/_static/login-page-google-account.png +0 -0
- data/docs/_static/login-page-google.png +0 -0
- data/docs/_static/login-page-linkedin.png +0 -0
- data/docs/_static/login-page.png +0 -0
- data/docs/_static/login_page_with_all_providers.png +0 -0
- data/docs/_static/registration-page-basic.png +0 -0
- data/docs/_static/registration-page-error.png +0 -0
- data/docs/_static/registration-page.png +0 -0
- data/docs/_static/verification-complete.png +0 -0
- data/docs/_static/verification-email.png +0 -0
- data/docs/_static/verification.png +0 -0
- data/docs/_templates/layout.html +6 -0
- data/docs/about.rst +72 -0
- data/docs/authentication.rst +332 -0
- data/docs/changelog.rst +41 -0
- data/docs/conf.py +346 -0
- data/docs/configuration.rst +151 -0
- data/docs/contributors.rst +56 -0
- data/docs/devise_import.rst +112 -0
- data/docs/help.rst +24 -0
- data/docs/index.rst +31 -0
- data/docs/login.rst +242 -0
- data/docs/logout.rst +73 -0
- data/docs/password_reset.rst +85 -0
- data/docs/quickstart.rst +179 -0
- data/docs/registration.rst +364 -0
- data/docs/social_login.rst +409 -0
- data/docs/templates.rst +100 -0
- data/docs/user_data.rst +216 -0
- data/lib/stormpath/rails/version.rb +1 -1
- data/stormpath-rails.gemspec +1 -1
- metadata +57 -4
data/docs/index.rst
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Stormpath Rails Gem Guide
|
2
|
+
=============================
|
3
|
+
|
4
|
+
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.
|
5
|
+
|
6
|
+
Stormpath makes it incredibly simple to add users and user data to your application. It aims to completely abstract away all user registration, login, authentication, and authorization problems, and make building secure websites painless.
|
7
|
+
And the best part? **You don't even need a database!**
|
8
|
+
|
9
|
+
User Guide
|
10
|
+
----------
|
11
|
+
|
12
|
+
This part of the documentation will show you how to get started with the Stormpath Rails Gem. If you're new to the gem, start here!
|
13
|
+
|
14
|
+
.. toctree::
|
15
|
+
:maxdepth: 2
|
16
|
+
|
17
|
+
about
|
18
|
+
quickstart
|
19
|
+
configuration
|
20
|
+
user_data
|
21
|
+
authentication
|
22
|
+
registration
|
23
|
+
login
|
24
|
+
social_login
|
25
|
+
logout
|
26
|
+
password_reset
|
27
|
+
devise_import
|
28
|
+
templates
|
29
|
+
help
|
30
|
+
contributors
|
31
|
+
changelog
|
data/docs/login.rst
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
.. _login:
|
2
|
+
|
3
|
+
|
4
|
+
Login
|
5
|
+
=====
|
6
|
+
|
7
|
+
By default this gem will serve an HTML login page at ``/login``. You can
|
8
|
+
change this URI with the ``web.login.uri`` option. You can disable this feature
|
9
|
+
entirely by setting ``web.login.enabled`` to ``false``.
|
10
|
+
|
11
|
+
To view the default page in your example application, navigate to this URL:
|
12
|
+
|
13
|
+
http://localhost:3000/login
|
14
|
+
|
15
|
+
If the login attempt is successful, we will send the user to the Next URI and
|
16
|
+
create the proper session cookies.
|
17
|
+
|
18
|
+
|
19
|
+
Next URI
|
20
|
+
--------
|
21
|
+
|
22
|
+
The form will render with two fields for login and password, and this form
|
23
|
+
will be posted to ``/login``. If login is successful, we will redirect the user
|
24
|
+
to ``/``. If you wish to change this, use the ``nextUri`` config option::
|
25
|
+
|
26
|
+
.. code-block:: yaml
|
27
|
+
|
28
|
+
web:
|
29
|
+
login:
|
30
|
+
enabled: true,
|
31
|
+
nextUri: "/dashboard"
|
32
|
+
|
33
|
+
|
34
|
+
Form Customization
|
35
|
+
------------------
|
36
|
+
|
37
|
+
The label and placeholder values can be changed by modifying the login form
|
38
|
+
field configuration:
|
39
|
+
|
40
|
+
.. code-block:: yaml
|
41
|
+
|
42
|
+
web:
|
43
|
+
login:
|
44
|
+
form:
|
45
|
+
fields:
|
46
|
+
login:
|
47
|
+
label: 'Your Username or Email',
|
48
|
+
placeholder: 'email@trustyapp.com'
|
49
|
+
password:
|
50
|
+
label: 'Your super-secure PAssw0rd!'
|
51
|
+
|
52
|
+
|
53
|
+
Controller private & helper methods
|
54
|
+
-----------------------------------
|
55
|
+
|
56
|
+
The Application Controller gets the ``Stormpath::Rails::Controller`` module included by default. The module provides 4 private controller methods:
|
57
|
+
|
58
|
+
- ``current_account`` - get the current account
|
59
|
+
- ``signed_in?`` - check if the user is signed in.
|
60
|
+
- ``require_authentication!`` - a before action to stop unauthenticated access.
|
61
|
+
- ``require_no_authentication!`` - a before action to stop authenticated access (a logged in user shouldn't be able to see the login form).
|
62
|
+
|
63
|
+
By default, the ``current_account`` and ``signed_in?`` are marked as helper_methods and you can use them in your views.
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
|
68
|
+
.. _json_login_api:
|
69
|
+
|
70
|
+
JSON Login API
|
71
|
+
--------------
|
72
|
+
|
73
|
+
If you want to make a login attempt from a front-end application (Angular, React),
|
74
|
+
simply post a JSON body to the ``/login`` endpoint, with the following format::
|
75
|
+
|
76
|
+
{
|
77
|
+
"login": "foo@bar.com",
|
78
|
+
"password": "myPassword"
|
79
|
+
}
|
80
|
+
|
81
|
+
If the login attempt is successful, you will receive a 200 OK response and the
|
82
|
+
session cookies will be set on the response. If there is an error we will
|
83
|
+
send a 400 status with an error message in the body.
|
84
|
+
|
85
|
+
If you make a GET request to the login endpoint, with ``Accept:
|
86
|
+
application/json``, we will send you a JSON view model that describes the login
|
87
|
+
form and the social account stores that are mapped to your Stormpath
|
88
|
+
Application. Here is an example view model that shows you an application that
|
89
|
+
has a default login form, and a mapped Google directory:
|
90
|
+
|
91
|
+
.. code-block:: javascript
|
92
|
+
|
93
|
+
{
|
94
|
+
"accountStores": [
|
95
|
+
{
|
96
|
+
"name": "stormpath-rails google",
|
97
|
+
"href": "https://api.stormpath.com/v1/directories/gc0Ty90yXXk8ifd2QPwt",
|
98
|
+
"provider": {
|
99
|
+
"providerId": "google",
|
100
|
+
"href": "https://api.stormpath.com/v1/directories/gc0Ty90yXXk8ifd2QPwt/provider",
|
101
|
+
"clientId": "422132428-9auxxujR9uku8I5au.apps.googleusercontent.com",
|
102
|
+
"scope": "email profile"
|
103
|
+
}
|
104
|
+
}
|
105
|
+
],
|
106
|
+
"form": {
|
107
|
+
"fields": [
|
108
|
+
{
|
109
|
+
"label": "Username or Email",
|
110
|
+
"placeholder": "Username or Email",
|
111
|
+
"required": true,
|
112
|
+
"type": "text",
|
113
|
+
"name": "login"
|
114
|
+
},
|
115
|
+
{
|
116
|
+
"label": "Password",
|
117
|
+
"placeholder": "Password",
|
118
|
+
"required": true,
|
119
|
+
"type": "password",
|
120
|
+
"name": "password"
|
121
|
+
}
|
122
|
+
]
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
Overriding Login
|
128
|
+
----------------
|
129
|
+
|
130
|
+
Controllers
|
131
|
+
...........
|
132
|
+
|
133
|
+
Since Stormpath controllers are highly configurable, they have lots of configuration code and are not written in a traditional way.
|
134
|
+
|
135
|
+
A LoginController would usually have two actions - new & create, however in Stormpath-Rails they are separated into two single action controllers - ``Stormpath::Rails::Login::NewController`` and ``Stormpath::Rails::Login::CreateController``.
|
136
|
+
They both respond to a ``call`` method (action).
|
137
|
+
|
138
|
+
To override a Stormpath controller, first you need to subclass it:
|
139
|
+
|
140
|
+
.. code-block:: ruby
|
141
|
+
|
142
|
+
class CreateSessionController < Stormpath::Rails::Login::CreateController
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
and update the routes to point to your new controller:
|
147
|
+
|
148
|
+
.. code-block:: ruby
|
149
|
+
|
150
|
+
Rails.application.routes.draw do
|
151
|
+
stormpath_rails_routes(actions: {
|
152
|
+
'login#create' => 'create_session#call'
|
153
|
+
})
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
Routes
|
158
|
+
------
|
159
|
+
|
160
|
+
To override routes (while using Stormpath default controllers), please use the configuration file ``config/stormpath.yml`` and override them there.
|
161
|
+
As usual, to see what the routes are, run *rake routes*.
|
162
|
+
|
163
|
+
Views
|
164
|
+
-----
|
165
|
+
|
166
|
+
You can use the Stormpath views generator to copy the default views to your application for modification:
|
167
|
+
|
168
|
+
.. code-block:: ruby
|
169
|
+
|
170
|
+
rails generate stormpath:views
|
171
|
+
|
172
|
+
|
173
|
+
which generates these files::
|
174
|
+
|
175
|
+
stormpath/rails/layouts/stormpath.html.erb
|
176
|
+
|
177
|
+
stormpath/rails/login/new.html.erb
|
178
|
+
stormpath/rails/login/_form.html.erb
|
179
|
+
|
180
|
+
stormpath/rails/register/new.html.erb
|
181
|
+
stormpath/rails/register/_form.html.erb
|
182
|
+
|
183
|
+
stormpath/rails/change_password/new.html.erb
|
184
|
+
|
185
|
+
stormpath/rails/forgot_password/new.html.erb
|
186
|
+
|
187
|
+
stormpath/rails/shared/_input.html.erb
|
188
|
+
|
189
|
+
stormpath/rails/verify_email/new.html.erb
|
190
|
+
|
191
|
+
|
192
|
+
Using ID Site
|
193
|
+
----------------------------------------------------------------------
|
194
|
+
|
195
|
+
Stormpath provides a hosted login application, known as ID Site. This feature
|
196
|
+
allows you to redirect the user to our hosted application. When the user
|
197
|
+
authenticates, they will be redirected back to your application with an identity
|
198
|
+
assertion.
|
199
|
+
|
200
|
+
This feature is useful if you don't want to modify your application to serve
|
201
|
+
web pages or single page apps, and would rather have that hosted somewhere else.
|
202
|
+
|
203
|
+
ID site looks like this:
|
204
|
+
|
205
|
+
.. image:: /_static/id-site-login.png
|
206
|
+
|
207
|
+
|
208
|
+
ID Site Configuration
|
209
|
+
.....................
|
210
|
+
|
211
|
+
If you wish to use the ID Site feature, you will need to log in to the
|
212
|
+
`Stormpath Admin Console`_ and configure the settings. You need to change the
|
213
|
+
**Authorized Redirect Uri** setting and set it to
|
214
|
+
``http://localhost:3000/id_site_result`` in order to instruct Stormpath about the resource that
|
215
|
+
handles all ID Site requests from Stormpath to your application. For example, if you want to support logging out
|
216
|
+
of your application via ID Site, then you need to set the route to which you want to be redirected after a successful logout:
|
217
|
+
|
218
|
+
.. image:: /_static/id-site-stormpath-config.png
|
219
|
+
|
220
|
+
Then you want to enable ID Site in your rails stormpath configuration:
|
221
|
+
|
222
|
+
.. code-block:: yaml
|
223
|
+
|
224
|
+
web:
|
225
|
+
idSite:
|
226
|
+
enabled: true
|
227
|
+
loginUri: ""
|
228
|
+
forgotUri: "/#/forgot"
|
229
|
+
registerUri: "/#/register"
|
230
|
+
|
231
|
+
|
232
|
+
When ID Site is enabled, any request for ``/login`` or ``/register`` will cause a
|
233
|
+
redirect to ID Site. When the user is finished at ID Site they will be
|
234
|
+
redirected to `/id_site_result` on your application. Our gem will handle
|
235
|
+
this request, and then redirect the user to the ``nextUri``.
|
236
|
+
|
237
|
+
For more information about how to use and customize the ID site, please see
|
238
|
+
this documentation:
|
239
|
+
|
240
|
+
http://docs.stormpath.com/guides/using-id-site/
|
241
|
+
|
242
|
+
.. _Stormpath Admin Console: https://api.stormpath.com
|
data/docs/logout.rst
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
.. _logout:
|
2
|
+
|
3
|
+
|
4
|
+
Logout
|
5
|
+
======
|
6
|
+
|
7
|
+
If you are using browser-based sessions, you'll need a way for the user to
|
8
|
+
logout and destroy their session cookies.
|
9
|
+
|
10
|
+
By default this library will automatically provide a POST route at ``/logout``.
|
11
|
+
Simply make a POST request to this URL and the session cookies will be
|
12
|
+
destroyed.
|
13
|
+
|
14
|
+
On a Rails application, this can usually be achieved with the following snippet in a view file:
|
15
|
+
|
16
|
+
.. code-block:: ruby
|
17
|
+
|
18
|
+
<% if signed_in? %>
|
19
|
+
<p>Logged in as: <%= current_account.given_name %></p>
|
20
|
+
<%= link_to "Log out", logout_path, method: :post %>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
|
24
|
+
Configuration Options
|
25
|
+
---------------------
|
26
|
+
|
27
|
+
If you wish to change the logout URI or the redirect url, you can provide the
|
28
|
+
following configuration:
|
29
|
+
|
30
|
+
.. code-block:: yaml
|
31
|
+
|
32
|
+
web:
|
33
|
+
logout:
|
34
|
+
enabled: true,
|
35
|
+
uri: '/log-me-out',
|
36
|
+
nextUri: '/goodbye'
|
37
|
+
|
38
|
+
|
39
|
+
Overriding Logout
|
40
|
+
-----------------
|
41
|
+
|
42
|
+
Controllers
|
43
|
+
...........
|
44
|
+
|
45
|
+
Since Stormpath controllers are highly configurable, they have lots of configuration code and are not written in a traditional way.
|
46
|
+
|
47
|
+
Logging out users is usually done with just a destroy method in some kind of SessionController, but in Stormpath we strive for high configuration so we
|
48
|
+
are handling this with a LogoutController that has one method ``create`` which responds to the ``call`` method.
|
49
|
+
|
50
|
+
To override a Stormpath controller, first you need to subclass it:
|
51
|
+
|
52
|
+
.. code-block:: ruby
|
53
|
+
|
54
|
+
class DestroySessionController < Stormpath::Rails::Logout::CreateController
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
and update the routes to point to your new controller:
|
59
|
+
|
60
|
+
.. code-block:: ruby
|
61
|
+
|
62
|
+
Rails.application.routes.draw do
|
63
|
+
stormpath_rails_routes(actions: {
|
64
|
+
'logout#create' => 'destroy_session#call'
|
65
|
+
})
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
Routes
|
70
|
+
------
|
71
|
+
|
72
|
+
To override routes (while using Stormpath default controllers), please use the configuration file ``config/stormpath.yml`` and override them there.
|
73
|
+
As usual, to see what the routes are, run *rake routes*.
|
@@ -0,0 +1,85 @@
|
|
1
|
+
.. _password_reset:
|
2
|
+
|
3
|
+
|
4
|
+
Password Reset
|
5
|
+
==============
|
6
|
+
|
7
|
+
Stormpath provides a self-service password reset flow for your users, allowing
|
8
|
+
them to request a link that lets them reset their password. This is a very
|
9
|
+
secure feature and we highly suggest it for your application.
|
10
|
+
|
11
|
+
|
12
|
+
Enable the Workflow
|
13
|
+
-------------------
|
14
|
+
|
15
|
+
To use the password reset workflow, you need to enable it on the directory
|
16
|
+
that your application is using. Login to the `Stormpath Admin Console`_ and
|
17
|
+
find your directory, then navigate to the workflows section of that directory.
|
18
|
+
|
19
|
+
Enable the password reset email if it is disabled.
|
20
|
+
|
21
|
+
You should also set the **Link Base Url** to be the following URL if you want the password reset form to be hosted on your domain:
|
22
|
+
|
23
|
+
.. code-block:: sh
|
24
|
+
|
25
|
+
http://localhost:3000/change
|
26
|
+
|
27
|
+
You can leave the default URL if you want the user to be redirected to the Stormpath password reset page with the reset form: ``https://api.stormpath.com/passwordReset``
|
28
|
+
|
29
|
+
|
30
|
+
Adjust Workflow in Config File
|
31
|
+
------------------------------
|
32
|
+
|
33
|
+
Make sure that you enable the workflow in your ``stormpath.yml`` configuration file
|
34
|
+
|
35
|
+
.. code-block:: yaml
|
36
|
+
|
37
|
+
web:
|
38
|
+
forgotPassword:
|
39
|
+
enabled: true
|
40
|
+
uri: "/forgot"
|
41
|
+
view: "stormpath/rails/forgot_password/new"
|
42
|
+
nextUri: "/login?status=forgot"
|
43
|
+
changePassword:
|
44
|
+
enabled: true
|
45
|
+
autoLogin: false
|
46
|
+
uri: "/change" # make sure the URI matches the one you stored in the Stormpath dashboard as the Link Base Url
|
47
|
+
nextUri: "/login?status=reset"
|
48
|
+
view: "stormpath/rails/change_password/new"
|
49
|
+
errorUri: "/forgot?status=invalid_sptoken"
|
50
|
+
|
51
|
+
|
52
|
+
You may also change the URLs of the pages in this workflow, as well as the redirect URLs that we use during the workflow.
|
53
|
+
If so, just make sure that you apply the changes to the **Link Base Url** in the Stormpath dashboard, and restart your server.
|
54
|
+
|
55
|
+
Using the Workflow
|
56
|
+
------------------
|
57
|
+
|
58
|
+
After enabling the workflow, restart your Rails application. You can now
|
59
|
+
complete a password reset workflow by doing the following steps:
|
60
|
+
|
61
|
+
* The login form at ``/login`` will show a "Forgot Password?" link.
|
62
|
+
* Clicking that link will take you to ``/forgot``, where you can ask for a password reset email
|
63
|
+
* After you receive the email, clicking on the link will take you to ``/change``
|
64
|
+
* You'll see a form that allows you to change your password
|
65
|
+
* After changing your password, you are taken to the login form
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Auto Login
|
70
|
+
----------
|
71
|
+
|
72
|
+
Our gem implements the most secure workflow by default: the user must
|
73
|
+
request a password reset link, then login again after changing their password.
|
74
|
+
We recommend these settings for security purposes, but if you wish to automatically
|
75
|
+
log the user in after they reset their password you can enable that functionality
|
76
|
+
with this option:
|
77
|
+
|
78
|
+
.. code-block:: yaml
|
79
|
+
|
80
|
+
web:
|
81
|
+
changePassword:
|
82
|
+
autoLogin: false
|
83
|
+
|
84
|
+
|
85
|
+
.. _Stormpath Admin Console: https://api.stormpath.com
|
data/docs/quickstart.rst
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
.. _quickstart:
|
2
|
+
|
3
|
+
|
4
|
+
Quickstart
|
5
|
+
=============================
|
6
|
+
|
7
|
+
This section walks you through the basic setup for Stormpath Rails gem, by the end
|
8
|
+
of this page you'll have setup the login and registration features for your
|
9
|
+
Rails application!
|
10
|
+
|
11
|
+
Create a Stormpath Account
|
12
|
+
--------------------------
|
13
|
+
|
14
|
+
Now that you've decided to use Stormpath, the first thing you'll want to do is
|
15
|
+
create a new Stormpath account: https://api.stormpath.com/register
|
16
|
+
|
17
|
+
|
18
|
+
Create an API Key Pair
|
19
|
+
----------------------
|
20
|
+
|
21
|
+
Once you've created a new account you need to create a new API key pair. A new
|
22
|
+
API key pair is easily created by logging into your dashboard and clicking the
|
23
|
+
"Create an API Key" button. This will generate a new API key for you, and
|
24
|
+
prompt you to download your key pair.
|
25
|
+
|
26
|
+
.. note::
|
27
|
+
Please keep the API key pair file you just downloaded safe! These two keys
|
28
|
+
allow you to make Stormpath API requests, and should be properly protected,
|
29
|
+
backed up, etc.
|
30
|
+
|
31
|
+
Once you've downloaded your `apiKey.properties` file, save it and be sure to set up the following environment variables:
|
32
|
+
|
33
|
+
- STORMPATH_API_KEY_ID
|
34
|
+
- STORMPATH_API_KEY_SECRET
|
35
|
+
|
36
|
+
Environment variables should be set up in you .bashrc file (or .zshrc if you use myzsh).
|
37
|
+
|
38
|
+
Example setup:
|
39
|
+
|
40
|
+
.. code-block:: sh
|
41
|
+
|
42
|
+
export STORMPATH_API_KEY_ID=6U4HZMHGVHN0U765BGW
|
43
|
+
export STORMPATH_API_KEY_SECRET=0e0TuVZKYiPiLTDLNnswEwpPpa5nPv
|
44
|
+
|
45
|
+
Find Your Stormpath Application
|
46
|
+
-------------------------------
|
47
|
+
|
48
|
+
All new Stormpath Tenants will have a Stormpath Application, called
|
49
|
+
"My Application". You'll generally want one application per project, and we can
|
50
|
+
use this default application to get started.
|
51
|
+
|
52
|
+
An application has a HREF, and it looks like this:
|
53
|
+
|
54
|
+
.. code-block:: sh
|
55
|
+
|
56
|
+
https://api.stormpath.com/v1/applications/24kkU5XOz4tQlZ7sBtPUN6
|
57
|
+
|
58
|
+
From inside the `Admin Console`_, you can find the HREF by navigating to the
|
59
|
+
Application in the Application's list.
|
60
|
+
|
61
|
+
To learn more about Stormpath Applications, please see the
|
62
|
+
`Application Resource`_ and
|
63
|
+
`Setting up Development and Production Environments`_
|
64
|
+
|
65
|
+
.. note::
|
66
|
+
Your default Application will also have a directory mapped to it. The
|
67
|
+
Directory is where Stormpath stores accounts. To learn more, please see
|
68
|
+
`Directory Resource`_ and `Modeling Your User Base`_.
|
69
|
+
|
70
|
+
- Make sure your application has a default account directory.
|
71
|
+
|
72
|
+
Now that you have your application HREF, make sure to set up another environment variable:
|
73
|
+
|
74
|
+
.. code-block:: sh
|
75
|
+
|
76
|
+
export STORMPATH_APPLICATION_URL=https://api.stormpath.com/v1/applications/24kkU5XOz4tQlZ7sBtPUN6
|
77
|
+
|
78
|
+
|
79
|
+
You're ready to bundle Stormpath Rails gem into your project!
|
80
|
+
|
81
|
+
Install the Gem
|
82
|
+
-------------------
|
83
|
+
|
84
|
+
Now that you've got a Stormpath account all setup and ready to go, all that's
|
85
|
+
left to do before we can dive into the code is install the gem.
|
86
|
+
|
87
|
+
Stormpath Rails officially supports Ruby versions over 2.1.0 and Rails over 4.0.
|
88
|
+
|
89
|
+
Add the stormpath-rails integration gem to your Gemfile.
|
90
|
+
|
91
|
+
Stormpath is currently in beta so it is necessary to include the gem version:
|
92
|
+
|
93
|
+
.. code-block:: ruby
|
94
|
+
|
95
|
+
gem 'stormpath-rails', '~> 2.0.0'
|
96
|
+
|
97
|
+
Bundle the Gemfile
|
98
|
+
|
99
|
+
.. code-block:: ruby
|
100
|
+
|
101
|
+
bundle install
|
102
|
+
|
103
|
+
Run the generator to insert the config yaml file and the neccessary controller module.
|
104
|
+
|
105
|
+
.. code-block:: sh
|
106
|
+
|
107
|
+
rails generate stormpath:install
|
108
|
+
|
109
|
+
|
110
|
+
Routes configuration
|
111
|
+
----------------------------
|
112
|
+
|
113
|
+
Make sure that you have the `root_path` defined in your rails `routes.rb`
|
114
|
+
|
115
|
+
Then, add `stormpath_rails_routes` to your routes.rb file.
|
116
|
+
|
117
|
+
.. code-block:: ruby
|
118
|
+
|
119
|
+
Rails.application.routes.draw do
|
120
|
+
root 'home#index'
|
121
|
+
stormpath_rails_routes
|
122
|
+
...
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
Start your server
|
127
|
+
----------------------------
|
128
|
+
|
129
|
+
Yes, that's it.
|
130
|
+
|
131
|
+
With this minimal configuration, our library will do the following:
|
132
|
+
|
133
|
+
- Fetch your Stormpath Application and all the data about its configuration and
|
134
|
+
account stores.
|
135
|
+
|
136
|
+
- Attach the default features to your Rails application, such as the
|
137
|
+
login page and registration page.
|
138
|
+
|
139
|
+
- Hold any requests that require authentication, until Stormpath is ready.
|
140
|
+
|
141
|
+
That's it, you're ready to go! Try navigating to these URLs in your application:
|
142
|
+
|
143
|
+
- http://localhost:3000/login
|
144
|
+
- http://localhost:3000/register
|
145
|
+
|
146
|
+
You should be able to register for an account and log in. The newly created
|
147
|
+
account will be placed in the directory that is mapped to "My Application".
|
148
|
+
|
149
|
+
.. note::
|
150
|
+
|
151
|
+
By default, we don't require email verification for new accounts, but we
|
152
|
+
highly recommend you use this workflow. You can enable email verification
|
153
|
+
by logging into the `Admin Console`_ and going to the the Workflows tab
|
154
|
+
for the directory of your Stormpath Application.
|
155
|
+
|
156
|
+
There are many more features than login and registration, please continue to the
|
157
|
+
next section to learn more!
|
158
|
+
|
159
|
+
|
160
|
+
Example Applications
|
161
|
+
--------------------
|
162
|
+
|
163
|
+
Looking for some example applications? We provide the following examples
|
164
|
+
applications to get you up and running quickly. They show you how to setup
|
165
|
+
Stormpath, and implement a profile page for the logged-in user:
|
166
|
+
|
167
|
+
- `Stormpath-Rails Sample Project`_
|
168
|
+
|
169
|
+
- `Stormpath Angular + Rails Sample Project`_
|
170
|
+
|
171
|
+
.. _Admin Console: https://api.stormpath.com/login
|
172
|
+
.. _Application Resource: https://docs.stormpath.com/rest/product-guide/latest/reference.html#application
|
173
|
+
.. _Active Directory: http://en.wikipedia.org/wiki/Active_Directory
|
174
|
+
.. _Directory Resource: https://docs.stormpath.com/rest/product-guide/latest/reference.html#directory
|
175
|
+
.. _Stormpath-Rails Sample Project: https://github.com/stormpath/stormpath-rails-sample
|
176
|
+
.. _LDAP: http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol
|
177
|
+
.. _Modeling Your User Base: https://docs.stormpath.com/rest/product-guide/latest/accnt_mgmt.html#modeling-your-user-base
|
178
|
+
.. _Setting up Development and Production Environments: https://docs.stormpath.com/guides/dev-test-prod-environments/
|
179
|
+
.. _Stormpath Angular + Rails Sample Project: https://github.com/stormpath/stormpath-angular-rails-sample
|