@@ -2768,7 +2768,7 @@ async function handleGetAuthorisationSession(
27682768 sessionIdFromPath : string ,
27692769) : Promise < Response > {
27702770 const sessionId = validateAuthorisationSessionId ( sessionIdFromPath ) ;
2771- const session = await requireLiveAuthorisationSession ( store , sessionId , now ) ;
2771+ const session = await requireReadableAuthorisationSession ( store , sessionId , now ) ;
27722772 const authorization = request . headers . get ( "authorization" ) ;
27732773 const token = authorization ?. startsWith ( "Bearer " ) ? authorization . slice ( "Bearer " . length ) . trim ( ) : "" ;
27742774 if ( ! token ) throw new ApiError ( 401 , "authorisation_session_token_required" , "authorisation session bearer token is required" ) ;
@@ -2804,8 +2804,11 @@ async function handlePrepareAuthorisationSession(
28042804) : Promise < Response > {
28052805 await throttleRequestSource ( store , request , requestId , "authorisation_session_challenge" , 60 , 60 , now ) ;
28062806 const sessionId = validateAuthorisationSessionId ( sessionIdFromPath ) ;
2807- const session = await requireLiveAuthorisationSession ( store , sessionId , now ) ;
2807+ const session = await requireReadableAuthorisationSession ( store , sessionId , now ) ;
28082808 await requireAuthorisationBrowserToken ( request , session . browser_token_hash ) ;
2809+ if ( session . status !== "pending" ) {
2810+ throw new ApiError ( 409 , "authorisation_session_complete" , "authorisation session has already completed" ) ;
2811+ }
28092812 if ( session . registry_origin !== registryOrigin ) {
28102813 throw new ApiError ( 409 , "authorisation_session_origin_mismatch" , "authorisation session belongs to another Registry origin" ) ;
28112814 }
@@ -2857,7 +2860,7 @@ async function handleCompleteAuthorisationSession(
28572860) : Promise < Response > {
28582861 await throttleRequestSource ( store , request , requestId , "authorisation_session_complete" , 40 , 60 , now ) ;
28592862 const sessionId = validateAuthorisationSessionId ( sessionIdFromPath ) ;
2860- const session = await requireLiveAuthorisationSession ( store , sessionId , now ) ;
2863+ const session = await requireReadableAuthorisationSession ( store , sessionId , now ) ;
28612864 await requireAuthorisationBrowserToken ( request , session . browser_token_hash ) ;
28622865 if ( session . status !== "pending" ) {
28632866 return json ( {
@@ -2928,10 +2931,10 @@ function validateAuthorisationSessionId(value: string): string {
29282931 return sessionId ;
29292932}
29302933
2931- async function requireLiveAuthorisationSession ( store : RegistryStore , sessionId : string , now : Date ) {
2934+ async function requireReadableAuthorisationSession ( store : RegistryStore , sessionId : string , now : Date ) {
29322935 const session = await store . getAuthorisationSession ( sessionId ) ;
29332936 if ( ! session ) throw new ApiError ( 404 , "authorisation_session_not_found" , "authorisation session was not found" ) ;
2934- if ( Date . parse ( session . expires_at ) <= now . getTime ( ) ) {
2937+ if ( session . status === "pending" && Date . parse ( session . expires_at ) <= now . getTime ( ) ) {
29352938 throw new ApiError ( 410 , "authorisation_session_expired" , "authorisation session has expired; start again from cellc" ) ;
29362939 }
29372940 return session ;
0 commit comments