AWS SSO Login Request Authorizer

Clicks the "Confirm and continue" button automatically when running `aws sso login`

As of 2024-04-06. See the latest version.

// ==UserScript==
// @name         AWS SSO Login Request Authorizer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Clicks the "Confirm and continue" button automatically when running `aws sso login`
// @author       Marc PEREZ
// @license      MIT
// @match        https://*.amazonaws.com/?*
// @match        https://*.awsapps.com/start/*
// @icon         https://d2q66yyjeovezo.cloudfront.net/icon/b5164fbdf0a4526876438e688f5e4130-8f4c3d179652d29309b38012bd392a52.svg
// @require      http://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js
// @require      https://update.greasyfork.org/scripts/383527/701631/Wait_for_key_elements.js
// @grant        window.close
// ==/UserScript==

/* globals jQuery, $, waitForKeyElements */

// Change this to `false` if you don't want to close the tab automatically
const CLOSE_AFTER_ALLOW = true;

function click(buttons) {
    buttons[0].click();
}

// Find the "Confirm and continue" button and click it
waitForKeyElements (
    "#cli_verification_btn", click
);

// Find the "Allow access" button and click it
waitForKeyElements (
    "#cli_login_button", click
);


// Close the page after a successful authrorization
function close(span) {
    window.close();
}
if (CLOSE_AFTER_ALLOW) {
    waitForKeyElements (
        'span[data-testid="device-code-unscoped-success"]', close
    );
}