Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -86,9 +86,6 @@ public string? Domain1
/// Is authenticated with Azure AD B2C (set by reflection).
/// </summary>
public bool IsB2C { get; set; }


// TODO: propose a fix for the blazorwasm project template

/// <summary>
/// Sign-up/sign-in policy in the case of B2C.
Expand Down Expand Up @@ -157,7 +154,7 @@ public string? Domain1
/// <summary>
/// Identifier URIs for web APIs.
/// </summary>
public string? AppIdUri { set; get; }
public string? AppIdUri { get; set; }

/// <summary>
/// API permissions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"Identifier": "dotnet-blazorwasm-client",
"Files": [
{
"FileName": "Program.cs",
"Options": [
"MinimalApp"
],
"Methods": {
"Global": {
"CodeChanges": [
{
"MultiLineBlock": [
"{",
" builder.Configuration.Bind(\"AzureAd\", options.ProviderOptions.Authentication);",
" options.ProviderOptions.DefaultAccessTokenScopes.Add(builder.Configuration[\"ServerApi\"]);",
"}"
],
"Replace": true,
"CodeChangeType": "Lambda",
"Parameter": "options",
"Parent": "builder.Services.AddMsalAuthentication",
"TrailingTrivia": {
"Semicolon": false
}
}
]
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task AddAuthCodeAsync()
CodeModifierConfig? codeModifierConfig = ReadCodeModifierConfigFromFileContent(content);
if (codeModifierConfig is null)
{
throw new FormatException($"Resource file { CodeModifierConfigPropertyInfo.Name } could not be parsed. ");
throw new FormatException($"Resource file {CodeModifierConfigPropertyInfo.Name} could not be parsed. ");
}

if (!string.Equals(codeModifierConfig.Identifier, _toolOptions.ProjectTypeIdentifier, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -133,7 +133,7 @@ private PropertyInfo? CodeModifierConfigPropertyInfo
}
catch (Exception e)
{
_consoleLogger.LogMessage($"Error parsing Code Modifier Config for project type { _toolOptions.ProjectType }, exception: { e.Message }");
_consoleLogger.LogMessage($"Error parsing Code Modifier Config for project type {_toolOptions.ProjectType}, exception: {e.Message}");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ public void ModifyAppSettings(ApplicationParameters applicationParameters, IEnum
* };
*/

_provisioningToolOptions.AppSettingsFilePath = GetAppSettingsFilePath(files);
if (!File.Exists(_provisioningToolOptions.AppSettingsFilePath))
{
// If default appsettings file does not exist, try to find it, if not found, create in the default location
var defaultAppSettingsPath = DefaultAppSettingsPath;
_provisioningToolOptions.AppSettingsFilePath = File.Exists(defaultAppSettingsPath) ? defaultAppSettingsPath
: files.FirstOrDefault(f => f.Contains(AppSettingsFileName)) ?? defaultAppSettingsPath;
}

JObject appSettings;
try
Expand All @@ -62,26 +68,9 @@ public void ModifyAppSettings(ApplicationParameters applicationParameters, IEnum
}
}

/// <summary>
/// First checks if default appsettings file exists, if not searches for the file.
/// If the file does not exist anywhere, it will be created later.
/// </summary>
private string GetAppSettingsFilePath(IEnumerable<string> files)
{
if (!File.Exists(_provisioningToolOptions.AppSettingsFilePath))
{
// If default appsettings file does not exist, try to find it, if not found, create in the default location
_provisioningToolOptions.AppSettingsFilePath = File.Exists(DefaultAppSettingsPath)
? DefaultAppSettingsPath
: files.Where(f => f.Contains(AppSettingsFileName)).FirstOrDefault();
}

return _provisioningToolOptions.AppSettingsFilePath ??= DefaultAppSettingsPath;
}

private string DefaultAppSettingsPath => _provisioningToolOptions.IsBlazorWasm
? Path.Combine(_provisioningToolOptions.ProjectPath, "wwwroot", AppSettingsFileName)
: Path.Combine(_provisioningToolOptions.ProjectPath, AppSettingsFileName);
? Path.Combine(_provisioningToolOptions.ProjectPath, "wwwroot", AppSettingsFileName)
: Path.Combine(_provisioningToolOptions.ProjectPath, AppSettingsFileName);

/// <summary>
/// Modifies AppSettings.json if necessary, helper method for testing
Expand All @@ -101,7 +90,7 @@ private string GetAppSettingsFilePath(IEnumerable<string> files)
appSettings["AzureAd"] = updatedAzureAdBlock;
}

if (_provisioningToolOptions.CallsGraph) // TODO blazor
if (_provisioningToolOptions.CallsGraph)
{
// update MicrosoftGraph Block
var microsoftGraphBlock = GetModifiedMicrosoftGraphBlock(appSettings);
Expand All @@ -112,7 +101,7 @@ private string GetAppSettingsFilePath(IEnumerable<string> files)
}
}

if (_provisioningToolOptions.CallsDownstreamApi) // TODO blazor
if (_provisioningToolOptions.CallsDownstreamApi)
{
// update DownstreamAPI Block
var updatedDownstreamApiBlock = GetModifiedDownstreamApiBlock(appSettings);
Expand All @@ -123,6 +112,13 @@ private string GetAppSettingsFilePath(IEnumerable<string> files)
}
}

if (!string.IsNullOrEmpty(_provisioningToolOptions.HostedApiScopes))
{
// update ServerAPI Block
changesMade = true;
appSettings["ServerApi"] = _provisioningToolOptions.HostedApiScopes;
}

return changesMade ? appSettings : null;
}

Expand Down
Loading