-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
482 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import axios from "axios"; | ||
import { getCookie } from "@/ee/sso/utils/cookies"; | ||
import { getBaseUrl } from "@/boot/axios"; | ||
|
||
import type { SSOProvider } from "@/ee/sso/types/sso"; | ||
|
||
const baseUrl = "accounts"; | ||
|
||
interface FormData { | ||
provider: string; | ||
process: string; | ||
callback_url: string; | ||
csrfmiddlewaretoken: string; | ||
} | ||
|
||
export function getCSRFToken() { | ||
return getCookie("csrftoken"); | ||
} | ||
|
||
// needed for sso provider redirect | ||
function postForm(url: string, data: FormData) { | ||
const f = document.createElement("form"); | ||
f.method = "POST"; | ||
f.action = url; | ||
|
||
for (const key in data) { | ||
const d = document.createElement("input"); | ||
d.type = "hidden"; | ||
d.name = key; | ||
d.value = data[key]; | ||
f.appendChild(d); | ||
} | ||
document.body.appendChild(f); | ||
f.submit(); | ||
} | ||
|
||
// sso providers | ||
export interface AllAuthResponse<T> { | ||
data: T; | ||
status: number; | ||
} | ||
|
||
export async function fetchSSOProviders(): Promise<SSOProvider> { | ||
const { data } = await axios.get(`${baseUrl}/ssoproviders/`); | ||
return data; | ||
} | ||
|
||
export async function addSSOProvider(payload: SSOProvider) { | ||
const { data } = await axios.post(`${baseUrl}/ssoproviders/`, payload); | ||
return data; | ||
} | ||
|
||
export async function editSSOProvider(id: number, payload: SSOProvider) { | ||
const { data } = await axios.put(`${baseUrl}/ssoproviders/${id}/`, payload); | ||
return data; | ||
} | ||
|
||
export async function removeSSOProvider(id: number) { | ||
const { data } = await axios.delete(`${baseUrl}/ssoproviders/${id}/`); | ||
return data; | ||
} | ||
|
||
export async function getCurrentSession() { | ||
const { data } = await axios.get("_allauth/browser/v1/auth/session"); | ||
return data; | ||
} | ||
|
||
export interface SSOProviderConfig { | ||
client_id: string; | ||
flows: string[]; | ||
id: string; | ||
name: string; | ||
} | ||
|
||
export interface SSOConfigResponseProviders { | ||
providers: SSOProviderConfig[]; | ||
} | ||
|
||
export interface SSOConfigResponse { | ||
socialaccount: SSOConfigResponseProviders; | ||
} | ||
|
||
export async function getSSOConfig(): Promise< | ||
AllAuthResponse<SSOConfigResponse> | ||
> { | ||
const { data } = await axios.get("_allauth/browser/v1/config"); | ||
return data; | ||
} | ||
|
||
export async function openSSOProviderRedirect(id: string) { | ||
postForm(`${getBaseUrl()}/_allauth/browser/v1/auth/provider/redirect`, { | ||
provider: id, | ||
process: "login", | ||
callback_url: `${location.origin}/account/provider/callback`, | ||
csrfmiddlewaretoken: getCSRFToken() || "", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<template> | ||
<q-dialog ref="dialogRef" @hide="onDialogHide"> | ||
<q-card class="q-dialog-plugin" style="width: 50"> | ||
<q-bar> | ||
{{ props.provider ? "Edit SSO Provider" : "Add SSO Provider" }} | ||
<q-space /> | ||
<q-btn dense flat icon="close" v-close-popup> | ||
<q-tooltip class="bg-white text-primary">Close</q-tooltip> | ||
</q-btn> | ||
</q-bar> | ||
|
||
<!-- name --> | ||
<q-card-section> | ||
<q-input | ||
:readonly="!!props.provider" | ||
label="Name" | ||
outlined | ||
dense | ||
v-model="localProvider.name" | ||
:rules="[(val) => !!val || '*Required']" | ||
/> | ||
</q-card-section> | ||
|
||
<!-- url --> | ||
<q-card-section> | ||
<q-input | ||
label="Server URL" | ||
outlined | ||
dense | ||
v-model="localProvider.server_url" | ||
:rules="[(val) => !!val || '*Required']" | ||
/> | ||
</q-card-section> | ||
|
||
<!-- client id --> | ||
<q-card-section> | ||
<q-input | ||
label="Client ID" | ||
outlined | ||
dense | ||
v-model="localProvider.client_id" | ||
:rules="[(val) => !!val || '*Required']" | ||
/> | ||
</q-card-section> | ||
|
||
<!-- secret --> | ||
<q-card-section> | ||
<q-input | ||
label="Secret" | ||
outlined | ||
dense | ||
v-model="localProvider.secret" | ||
:rules="[(val) => !!val || '*Required']" | ||
/> | ||
</q-card-section> | ||
|
||
<q-card-actions align="right"> | ||
<q-btn flat label="Cancel" v-close-popup /> | ||
<q-btn | ||
flat | ||
label="Submit" | ||
color="primary" | ||
:loading="loading" | ||
@click="submit" | ||
/> | ||
</q-card-actions> | ||
</q-card> | ||
</q-dialog> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
// composition imports | ||
import { ref, reactive } from "vue"; | ||
import { useDialogPluginComponent, extend } from "quasar"; | ||
import { editSSOProvider, addSSOProvider } from "@/ee/sso/api/sso"; | ||
import { notifySuccess } from "@/utils/notify"; | ||
import { SSOProvider } from "@/types/accounts"; | ||
// define emits | ||
defineEmits([...useDialogPluginComponent.emits]); | ||
// define props | ||
const props = defineProps<{ provider?: SSOProvider }>(); | ||
const { dialogRef, onDialogHide, onDialogOK } = useDialogPluginComponent(); | ||
const loading = ref(false); | ||
const localProvider: SSOProvider = props.provider | ||
? reactive(extend({}, props.provider)) | ||
: reactive({ | ||
id: 0, | ||
name: "", | ||
client_id: "", | ||
secret: "", | ||
server_url: "", | ||
} as SSOProvider); | ||
async function submit() { | ||
loading.value = true; | ||
try { | ||
props.provider | ||
? await editSSOProvider(localProvider.id, localProvider) | ||
: await addSSOProvider(localProvider); | ||
onDialogOK(); | ||
notifySuccess("SSO Provider was edited!"); | ||
} catch (e) {} | ||
loading.value = false; | ||
} | ||
</script> |
Oops, something went wrong.