Skip to content

Commit

Permalink
Use window.opener instead of displaying the hash
Browse files Browse the repository at this point in the history
  • Loading branch information
spearcat committed Dec 16, 2024
1 parent c31f63f commit 7676ff8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions client-metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"client_id": "https://obsidat.github.io/oauth/client-metadata.json",
"client_name": "obsidat",
"client_uri": "https://obsidat.github.io",
"redirect_uris": ["https://obsidat.github.io/oauth/redirect.html"],
"client_id": "https://atweb-vue.github.io/oauth/client-metadata.json",
"client_name": "atweb-vue",
"client_uri": "https://atweb-vue.github.io",
"redirect_uris": ["https://atweb-vue.github.io/oauth/redirect.html"],
"scope": "atproto transition:generic",
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"],
Expand Down
11 changes: 7 additions & 4 deletions redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
</head>
<body>
<script>
// @ts-check

const p = document.createElement('h2');
p.append('Signed in. Copy and paste this into the popup in Obsidian:');
p.append('Signed in. You can now close this tab.');

const pre = document.createElement('pre');
pre.append(document.location.hash.slice(1));
document.body.append(p);
document.body.append(pre);

(/** @type {typeof window.postMessage} */ (window.opener.postMessage))(document.location.hash.slice(1), '*')

// this is optional, but after retrieving the parameters, we should ideally
// scrub it from history to prevent this authorization state to be replayed,
// just for good measure.
history.replaceState(null, '', location.pathname + location.search);

setTimeout(() => window.close(), 1000);
</script>
</body>
</html>

0 comments on commit 7676ff8

Please sign in to comment.