@@ -779,8 +779,8 @@ async function buildPublicCredentialGroupEnrollment(
779779 }
780780}
781781
782- /** Finalizes an enrollment only after every active credential option has one usable connection . */
783- export async function completeCredentialGroupEnrollment ( token : string ) : Promise < boolean | null > {
782+ /** Finalizes an enrollment after the recipient finishes their optional account selections . */
783+ export async function completeCredentialGroupEnrollment ( token : string ) : Promise < true | null > {
784784 const row = await resolvePublicEnrollmentRowByIdentity ( {
785785 invitationTokenHash : hashInvitationToken ( token ) ,
786786 } )
@@ -790,7 +790,7 @@ export async function completeCredentialGroupEnrollment(token: string): Promise<
790790
791791export async function completeAuthorizedCredentialGroupEnrollment (
792792 identity : PublicCredentialGroupEnrollmentIdentity
793- ) : Promise < boolean | null > {
793+ ) : Promise < true | null > {
794794 const row = await resolveAuthorizedPublicEnrollmentRow ( identity )
795795 if ( ! row ) return null
796796 return completeResolvedCredentialGroupEnrollment ( row , identity )
@@ -799,7 +799,7 @@ export async function completeAuthorizedCredentialGroupEnrollment(
799799async function completeResolvedCredentialGroupEnrollment (
800800 row : NonNullable < Awaited < ReturnType < typeof resolvePublicEnrollmentRowByIdentity > > > ,
801801 identity : PublicCredentialGroupEnrollmentIdentity
802- ) : Promise < boolean | null > {
802+ ) : Promise < true | null > {
803803 return db . transaction ( async ( tx ) => {
804804 await lockCredentialGroupEnrollmentLifecycle ( tx , row . enrollment . id )
805805 const now = new Date ( )
@@ -825,7 +825,6 @@ async function completeResolvedCredentialGroupEnrollment(
825825 const [ group ] = await tx
826826 . select ( {
827827 status : credentialGroup . status ,
828- options : credentialGroup . options ,
829828 } )
830829 . from ( credentialGroup )
831830 . where (
@@ -838,52 +837,6 @@ async function completeResolvedCredentialGroupEnrollment(
838837 . for ( 'update' )
839838 if ( ! group || group . status !== 'active' ) return null
840839
841- const activeOptions = group . options . filter ( ( option ) => option . status === 'active' )
842- if ( activeOptions . length === 0 ) return false
843- const connections = await tx
844- . select ( {
845- optionId : credential . credentialGroupOptionId ,
846- status : credential . managedOauthStatus ,
847- scopeVersion : credential . managedOauthScopeVersion ,
848- authorizationAppId : credential . authorizationAppId ,
849- grantedScopes : credential . grantedScopes ,
850- grantedAt : credential . grantedAt ,
851- } )
852- . from ( credential )
853- . where (
854- and (
855- eq ( credential . type , 'managed_oauth' ) ,
856- eq ( credential . credentialGroupEnrollmentId , row . enrollment . id )
857- )
858- )
859- . for ( 'update' )
860-
861- for ( const option of activeOptions ) {
862- if ( ! isCredentialGroupProvider ( option . provider ) ) {
863- throw new Error ( `Unsupported Credential Group provider: ${ option . provider } ` )
864- }
865- const matchingConnections = connections . filter (
866- ( connection ) => connection . optionId === option . id
867- )
868- if ( matchingConnections . length !== 1 ) return false
869- const [ connection ] = matchingConnections
870- if ( ! connection || connection . status !== 'active' || ! connection . grantedAt ) return false
871-
872- const adapter = getCredentialGroupProviderAdapter ( option . provider )
873- const policy = await adapter . getPolicy ( option , {
874- workspaceId : identity . workspaceId ,
875- credentialGroupId : identity . credentialGroupId ,
876- executor : tx ,
877- } )
878- if (
879- connection . authorizationAppId !== policy . authorizationAppId ||
880- connection . scopeVersion !== policy . scopeVersion ||
881- ! adapter . hasRequiredScopes ( connection . grantedScopes ?? [ ] , policy . requiredScopes )
882- ) {
883- return false
884- }
885- }
886-
887840 const [ completed ] = await tx
888841 . update ( credentialGroupEnrollment )
889842 . set ( { status : 'completed' , completedAt : now , updatedAt : now } )
0 commit comments