Skip to content

Instantly share code, notes, and snippets.

@eyecatchup
Last active May 2, 2025 16:06
Show Gist options
  • Save eyecatchup/2d700122e24154fdc985b7071ec7764a to your computer and use it in GitHub Desktop.
Save eyecatchup/2d700122e24154fdc985b7071ec7764a to your computer and use it in GitHub Desktop.

Revisions

  1. eyecatchup revised this gist Aug 27, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions calc-sapisidhash.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // Generates the SAPISIDHASH token Google uses in the Authorization header of some API requests
    async function getSApiSidHash(SAPISID, origin) {
    function sha1(str) {
    return window.crypto.subtle.digest("SHA-1", new TextEncoder("utf-8").encode(str)).then(buf => {
  2. eyecatchup created this gist Apr 14, 2022.
    15 changes: 15 additions & 0 deletions calc-sapisidhash.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    async function getSApiSidHash(SAPISID, origin) {
    function sha1(str) {
    return window.crypto.subtle.digest("SHA-1", new TextEncoder("utf-8").encode(str)).then(buf => {
    return Array.prototype.map.call(new Uint8Array(buf), x=>(('00'+x.toString(16)).slice(-2))).join('');
    });
    }

    const TIMESTAMP_MS = Date.now();
    const digest = await sha1(`${TIMESTAMP_MS} ${SAPISID} ${origin}`);

    return `${TIMESTAMP_MS}_${digest}`;
    }

    const SAPISIDHASH = await getSApiSidHash(document.cookie.split('SAPISID=')[1].split('; ')[0], 'https://photos.google.com');
    console.log(SAPISIDHASH);