Skip to content

Commit

Permalink
WIP: Add ORCID OAuth verification to invitation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhanson committed Dec 11, 2024
1 parent 13d984f commit a240366
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 9 deletions.
67 changes: 65 additions & 2 deletions src/pages/acceptInvitation/AcceptInvitationPageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,33 @@ export const useAcceptInvitationPageStore = defineComponentStore(
updateAcceptInvitationPayload('affiliation', data.value.affiliation);
}
updateAcceptInvitationPayload('userCountry', data.value.country);
updateAcceptInvitationPayload('userOrcid', data.value.orcid);

updateAcceptInvitationPayload('orcid', data.value.orcid);
updateAcceptInvitationPayload(
'orcidIsVerified',
data.value.orcidIsVerified,
);
updateAcceptInvitationPayload(
'orcidAccessDenied',
data.value.orcidAccessDenied,
);
updateAcceptInvitationPayload(
'orcidAccessToken',
data.value.orcidAccessToken,
);
updateAcceptInvitationPayload(
'orcidAccessScope',
data.value.orcidAccessScope,
);
updateAcceptInvitationPayload(
'orcidRefreshToken',
data.value.orcidRefreshToken,
);
updateAcceptInvitationPayload(
'orcidAccessExpiresOn',
data.value.orcidAccessExpiresOn,
);

updateAcceptInvitationPayload(
'userGroupsToAdd',
data.value.userGroupsToAdd,
Expand All @@ -110,6 +136,37 @@ export const useAcceptInvitationPageStore = defineComponentStore(
acceptInvitationPayload.value[fieldName] = value;
}

/**
* Sets ORCID data in invitation payload. If data is null, all ORCID related fields will be set to null/zero value.
*
* @param {Object|null} data - The ORCID OAuth data object.
* @param {string} data.orcid - The ORCID URL of the user.
* @param {boolean} data.orcidIsVerified - Indicates if the user's ORCID is verified.
* @param {null|string} data.orcidAccessDenied - Indicates if access to ORCID is denied (null if not denied).
* @param {string} data.orcidAccessToken - The access token for ORCID API.
* @param {string} data.orcidAccessScope - The scope of access for the ORCID API.
* @param {string} data.orcidRefreshToken - The refresh token for obtaining new access tokens.
* @param {string} data.orcidAccessExpiresOn - The expiration date and time of the access token in ISO format.
* @param data
*/
function setOrcidData(data) {
const fields = [
'orcid',
'orcidIsVerified',
'orcidAccessDenied',
'orcidAccessToken',
'orcidAccessScope',
'orcidRefreshToken',
'orcidAccessExpiresOn',
];
const isDataNull = data === null;
fields.forEach((fieldName) => {
acceptInvitationPayload.value[fieldName] = isDataNull
? null
: data[fieldName];
});
}

/** Steps */
const currentStepId = ref(
pageInitConfig.steps[0] ? pageInitConfig.steps[0].id : '',
Expand Down Expand Up @@ -314,7 +371,12 @@ export const useAcceptInvitationPageStore = defineComponentStore(
method: 'PUT',
body: {invitationData: invitationRequestPayload.value},
});
if (!acceptInvitationPayload.value.privacyStatement) {
// FIXME: Privacy statement check blocks ORCID from saving before hand.
// Can this check be moved outside of update payload check?
if (
!acceptInvitationPayload.value.privacyStatement &&
currentStep.value.id !== 'verifyOrcid'
) {
errors.value = {
privacyStatement: [t('acceptInvitation.privacyStatement.validation')],
};
Expand Down Expand Up @@ -431,6 +493,7 @@ export const useAcceptInvitationPageStore = defineComponentStore(
//methods
nextStep,
previousStep,
setOrcidData,
updateAcceptInvitationPayload,
cancel,

Expand Down
35 changes: 28 additions & 7 deletions src/pages/acceptInvitation/AcceptInvitationVerifyOrcid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<script setup>
import PkpButton from '@/components/Button/Button.vue';
import {defineProps} from 'vue';
import {defineProps, onMounted} from 'vue';
import {useLocalize} from '@/composables/useLocalize';
import {useAcceptInvitationPageStore} from './AcceptInvitationPageStore';
Expand All @@ -27,21 +27,42 @@ const props = defineProps({
const store = useAcceptInvitationPageStore();
const {t} = useLocalize();
onMounted(() => {
pkp.eventBus.$on('addOrcidInvitationData', (data) => setOrcidData(data));
});
/**
* Processes ORCID data for an invitation.
*
* @param {Object} data - The ORCID OAuth data object.
* @param {string} data.orcid - The ORCID URL of the user.
* @param {boolean} data.orcidIsVerified - Indicates if the user's ORCID is verified.
* @param {null|string} data.orcidAccessDenied - Indicates if access to ORCID is denied (null if not denied).
* @param {string} data.orcidAccessToken - The access token for ORCID API.
* @param {string} data.orcidAccessScope - The scope of access for the ORCID API.
* @param {string} data.orcidRefreshToken - The refresh token for obtaining new access tokens.
* @param {string} data.orcidAccessExpiresOn - The expiration date and time of the access token in ISO format.
*
* @returns {void}
*/
async function setOrcidData(data) {
store.setOrcidData(data);
await store.nextStep();
}
/**
* Go to the next step
*/
function skipOrcid() {
// TODO: See how this should be handled given updated ORCID fields
// delete store.acceptInvitationPayload.userOrcid;
// delete store.acceptInvitationPayload.orcid;
store.openStep(store.steps[1 + store.currentStepIndex].id);
}
/**
* Initiates ORCID OAuth granting flow
*/
function verifyOrcid() {
openOrcidOAuth();
store.openStep(store.steps[1 + store.currentStepIndex].id);
}
function openOrcidOAuth() {
const oauthWindow = window.open(
props.orcidOAuthUrl,
'_blank',
Expand Down

0 comments on commit a240366

Please sign in to comment.