mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
react to case, if both communities try to authenticate each other at the same time
This commit is contained in:
parent
6293eff1de
commit
c8eeac2c02
@ -6,14 +6,17 @@ import { Ed25519PublicKey } from 'shared'
|
||||
* Find a pending community handshake by public key.
|
||||
* @param publicKey The public key of the community.
|
||||
* @param apiVersion The API version of the community.
|
||||
* @param status The status of the community handshake. Optional, if not set, it will find a pending community handshake.
|
||||
* @returns The CommunityHandshakeState with associated federated community and community.
|
||||
*/
|
||||
export function findPendingCommunityHandshake(publicKey: Ed25519PublicKey, apiVersion: string): Promise<CommunityHandshakeState | null> {
|
||||
export function findPendingCommunityHandshake(
|
||||
publicKey: Ed25519PublicKey, apiVersion: string, status?: CommunityHandshakeStateType
|
||||
): Promise<CommunityHandshakeState | null> {
|
||||
return CommunityHandshakeState.findOne({
|
||||
where: {
|
||||
publicKey: publicKey.asBuffer(),
|
||||
apiVersion,
|
||||
status: Not(In([
|
||||
status: status || Not(In([
|
||||
CommunityHandshakeStateType.EXPIRED,
|
||||
CommunityHandshakeStateType.FAILED,
|
||||
CommunityHandshakeStateType.SUCCESS
|
||||
|
||||
@ -41,7 +41,7 @@ export async function startOpenConnectionCallback(
|
||||
|
||||
let state: DbCommunityHandshakeState | null = null
|
||||
try {
|
||||
const pendingState = await findPendingCommunityHandshake(publicKey, api)
|
||||
const pendingState = await findPendingCommunityHandshake(publicKey, api, CommunityHandshakeStateType.START_OPEN_CONNECTION_CALLBACK)
|
||||
if (pendingState) {
|
||||
const stateLogic = new CommunityHandshakeStateLogic(pendingState)
|
||||
// retry on timeout or failure
|
||||
@ -134,15 +134,12 @@ export async function startAuthentication(
|
||||
if (!comB.publicJwtKey) {
|
||||
throw new Error('Public JWT key still not exist for foreign community')
|
||||
}
|
||||
state = await findPendingCommunityHandshake(fedComBPublicKey, fedComB.apiVersion)
|
||||
state = await findPendingCommunityHandshake(fedComBPublicKey, fedComB.apiVersion, CommunityHandshakeStateType.START_COMMUNITY_AUTHENTICATION)
|
||||
if (!state) {
|
||||
throw new Error('No pending community handshake found')
|
||||
}
|
||||
const stateLogic = new CommunityHandshakeStateLogic(state)
|
||||
if (
|
||||
(await stateLogic.isTimeoutUpdate()) ||
|
||||
state.status !== CommunityHandshakeStateType.START_COMMUNITY_AUTHENTICATION
|
||||
) {
|
||||
if ((await stateLogic.isTimeoutUpdate())) {
|
||||
methodLogger.debug('invalid state', new CommunityHandshakeStateLoggingView(state))
|
||||
throw new Error('No valid pending community handshake found')
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user