upd: change auth page

This commit is contained in:
Mar0xy 2023-09-24 20:44:33 +02:00
parent c19ef16a06
commit 58988c2b3c
No known key found for this signature in database
GPG Key ID: 56569BBE47D2C828
1 changed files with 22 additions and 1 deletions

View File

@ -55,12 +55,33 @@ const props = defineProps<{
token: string; token: string;
}>(); }>();
const getUrlParams = () =>
window.location.search
.substring(1)
.split("&")
.reduce((result, query) => {
const [k, v] = query.split("=");
result[k] = decodeURI(v);
return result;
}, {});
let state = $ref<'waiting' | 'accepted' | 'fetch-session-error' | 'denied' | null>(null); let state = $ref<'waiting' | 'accepted' | 'fetch-session-error' | 'denied' | null>(null);
let session = $ref<Misskey.entities.AuthSession | null>(null); let session = $ref<Misskey.entities.AuthSession | null>(null);
function accepted() { function accepted() {
state = 'accepted'; state = 'accepted';
if (session && session.app.callbackUrl) { const isMastodon = !!getUrlParams().mastodon;
if (session && session.app.callbackUrl && isMastodon) {
const redirectUri = decodeURIComponent(getUrlParams().redirect_uri);
if (!session.app.callbackUrl.split("\n").includes(redirectUri)) {
state = "fetch-session-error";
throw new Error("Callback URI doesn't match registered app");
}
const callbackUrl = new URL(redirectUri);
callbackUrl.searchParams.append("code", session.token);
if (getUrlParams().state) callbackUrl.searchParams.append("state", getUrlParams().state);
location.href = callbackUrl.toString();
} else if (session && session.app.callbackUrl) {
const url = new URL(session.app.callbackUrl); const url = new URL(session.app.callbackUrl);
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url'); if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(url.protocol)) throw new Error('invalid url');
location.href = `${session.app.callbackUrl}?token=${session.token}`; location.href = `${session.app.callbackUrl}?token=${session.token}`;