From e38b31bf97c994f5e212fde15c7420c3c68306b5 Mon Sep 17 00:00:00 2001 From: Jeidnx Date: Sun, 18 Jun 2023 18:32:52 +0200 Subject: [PATCH 1/6] Add support for oidc --- src/components/LoginPage.vue | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index d7d287534c..45966fda9d 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -28,6 +28,11 @@
+ @@ -38,9 +43,18 @@ export default { return { username: null, password: null, + oidcProviders: null, }; }, mounted() { + //TODO: Maybe there is a better way to do this? + const urlParams = new URLSearchParams(window.location.search); + const session = urlParams.get("session"); + if (session) { + this.setPreference("authToken" + this.hashCode(this.authApiUrl()), session); + this.$router.push("/"); + } + this.fetchConfig(); //TODO: Add Server Side check if (this.getAuthToken()) { this.$router.push("/"); @@ -50,6 +64,16 @@ export default { document.title = this.$t("titles.login") + " - Piped"; }, methods: { + async fetchConfig() { + this.fetchJson(this.apiUrl() + "/config").then(config => { + this.oidcProviders = config?.oidcProviders.map(name => { + return { + name, + authUrl: `${this.authApiUrl()}/oidc/${name}/login`, + }; + }); + }); + }, login() { if (!this.username || !this.password) return; this.fetchJson(this.authApiUrl() + "/login", null, { From 0efeff00983ca8c2483d5a03a6f69878632643e2 Mon Sep 17 00:00:00 2001 From: Jeidnx Date: Mon, 19 Jun 2023 18:25:58 +0200 Subject: [PATCH 2/6] Include redirect parameter in link --- src/components/LoginPage.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index 45966fda9d..9244e9032a 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -30,7 +30,7 @@ @@ -69,7 +69,7 @@ export default { this.oidcProviders = config?.oidcProviders.map(name => { return { name, - authUrl: `${this.authApiUrl()}/oidc/${name}/login`, + authUri: `${this.authApiUrl()}/oidc/${name}/login?redirect=${window.location.origin}/login`, }; }); }); From f8fc281284e8b200599ec8b73f70a3a407855b65 Mon Sep 17 00:00:00 2001 From: Jeidnx Date: Thu, 26 Oct 2023 13:43:19 +0200 Subject: [PATCH 3/6] Add oidc delete capability --- src/components/LoginPage.vue | 4 +--- src/components/PreferencesPage.vue | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index 9244e9032a..9a12344cda 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -47,9 +47,7 @@ export default { }; }, mounted() { - //TODO: Maybe there is a better way to do this? - const urlParams = new URLSearchParams(window.location.search); - const session = urlParams.get("session"); + const session = this.$route.query.session; if (session) { this.setPreference("authToken" + this.hashCode(this.authApiUrl()), session); this.$router.push("/"); diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index 06ee1192c6..6f08a680a9 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -473,6 +473,7 @@ export default { document.title = this.$t("titles.preferences") + " - Piped"; }, async mounted() { + if (this.$route.query.deleted == this.getAuthToken()) this.logout(); if (Object.keys(this.$route.query).length > 0) this.$router.replace({ query: {} }); this.fetchJson("https://piped-instances.kavin.rocks/").then(resp => { @@ -611,7 +612,8 @@ export default { }), }).then(resp => { if (!resp.error) { - this.logout(); + const redirect = resp.redirect; + redirect ? (location.href = redirect) : this.logout(); } else alert(resp.error); }); }, From 344ae7d06fc4f857400ade647d121a49a615ad76 Mon Sep 17 00:00:00 2001 From: Jeidnx Date: Thu, 26 Oct 2023 14:22:07 +0200 Subject: [PATCH 4/6] fix css --- src/components/LoginPage.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index 4b4b0142b0..a026cb4f36 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -28,9 +28,9 @@
-
    + From b319b96198cd96f104d90d572214aeb3d2303d3d Mon Sep 17 00:00:00 2001 From: Jeidnx Date: Tue, 12 Nov 2024 15:32:42 +0100 Subject: [PATCH 5/6] chore: oidc refinements --- src/components/LoginPage.vue | 7 +++---- src/components/PreferencesPage.vue | 11 ++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index d652e84581..0f5338ec0e 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -33,10 +33,9 @@ - @@ -54,10 +53,10 @@ export default { const session = this.$route.query.session; if (session) { this.setPreference("authToken" + this.hashCode(this.authApiUrl()), session); - this.$router.push("/"); + this.setPreference("isOidcLogin", true); + window.location = import.meta.env.BASE_URL; } this.fetchConfig(); - //TODO: Add Server Side check if (this.getAuthToken()) { this.$router.push(import.meta.env.BASE_URL); } diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index 74271e51a5..99b76a2c7d 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -330,6 +330,7 @@
    0) this.$router.replace({ query: {} }); + const token = this.getAuthToken(); + if (token && this.$route.query.deleted == token) this.logout(); + this.fetchInstances(); if (this.testLocalStorage) { this.selectedInstance = this.getPreferenceString("instance", import.meta.env.VITE_PIPED_API); this.authInstance = this.getPreferenceBoolean("authInstance", false); this.selectedAuthInstance = this.getPreferenceString("auth_instance_url", this.selectedInstance); + this.isOidcLogin = this.getPreferenceBoolean("isOidcLogin", false); this.sponsorBlock = this.getPreferenceBoolean("sponsorblock", true); var skipOptions, skipList; @@ -669,6 +674,10 @@ export default { return "https://www.ssllabs.com/ssltest/analyze.html?d=" + new URL(url).host + "&latest"; }, async deleteAccount() { + if (this.getPreferenceBoolean("isOidcLogin", false)) { + window.location = this.authApiUrl() + "/user/delete?session=" + this.getAuthToken(); + return; + } this.fetchJson(this.authApiUrl() + "/user/delete", null, { method: "POST", headers: { From 788f5f9f8d501ad8192e295711ab3bf5a6f8ef39 Mon Sep 17 00:00:00 2001 From: Jeidnx Date: Wed, 20 Nov 2024 16:36:31 +0100 Subject: [PATCH 6/6] chore: change delete parameters --- src/components/PreferencesPage.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/PreferencesPage.vue b/src/components/PreferencesPage.vue index 99b76a2c7d..0ed34b9324 100644 --- a/src/components/PreferencesPage.vue +++ b/src/components/PreferencesPage.vue @@ -529,6 +529,10 @@ export default { document.title = this.$t("titles.preferences") + " - Piped"; }, async mounted() { + const deleted = this.$route.query.deleted; + if (deleted) { + this.logout(); + } if (Object.keys(this.$route.query).length > 0) this.$router.replace({ query: {} }); const token = this.getAuthToken(); @@ -675,7 +679,10 @@ export default { }, async deleteAccount() { if (this.getPreferenceBoolean("isOidcLogin", false)) { - window.location = this.authApiUrl() + "/user/delete?session=" + this.getAuthToken(); + const url = new URL("/user/delete", this.authApiUrl()); + url.searchParams.append("session", this.getAuthToken()); + url.searchParams.append("redirect", `${window.location.origin}/preferences`); + window.location = url.href; return; } this.fetchJson(this.authApiUrl() + "/user/delete", null, { @@ -688,14 +695,15 @@ export default { }), }).then(resp => { if (!resp.error) { - const redirect = resp.redirect; - redirect ? (location.href = redirect) : this.logout(); + this.logout(); } else alert(resp.error); }); }, logout() { // reset the auth token localStorage.removeItem("authToken" + this.hashCode(this.authApiUrl())); + // Remove oidc state + localStorage.removeItem("isOidcLogin"); // redirect to trending page window.location = import.meta.env.BASE_URL; },