ArchiSteamFarm/IPC/Controllers/Api/TwoFactorAuthenticationController.cs
/// <summary>
///     Imports a MobileAuthenticator into the ASF 2FA module of a given bot.
/// </summary>
Imports a MobileAuthenticator into the ASF 2FA module of a given bot.
Imports a MobileAuthenticator into the ASF 2FA module of a given bot .
[Consumes("application/json")]
	[HttpPost]
	[ProducesResponseType(typeof(GenericResponse<IReadOnlyDictionary<string, GenericResponse>>), (int) HttpStatusCode.OK)]
	[ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
	public async Task<ActionResult<GenericResponse>> Post(string botNames, [FromBody] MobileAuthenticator authenticator) {
		if (string.IsNullOrEmpty(botNames)) {
			throw new ArgumentNullException(nameof(botNames));
		}
		ArgumentNullException.ThrowIfNull(authenticator);
		HashSet<Bot>? bots = Bot.GetBots(botNames);
		if ((bots == null) || (bots.Count == 0)) {
			return BadRequest(new GenericResponse<IReadOnlyDictionary<string, GenericResponse<string>>>(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botNames)));
		}
		IList<bool> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.TryImportAuthenticator(authenticator)))).ConfigureAwait(false);
		Dictionary<string, GenericResponse> result = new(bots.Count, Bot.BotsComparer);
		foreach (Bot bot in bots) {
			bool success = results[result.Count];
			result[bot.BotName] = new GenericResponse(success);
		}
		return Ok(new GenericResponse<IReadOnlyDictionary<string, GenericResponse>>(result));
	}
[ Consumes ( " " ) ] [ HttpPost ] [ ProducesResponseType ( typeof ( GenericResponse < IReadOnlyDictionary < string , GenericResponse > > ) , ( int ) HttpStatusCode . OK ) ] [ ProducesResponseType ( typeof ( GenericResponse ) , ( int ) HttpStatusCode . BadRequest ) ] public async Task < ActionResult < GenericResponse > > Post ( string botNames , [ FromBody ] MobileAuthenticator authenticator ) { if ( string . IsNullOrEmpty ( botNames ) ) { throw new ArgumentNullException ( nameof ( botNames ) ) ; } ArgumentNullException . ThrowIfNull ( authenticator ) ; HashSet < Bot > ? bots = Bot . GetBots ( botNames ) ; if ( ( bots == null ) || ( bots . Count == 0 ) ) { return BadRequest ( new GenericResponse < IReadOnlyDictionary < string , GenericResponse < string > > > ( false , string . Format ( CultureInfo . CurrentCulture , Strings . BotNotFound , botNames ) ) ) ; } IList < bool > results = await Utilities . InParallel ( bots . Select ( bot => Task . Run ( ( ) => bot . TryImportAuthenticator ( authenticator ) ) ) ) . ConfigureAwait ( false ) ; Dictionary < string , GenericResponse > result = new ( bots . Count , Bot . BotsComparer ) ; foreach ( Bot bot in bots ) { bool success = results [ result . Count ] ; result [ bot . BotName ] = new GenericResponse ( success ) ; } return Ok ( new GenericResponse < IReadOnlyDictionary < string , GenericResponse > > ( result ) ) ; }
Imports a MobileAuthenticator into the ASF 2FA module of a given bot.
Imports a MobileAuthenticator into the ASF 2FA module of a given bot .
botNames
string
MobileAuthenticator
[FromBody]