@@ -79,7 +79,7 @@ class LoginRequest extends AuthRequest {
7979 static get ( req , res ) {
8080 const request = LoginRequest . fromParams ( req , res )
8181
82- request . renderForm ( )
82+ request . renderForm ( null , req )
8383 }
8484
8585 /**
@@ -157,37 +157,19 @@ class LoginRequest extends AuthRequest {
157157 * @return {string }
158158 */
159159 postLoginUrl ( validUser ) {
160- let uri
161-
162- if ( this . authQueryParams [ 'client_id' ] ) {
163- // Login request is part of an app's auth flow
164- uri = this . authorizeUrl ( )
160+ // Login request is part of an app's auth flow
161+ if ( / t o k e n / . test ( this . authQueryParams [ 'response_type' ] ) ) {
162+ return this . authorizeUrl ( )
163+ // Login request is a user going to /login in browser
165164 } else if ( validUser ) {
166- // Login request is a user going to /login in browser
167- // uri = this.accountManager.accountUriFor(validUser.username)
168- uri = validUser . accountUri
165+ return this . authQueryParams [ 'redirect_uri' ] || validUser . accountUri
169166 }
170-
171- return uri
172167 }
173168
174169 /**
175170 * Redirects the Login request to continue on the OIDC auth workflow.
176171 */
177172 redirectPostLogin ( validUser ) {
178- // TODO: Make the kludge below unnecessary (e.g., by separating OIDC and TLS auth).
179- // If we have arrived here in the WebID-TLS case,
180- // this means the client has done an AJAX POST request to /login/tls.
181- // If the WebID is external, and we send out a redirect to that external URL,
182- // there is a risk that this external URL returns a non-2xx response.
183- // This in turn makes the AJAX call on the client fail,
184- // and its success code is not executed because of that failure.
185- // To prevent this, we just reply a 204 for external WebIDs.
186- if ( this . authMethod === TLS_AUTH && validUser . externalWebId ) {
187- debug ( 'Login successful with WebID-TLS' )
188- return this . response . header ( 'User' , validUser . webId ) . status ( 204 ) . send ( )
189- }
190-
191173 let uri = this . postLoginUrl ( validUser )
192174 debug ( 'Login successful, redirecting to ' , uri )
193175 this . response . redirect ( uri )
@@ -196,13 +178,15 @@ class LoginRequest extends AuthRequest {
196178 /**
197179 * Renders the login form
198180 */
199- renderForm ( error ) {
181+ renderForm ( error , req ) {
182+ let queryString = req && req . url && req . url . replace ( / [ ^ ? ] + \? / , '' ) || ''
200183 let params = Object . assign ( { } , this . authQueryParams ,
201184 {
202185 registerUrl : this . registerUrl ( ) ,
203186 returnToUrl : this . returnToUrl ,
204187 enablePassword : this . localAuth . password ,
205- enableTls : this . localAuth . tls
188+ enableTls : this . localAuth . tls ,
189+ tlsUrl : `/login/tls?${ encodeURIComponent ( queryString ) } `
206190 } )
207191
208192 if ( error ) {
0 commit comments