Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CommandLine/XblPlayerDataReset/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private static async Task<int> 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)
Expand Down Expand Up @@ -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<Example> Examples
{
Expand Down
21 changes: 19 additions & 2 deletions Microsoft.Xbox.Service.DevTools/Authentication/AuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +112,7 @@ public async Task<DevAccount> SignInAsync(string tenant)
return account;
}

public async Task<TestAccount> SignInTestAccountAsync(string sandbox)
public async Task<TestAccount> SignInTestAccountAsync(string sandbox, bool tryCached)
{
if (this.AuthContext == null)
{
Expand All @@ -128,7 +129,23 @@ public async Task<TestAccount> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ internal static async Task<DevAccount> SignInAsync(DevAccountSource accountSourc
/// Attempt to sign in a test account, UI will be triggered if necessary
/// </summary>
/// <param name="userName">The user name of the account, optional.</param>
/// <param name="sandbox">The target sandbox for the XToken</param>
/// <param name="tryCached">Try authentifying using cached credential first</param>
/// <returns>TestAccount object contains test account info.</returns>
public static async Task<TestAccount> SignInTestAccountAsync(string userName, string sandbox)
public static async Task<TestAccount> 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;
}

Expand Down