Skip to content

Instantly share code, notes, and snippets.

@affix
Created December 16, 2025 09:22
Show Gist options
  • Select an option

  • Save affix/ed615d1aacf01cf84ebe09b018089419 to your computer and use it in GitHub Desktop.

Select an option

Save affix/ed615d1aacf01cf84ebe09b018089419 to your computer and use it in GitHub Desktop.
A user script to automatically log you on to Entra if you have mutliple identities
// ==UserScript==
// @name GitHub to Entra Auto-Clicker
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Handle multiple EntraID accounts on the Entra SSO Page when logging in to Github Orgs
// @author Keiran Smith
// @match https://login.microsoftonline.com/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @downloadURL https://gist.github.com/affix/ed615d1aacf01cf84ebe09b018089419/raw/738d6d72fa9cd0b3f8298c9ee7f4f324a14d5026/entra-auto-login.user.js
// @updateURL https://gist.github.com/affix/ed615d1aacf01cf84ebe09b018089419/raw/738d6d72fa9cd0b3f8298c9ee7f4f324a14d5026/entra-auto-login.user.js
// ==/UserScript==
(function() {
'use strict';
const DEFAULT_EMAIL = 'you@somesite.com';
// Get email from settings or use default
function getTargetEmail() {
return GM_getValue('TARGET_EMAIL', DEFAULT_EMAIL);
}
// Set email in settings
function setTargetEmail(email) {
GM_setValue('TARGET_EMAIL', email);
}
// Register menu command to change email
GM_registerMenuCommand('Set Target Email', () => {
const currentEmail = getTargetEmail();
const newEmail = prompt('Enter the email address to auto-click:', currentEmail);
if (newEmail && newEmail.trim()) {
setTargetEmail(newEmail.trim());
alert(`Target email set to: ${newEmail.trim()}`);
}
});
// Only run if redirected from GitHub
if (!document.referrer.includes('github.com')) {
return;
}
console.log('GitHub redirect detected, attempting auto-login');
function clickAccountTile(email) {
const containers = Array.from(document.getElementsByClassName('tile-container'));
const targetContainer = containers.find(el => el.textContent.includes(email));
if (targetContainer) {
const clickableButton = targetContainer.querySelector('[role="button"][tabindex="0"]');
if (clickableButton) {
console.log('Clicking account tile for:', email);
clickableButton.click();
return true;
}
}
return false;
}
// Observe for dynamic content
const observer = new MutationObserver(() => {
if (clickAccountTile(getTargetEmail())) {
console.log('Successfully clicked account tile');
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Cleanup after 10 seconds
setTimeout(() => observer.disconnect(), 10000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment