Skip to content

Commit

Permalink
[ui-authorization] authorize application by providing client id
Browse files Browse the repository at this point in the history
Co-authored-by: Maciej Samoraj <[email protected]>
  • Loading branch information
elf-pavlik and samurex committed Nov 6, 2023
1 parent cb210ad commit ad39c40
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 13 deletions.
11 changes: 10 additions & 1 deletion ui/authorization/src/components/AuthorizeApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,18 @@ import {
DataInstance
} from '@janeirodigital/sai-api-messages';
import { reactive, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useCoreStore } from '@/store/core';
import { useAppStore } from '@/store/app';
const router = useRouter()
const coreStore = useCoreStore();
const appStore = useAppStore();
const props = defineProps<{
application: Partial<Application>;
authorizationData: AuthorizationData;
redirect: Boolean
}>();
type PropagatingScope = 'none' | 'all';
Expand Down Expand Up @@ -567,7 +570,13 @@ function authorize(granted = true) {
watch(
() => appStore.accessAuthorization,
(accessAuthorization) => {
if (accessAuthorization) window.location.href = accessAuthorization.callbackEndpoint;
if (accessAuthorization) {
if(props.redirect) {
window.location.href = accessAuthorization.callbackEndpoint;
} else {
router.push( { name: 'application-list' })
}
}
}
);
</script>
15 changes: 8 additions & 7 deletions ui/authorization/src/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ export const useAppStore = defineStore('app', () => {
loadedDataInstances[registrationId] = [...dataInstances];
}

async function listApplications(force = false) {
if (!applicationList.length || force) {
const applications = await backend.listApplications();
applicationList.push(...applications);
}
}

async function authorizeApp(authorization: Authorization) {
accessAuthorization.value = await backend.authorizeApp(authorization);
listApplications(true);
}

async function listSocialAgents() {
Expand All @@ -59,13 +67,6 @@ export const useAppStore = defineStore('app', () => {
application.value = await backend.getApplication(applicationId);
}

async function listApplications() {
if (!applicationList.length) {
const applications = await backend.listApplications();
applicationList.push(...applications);
}
}

async function listDataRegistries(agentId: string, lang = 'en') {
if (!dataRegistryList.length) {
const dataRegistries = await backend.listDataRegistires(agentId, lang);
Expand Down
78 changes: 73 additions & 5 deletions ui/authorization/src/views/ApplicationList.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,82 @@
<style>
#add-button {
display: block;
margin: 16px auto 0;
}
</style>
<template>
<v-list>
<v-list-item v-for="application in appStore.applicationList" :key="application.id" :prepend-avatar="application.logo" :title="application.name">
</v-list-item>
</v-list>
<v-container>
<v-list>
<v-list-item
v-for="application in appStore.applicationList"
:key="application.id" :prepend-avatar="application.logo"
:title="application.name">
</v-list-item>
</v-list>
<v-btn
id="add-button"
color="primary"
@click="addDialog = true"
>
<v-icon icon="mdi-plus"></v-icon>Add application
</v-btn>
<v-dialog
persistent
fullscreen
width="100vw"
v-model="addDialog"
>
<v-card>
<v-card-title>
Add application
</v-card-title>
<v-card-text>
<v-text-field
v-model="addClientId"
label="Client Id"
></v-text-field>
</v-card-text>
<v-card-actions>
<v-btn
color="warning"
variant="tonal"
@click="addDialog = false"
>
Cancel
</v-btn>
<v-spacer></v-spacer>
<v-btn
color="primary"
:disabled="!addClientId"
@click="addApplication"
>
Next
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-container>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { useAppStore } from '@/store/app';
import { useRouter } from 'vue-router';
const router = useRouter()
const appStore = useAppStore()
appStore.listApplications()
</script>
const addDialog = ref(false)
const addClientId = ref('')
// http://localhost:3000/acme/projectron/vue
function addApplication() {
addDialog.value = false
if (addClientId.value) {
router.push({ name: 'authorization', query: { client_id: addClientId.value, redirect: 'false' }})
}
}
</script>
2 changes: 2 additions & 0 deletions ui/authorization/src/views/Authorization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
v-if="!route.query.resource && appStore.authorizationData && appStore.application"
:application="appStore.application"
:authorizationData="appStore.authorizationData"
:redirect="route.query.redirect !== 'false'"
></AuthorizeApp>
<AuthorizeAgent v-if="!route.query.resource && agent" :agent="agent"></AuthorizeAgent>
<ShareResource
Expand Down Expand Up @@ -33,6 +34,7 @@ const resourceId = ref<string | undefined>();
watch(
() => [route.query.client_id, route.query.resource],
([client_id, resource]) => {
if (route.name !== 'authorization') return
if (route.query.webid) return;
if (!client_id || Array.isArray(client_id)) throw new Error('one client_id is required');
clientId.value = client_id;
Expand Down

0 comments on commit ad39c40

Please sign in to comment.