ArchiSteamFarm/IPC/Controllers/Api/TwoFactorAuthenticationController.cs
/// <summary>
///     Handles 2FA confirmations of given bots, requires ASF 2FA module to be active on them.
/// </summary>
Handles 2FA confirmations of given bots, requires ASF 2FA module to be active on them.
Handles 2FA confirmations of given bots requires ASF 2FA module to be active on them .
[Consumes("application/json")]
	[HttpPost("Confirmations")]
	[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, GenericResponse<IReadOnlyCollection<Confirmation>>>>), (int) HttpStatusCode.OK)]
	[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
	public async Task<ActionResult<GenericResponse>> ConfirmationsPost(string botNames, [FromBody] TwoFactorAuthenticationConfirmationsRequest request) {
		if (string.IsNullOrEmpty(botNames)) {
			throw new ArgumentNullException(nameof(botNames));
		}
		ArgumentNullException.ThrowIfNull(request);
		if (request.AcceptedType.HasValue && ((request.AcceptedType.Value == Confirmation.EType.Unknown) || !Enum.IsDefined(typeof(Confirmation.EType), request.AcceptedType.Value))) {
			return BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.AcceptedType))));
		}
		HashSet<Bot>? bots = Bot.GetBots(botNames);
		if ((bots == null) || (bots.Count == 0)) {
			return BadRequest(new GenericResponse<IReadOnlyDictionary<string, GenericResponse<IReadOnlyCollection<Confirmation>>>>(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
		}
		IList<(bool Success, IReadOnlyCollection<Confirmation>? HandledConfirmations, string Message)> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.HandleTwoFactorAuthenticationConfirmations(request.Accept, request.AcceptedType, request.AcceptedCreatorIDs.Count > 0 ? request.AcceptedCreatorIDs : null, request.WaitIfNeeded))).ConfigureAwait(false);
		Dictionary<string, GenericResponse<IReadOnlyCollection<Confirmation>>> result = new(bots.Count, Bot.BotsComparer);
		foreach (Bot bot in bots) {
			(bool success, IReadOnlyCollection<Confirmation>? handledConfirmations, string message) = results[result.Count];
			result[bot.BotName] = new GenericResponse<IReadOnlyCollection<Confirmation>>(success, message, handledConfirmations);
		}
		return Ok(new GenericResponse<IReadOnlyDictionary<string, GenericResponse<IReadOnlyCollection<Confirmation>>>>(result));
	}
[ Consumes ( " " ) ] [ HttpPost ( " " ) ] [ ProducesResponseType ( typeof ( GenericResponse < IReadOnlyDictionary < string , GenericResponse < IReadOnlyCollection < Confirmation > > > > ) , ( int ) HttpStatusCode . OK ) ] [ ProducesResponseType ( typeof ( GenericResponse ) , ( int ) HttpStatusCode . BadRequest ) ] public async Task < ActionResult < GenericResponse > > ConfirmationsPost ( string botNames , [ FromBody ] TwoFactorAuthenticationConfirmationsRequest request ) { if ( string . IsNullOrEmpty ( botNames ) ) { throw new ArgumentNullException ( nameof ( botNames ) ) ; } ArgumentNullException . ThrowIfNull ( request ) ; if ( request . AcceptedType . HasValue && ( ( request . AcceptedType . Value == Confirmation . EType . Unknown ) || ! Enum . IsDefined ( typeof ( Confirmation . EType ) , request . AcceptedType . Value ) ) ) { return BadRequest ( new GenericResponse ( false , string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsInvalid , nameof ( request . AcceptedType ) ) ) ) ; } HashSet < Bot > ? bots = Bot . GetBots ( botNames ) ; if ( ( bots == null ) || ( bots . Count == 0 ) ) { return BadRequest ( new GenericResponse < IReadOnlyDictionary < string , GenericResponse < IReadOnlyCollection < Confirmation > > > > ( false , string . Format ( CultureInfo . CurrentCulture , Strings . BotNotFound , botNames ) ) ) ; } IList < ( bool Success , IReadOnlyCollection < Confirmation > ? HandledConfirmations , string Message ) > results = await Utilities . InParallel ( bots . Select ( bot => bot . Actions . HandleTwoFactorAuthenticationConfirmations ( request . Accept , request . AcceptedType , request . AcceptedCreatorIDs . Count > 0 ? request . AcceptedCreatorIDs : null , request . WaitIfNeeded ) ) ) . ConfigureAwait ( false ) ; Dictionary < string , GenericResponse < IReadOnlyCollection < Confirmation > > > result = new ( bots . Count , Bot . BotsComparer ) ; foreach ( Bot bot in bots ) { ( bool success , IReadOnlyCollection < Confirmation > ? handledConfirmations , string message ) = results [ result . Count ] ; result [ bot . BotName ] = new GenericResponse < IReadOnlyCollection < Confirmation > > ( success , message , handledConfirmations ) ; } return Ok ( new GenericResponse < IReadOnlyDictionary < string , GenericResponse < IReadOnlyCollection < Confirmation > > > > ( result ) ) ; }
Handles 2FA confirmations of given bots, requires ASF 2FA module to be active on them.
Handles 2FA confirmations of given bots requires ASF 2FA module to be active on them .
botNames
string
TwoFactorAuthenticationConfirmationsRequest
[FromBody]