@@ -81,27 +81,60 @@ This model needs to be the same one defined in the initializer, an instance will
8181To login via Hydra your app needs to send the user to ` /auth/rpi ` via a POST request:
8282
8383``` ruby
84- < %= link_to ' Log in' , ' /auth/rpi' , method: :post %>
84+ link_to ' Log in' , ' /auth/rpi' , method: :post
8585# or:
86- <%= button_to 'Log in', '/auth/rpi' % >
86+ button_to ' Log in' , ' /auth/rpi'
8787```
8888
8989A GET request will be blocked by the CSRF protection gem.
9090
9191Alternatively you can use the path helpers:
9292
9393``` ruby
94- < %= link_to ' Log in' , rpi_auth_login_path, method: :post %>
94+ link_to ' Log in' , rpi_auth_login_path, method: :post
9595# or:
96- <%= button_to 'Log in', rpi_auth_login_path % >
96+ button_to ' Log in' , rpi_auth_login_path
9797```
9898
9999There is also a helper for the logout route:
100100
101101``` ruby
102- < %= link_to ' Log out' , rpi_auth_logout_path %>
102+ link_to ' Log out' , rpi_auth_logout_path
103103```
104104
105+ ### Sin
106+
107+ ### Redirecting users to the "next step"
108+
109+ There are a three possible places the user will end up at following logging in,
110+ in the following order:
111+
112+ 1 . The ` success_redirect ` URL.
113+ 2 . The specified ` returnTo ` URL.
114+ 3 . The page the user was on (if the Referer header is sent in).
115+ 4 . The root path of the application.
116+
117+ Note that none of these places can be on a different host, i.e. they have to be
118+ inside your application.
119+
120+ The ` success_redirect ` set in the RpiAuth configuration block will trump
121+ everything, so only use this configuration option if you always want your users
122+ to end up at the same place.
123+
124+ If you wish to redirect users to the next step in the process, e.g. to a
125+ registration form, then you should supply a parameter called ` returnTo ` which
126+ is then used to redirect after log in/sign up are successful.
127+
128+ ``` ruby
129+ button_to ' Log in to start registraion' , rpi_auth_login_path, params: { returnTo: ' /registration_form' }
130+ ```
131+
132+ If this parameter is missing [ Omniauth uses the HTTP Referer
133+ header] ( https://github.com/omniauth/omniauth/blob/d2fd0fc80b0342046484b99102fa00ec5b5392ff/lib/omniauth/strategy.rb#L252-L256 )
134+ meaning (most) users will end up back on the page where they started the auth flow (this is often the most preferable situation).
135+
136+ Finally, if none of these things are set, we end up back at the application root.
137+
105138### Globbed/catch-all routes
106139
107140If your app has a catch-all route at the end of the routing table, you must
0 commit comments