Commit 9765831 Lois Desplat
committed Apr 23, 2016
1 parent 4047201 commit 9765831 Copy full SHA for 9765831
File tree 2 files changed +18
-9
lines changed
2 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -197,13 +197,16 @@ exports.v2 = function (settings) {
197
197
// Authorization callback
198
198
199
199
state = request . state [ cookie ] ;
200
- if ( ! state ) {
201
- if ( request . query && request . query . refresh === 1 ) {
200
+ if ( ! state ) {
201
+ if ( request . query . refresh ) {
202
202
return reply ( Boom . internal ( 'Missing ' + name + ' request token cookie' ) ) ;
203
- } else {
204
- var url = request . connection . info . protocol + '://' + request . info . host + request . url . path + '&refresh=1' ;
205
- return reply ( '<html><head><meta http-equiv="refresh" content="0;URL=\'' + url + '\'"></head><body></body></html>' ) ;
206
203
}
204
+
205
+ // Workaround for some browsers where due to CORS and the redirection method,
206
+ // it will not send the state cookie along until the request comes directly from the same domain
207
+ const newQuery = Object . assign ( { } , request . url . query , { refresh : 1 } ) ;
208
+ const refreshUrl = internals . location ( request , protocol , settings . location ) + '?' + internals . queryString ( newQuery ) ;
209
+ return reply ( `<html><head><meta http-equiv="refresh" content="0;URL="${ refreshUrl } "></head><body></body></html>` ) ;
207
210
}
208
211
209
212
reply . unstate ( cookie ) ;
Original file line number Diff line number Diff line change @@ -1471,7 +1471,7 @@ describe('Bell', () => {
1471
1471
} ) ;
1472
1472
} ) ;
1473
1473
1474
- it ( 'errors on missing cookie in token step' , ( done ) => {
1474
+ it ( 'refreshes & errors on missing cookie in token step' , ( done ) => {
1475
1475
1476
1476
const mock = new Mock . V2 ( ) ;
1477
1477
mock . start ( ( provider ) => {
@@ -1511,11 +1511,17 @@ describe('Bell', () => {
1511
1511
mock . server . inject ( res . headers . location , ( mockRes ) => {
1512
1512
1513
1513
expect ( mockRes . headers . location ) . to . contain ( 'http://localhost:80/login?code=1&state=' ) ;
1514
-
1515
1514
server . inject ( mockRes . headers . location , ( response ) => {
1516
1515
1517
- expect ( response . statusCode ) . to . equal ( 500 ) ;
1518
- mock . stop ( done ) ;
1516
+ expect ( response . statusCode ) . to . equal ( 200 ) ;
1517
+ const newLocation = mockRes . headers . location + '&refresh=1' ;
1518
+ expect ( response . payload ) . to . contain ( newLocation ) ;
1519
+
1520
+ server . inject ( newLocation , ( errorResponse ) => {
1521
+
1522
+ expect ( errorResponse . statusCode ) . to . equal ( 500 ) ;
1523
+ mock . stop ( done ) ;
1524
+ } ) ;
1519
1525
} ) ;
1520
1526
} ) ;
1521
1527
} ) ;
You can’t perform that action at this time.
0 commit comments