Skip to content

Commit

Permalink
oauth: auto close callback browser window
Browse files Browse the repository at this point in the history
Makes things a little easier for operators using mctl.
  • Loading branch information
joelrebel committed Jun 28, 2024
1 parent 54f59dc commit db62b49
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion internal/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,29 @@ func (c *authClient) handlePKCECallback(ctx context.Context, w http.ResponseWrit
tc <- nil
}

w.Write([]byte("Success. You can now close this window.")) //nolint
w.Write(successHTML()) //nolint
tc <- token
}

func successHTML() []byte {
return []byte(`
<div class="info"><p>Auth success, you may close this page.</p></div>
<div class="auto"></div>
<script>
let auto = document.querySelector('.auto');
var timeout = 5;
setTimeout(function() { this.close(); }, timeout*1000);
var id = setInterval(function() {
if (timeout < 1) {
clearInterval(id);
auto.innerHTML = "Unable to close page automatically";
return;
}
timeout--;
auto.innerHTML = "This page will close automatically in " + timeout + " seconds...";
}, 1000);
</script>
`)
}

0 comments on commit db62b49

Please sign in to comment.