@@ -17,7 +17,6 @@ const hash = require("pbkdf2-password")();
1717const path = require ( "path" ) ;
1818const session = require ( "express-session" ) ;
1919const jwt = require ( "jsonwebtoken" ) ;
20- const url = require ( "url" ) ;
2120
2221var app = ( module . exports = express ( ) ) ;
2322
@@ -140,11 +139,16 @@ app.get("/analytics", restrict, function (req, res) {
140139} ) ;
141140
142141app . get ( "/logout" , function ( req , res ) {
143- // destroy the user's session to log them out
144- // will be re-created next request
145- req . session . destroy ( function ( ) {
146- res . redirect ( "/" ) ;
147- } ) ;
142+ const mbLogoutUrl = new URL ( "/auth/logout" , METABASE_SITE_URL ) ;
143+
144+ // destroy the user's session to log them out
145+ // will be re-created next request
146+ req . session . destroy ( function ( ) {
147+ // sign user out of Metabase by loading /auth/logout in a hidden iframe
148+ res . send ( `
149+ You have been logged out. <a href="/login">Log in</a>
150+ <iframe src="${ mbLogoutUrl } " hidden></iframe>` ) ;
151+ } ) ;
148152} ) ;
149153
150154app . get ( "/login" , function ( req , res ) {
@@ -184,15 +188,11 @@ app.post("/login", function (req, res, next) {
184188} ) ;
185189
186190app . get ( "/sso/metabase" , restrict , ( req , res ) => {
187- res . redirect (
188- url . format ( {
189- pathname : `${ METABASE_SITE_URL } /auth/sso` ,
190- query : {
191- jwt : signUserToken ( req . session . user ) ,
192- return_to : `${ req . query . return_to || "/" } ?${ mods } ` ,
193- } ,
194- } )
195- ) ;
191+ const ssoUrl = new URL ( "/auth/sso" , METABASE_SITE_URL ) ;
192+ ssoUrl . searchParams . set ( "jwt" , signUserToken ( req . session . user ) ) ;
193+ ssoUrl . searchParams . set ( "return_to" , `${ req . query . return_to ?? "/" } ?${ mods } ` ) ;
194+
195+ res . redirect ( ssoUrl ) ;
196196} ) ;
197197
198198const PORT = 8080 ;
0 commit comments