upd: change auth page
This commit is contained in:
parent
c19ef16a06
commit
58988c2b3c
|
@ -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}`;
|
||||||
|
|
Loading…
Reference in New Issue