Add support for oidc

This commit is contained in:
Jeidnx 2023-06-18 18:32:52 +02:00
parent 299f9906b4
commit e38b31bf97
No known key found for this signature in database
GPG key ID: 0E9E697B7E99DF39

View file

@ -28,6 +28,11 @@
<div> <div>
<a class="btn w-auto" @click="login" v-t="'titles.login'" /> <a class="btn w-auto" @click="login" v-t="'titles.login'" />
</div> </div>
<ul class="md:flex-1 md:justify-center md:flex">
<li v-for="provider in oidcProviders" :key="provider.name">
<a class="btn w-auto" :href="provider.authUrl">Log in with {{ provider.name }}</a>
</li>
</ul>
</form> </form>
</div> </div>
</template> </template>
@ -38,9 +43,18 @@ export default {
return { return {
username: null, username: null,
password: null, password: null,
oidcProviders: null,
}; };
}, },
mounted() { 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 //TODO: Add Server Side check
if (this.getAuthToken()) { if (this.getAuthToken()) {
this.$router.push("/"); this.$router.push("/");
@ -50,6 +64,16 @@ export default {
document.title = this.$t("titles.login") + " - Piped"; document.title = this.$t("titles.login") + " - Piped";
}, },
methods: { 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() { login() {
if (!this.username || !this.password) return; if (!this.username || !this.password) return;
this.fetchJson(this.authApiUrl() + "/login", null, { this.fetchJson(this.authApiUrl() + "/login", null, {