Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public async Task AddAuthCodeAsync()
if (csProjFiles.Count() != 1)
{
var errorMsg = string.Format(Resources.ProjectPathError, _toolOptions.ProjectFilePath);
_consoleLogger.LogFailure(errorMsg, Commands.UPDATE_PROJECT_COMMAND);
return;
_consoleLogger.LogFailureAndExit(errorMsg);
}

_toolOptions.ProjectFilePath = csProjFiles.First();
Expand Down Expand Up @@ -89,7 +88,7 @@ public async Task AddAuthCodeAsync()
await HandleCodeFileAsync(file, project, options, codeModifierConfig.Identifier);
}

_consoleLogger.LogJsonMessage(new JsonResponse(Commands.UPDATE_PROJECT_COMMAND, State.Success, output: _output.ToString().TrimEnd()));
_consoleLogger.LogJsonMessage(State.Success, output: _output.ToString().TrimEnd());
}

internal static string GetCodeFileString(CodeFile file, string identifier) // todo make all code files strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Microsoft.DotNet.MSIdentity.Properties;
using Microsoft.DotNet.MSIdentity.Shared;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensions.Msal;
Expand Down Expand Up @@ -105,7 +106,7 @@ public override async ValueTask<AccessToken> GetTokenAsync(TokenRequestContext r
{
if (account == null && !string.IsNullOrEmpty(Username))
{
_consoleLogger.LogFailure(
_consoleLogger.LogFailureAndExit(
$"No valid tokens found in the cache.\n" +
$"Please sign-in to Visual Studio with this account: {Username}.\n\n" +
$"After signing-in, re-run the tool.");
Expand All @@ -118,24 +119,30 @@ public override async ValueTask<AccessToken> GetTokenAsync(TokenRequestContext r
}
catch (MsalServiceException ex)
{
// AAD error codes: https://learn.microsoft.com/en-us/azure/active-directory/develop/reference-aadsts-error-codes
if (ex.Message.Contains("AADSTS70002")) // "The client does not exist or is not enabled for consumers"
{
_consoleLogger.LogFailure(
// We want to exit here because this is probably an MSA without an AAD tenant.
_consoleLogger.LogFailureAndExit(
"An Azure AD tenant, and a user in that tenant, " +
"needs to be created for this account before an application can be created. " +
"See https://aka.ms/ms-identity-app/create-a-tenant. ");
Environment.Exit(1); // we want to exit here because this is probably an MSA without an AAD tenant.
}

_consoleLogger.LogFailure($"Error encountered with sign-in. See error message for details:\n{ex.Message}");
Environment.Exit(1); // we want to exit here. Re-sign in will not resolve the issue.
// we want to exit here. Re-sign in will not resolve the issue.
_consoleLogger.LogFailureAndExit(string.Join(Environment.NewLine, Resources.SignInError, ex.Message));
}
catch (Exception ex)
{
_consoleLogger.LogFailure($"Error encountered with sign-in. See error message for details:\n{ex.Message}");
Environment.Exit(1);
_consoleLogger.LogFailureAndExit(string.Join(Environment.NewLine, Resources.SignInError, ex.Message));
}
return new AccessToken(result.AccessToken, result.ExpiresOn);

if (result is null)
{
_consoleLogger.LogFailureAndExit(Resources.FailedToAcquireToken);
}

return new AccessToken(result!.AccessToken, result.ExpiresOn);
}
}
}

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@
<data name="FailedClientSecretWithApp" xml:space="preserve">
<value>Failed to add client secret for Azure AD app : {0}({1})</value>
</data>
<data name="FailedToAcquireToken" xml:space="preserve">
<value>Failed to acquire a token.</value>
</data>
<data name="FailedToCreateApp" xml:space="preserve">
<value>Failed to create Azure AD/AD B2C app registration.</value>
</data>
Expand All @@ -251,11 +254,14 @@
<comment>0 = File name, 1 = Exception message</comment>
</data>
<data name="FailedToProvisionClientApp" xml:space="preserve">
<value>Failed to provision Client Application</value>
<value>Failed to provision Client Application for Blazor WASM hosted project</value>
</data>
<data name="FailedToRetrieveADObjectsError" xml:space="preserve">
<value>Failed to retrieve all Azure AD/AD B2C objects(apps/service principals</value>
</data>
<data name="FailedToRetrieveApplicationParameters" xml:space="preserve">
<value>Failed to retrieve application parameters.</value>
</data>
<data name="FailedToUpdateApp" xml:space="preserve">
<value>Failed to update Azure AD app registration {0} ({1})</value>
<comment>0 = Display Name, 1 = App Id</comment>
Expand All @@ -265,7 +271,7 @@
<comment>0 = null object</comment>
</data>
<data name="FailedToUpdateClientAppCode" xml:space="preserve">
<value>Failed to update client app program.cs file</value>
<value>Failed to update client app program.cs file for Blazor WASM hosted project</value>
</data>
<data name="InitializeUserSecrets" xml:space="preserve">
<value>Initializing User Secrets . . .</value>
Expand Down Expand Up @@ -307,6 +313,9 @@
<value>Resource file {0} could not be parsed.</value>
<comment>0 = CodeModifierConfigPropertyInfo.Name</comment>
</data>
<data name="SignInError" xml:space="preserve">
<value>Error encountered with sign-in. See error message for details:</value>
</data>
<data name="Success" xml:space="preserve">
<value>SUCCESS</value>
</data>
Expand Down
Loading