diff --git a/CommandLine/XblPlayerDataReset/Program.cs b/CommandLine/XblPlayerDataReset/Program.cs index ace830a..5cfd873 100644 --- a/CommandLine/XblPlayerDataReset/Program.cs +++ b/CommandLine/XblPlayerDataReset/Program.cs @@ -164,7 +164,7 @@ private static async Task OnReset(ResetOptions options) // Sign into each account individually foreach (string testAccountName in testAccountNames) { - TestAccount ta = await ToolAuthentication.SignInTestAccountAsync(testAccountName, options.Sandbox); + TestAccount ta = await ToolAuthentication.SignInTestAccountAsync(testAccountName, options.Sandbox, options.Silent); // If we have a failure, output the account and stop the process if (ta == null) @@ -303,6 +303,10 @@ internal class ResetOptions HelpText = "Delimiter that separates accounts to reset. Defaults to \",\".")] public string Delimiter { get; set; } + [Option('i', "silent", Required = false, + HelpText = "Connect to the account using cached credentials. May still open UI if authentification is necessary.")] + public bool Silent { get; set; } + [Usage(ApplicationAlias = "XblPlayerDataReset")] public static IEnumerable Examples { diff --git a/Microsoft.Xbox.Service.DevTools/Authentication/AuthClient.cs b/Microsoft.Xbox.Service.DevTools/Authentication/AuthClient.cs index f0cb515..fe1cc02 100644 --- a/Microsoft.Xbox.Service.DevTools/Authentication/AuthClient.cs +++ b/Microsoft.Xbox.Service.DevTools/Authentication/AuthClient.cs @@ -9,6 +9,7 @@ namespace Microsoft.Xbox.Services.DevTools.Authentication using System.Net.Http; using System.Threading.Tasks; using DevTools.Common; + using Microsoft.Identity.Client; using Newtonsoft.Json; internal class AuthClient @@ -111,7 +112,7 @@ public async Task SignInAsync(string tenant) return account; } - public async Task SignInTestAccountAsync(string sandbox) + public async Task SignInTestAccountAsync(string sandbox, bool tryCached) { if (this.AuthContext == null) { @@ -128,7 +129,23 @@ public async Task SignInTestAccountAsync(string sandbox) throw new InvalidOperationException("To log in a Partner Center account, call the SignInAsync method"); } - string msaToken = await this.AuthContext.AcquireTokenAsync(); + string msaToken; + if (!tryCached) + { + msaToken = await this.AuthContext.AcquireTokenAsync(); + } + else + { + try + { + msaToken = await this.AuthContext.AcquireTokenSilentAsync(); + } + catch (MsalUiRequiredException) + { + msaToken = await this.AuthContext.AcquireTokenAsync(); + } + } + XasTokenResponse token = await this.FetchXstsToken(msaToken, sandbox); var account = new TestAccount(token); diff --git a/Microsoft.Xbox.Service.DevTools/Authentication/ToolAuthentication.cs b/Microsoft.Xbox.Service.DevTools/Authentication/ToolAuthentication.cs index 8b571a3..a0f73b7 100644 --- a/Microsoft.Xbox.Service.DevTools/Authentication/ToolAuthentication.cs +++ b/Microsoft.Xbox.Service.DevTools/Authentication/ToolAuthentication.cs @@ -129,12 +129,14 @@ internal static async Task SignInAsync(DevAccountSource accountSourc /// Attempt to sign in a test account, UI will be triggered if necessary /// /// The user name of the account, optional. + /// The target sandbox for the XToken + /// Try authentifying using cached credential first /// TestAccount object contains test account info. - public static async Task SignInTestAccountAsync(string userName, string sandbox) + public static async Task SignInTestAccountAsync(string userName, string sandbox, bool tryCached) { SetAuthInfo(DevAccountSource.TestAccount, userName, "consumers"); - TestAccount testAccount = await Client.SignInTestAccountAsync(sandbox); + TestAccount testAccount = await Client.SignInTestAccountAsync(sandbox, tryCached); return testAccount; }