Skip to content

Commit 8c9dc50

Browse files
Blazor WASM debugging setup
Anti-Forgery error fixed
1 parent 99800d5 commit 8c9dc50

File tree

8 files changed

+16
-20
lines changed

8 files changed

+16
-20
lines changed

Modules/Intent.Modules.Blazor.Authentication/Intent.Blazor.Authentication.imodspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.Blazor.Authentication</id>
4-
<version>1.0.5-pre.0</version>
4+
<version>1.0.5-pre.1</version>
55
<supportedClientVersions>[4.5.0-a,5.0.0)</supportedClientVersions>
66
<summary>Automates Authentication components for a Blazor application</summary>
77
<description>Automates Authentication components for a Blazor application</description>

Modules/Intent.Modules.Blazor.Authentication/Templates/Templates/Server/JwtAuthServiceConcrete/JwtAuthServiceConcreteTemplatePartial.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public JwtAuthServiceConcreteTemplate(IOutputTarget outputTarget, object model =
9191
method.AddParameter("bool", "rememberMe");
9292
method.AddParameter("string", "returnUrl");
9393

94+
95+
method.AddStatement("var httpContext = _httpContextAccessor.HttpContext ?? throw new InvalidOperationException(\"No active HttpContext found.\");");
96+
method.AddStatement("await httpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);", s => s.SeparatedFromNext());
97+
9498
method.AddAssignmentStatement("var tokenResponse", new CSharpStatement("await _httpClient.PostAsJsonAsync(\"/login\", new { Email = username, Password = password });"));
9599

96100
method.AddIfStatement("tokenResponse.IsSuccessStatusCode", @if =>
@@ -107,7 +111,7 @@ public JwtAuthServiceConcreteTemplate(IOutputTarget outputTarget, object model =
107111
};".ConvertToStatements());
108112
@if.AddAssignmentStatement("var claimsIdentity", new CSharpStatement("new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);"));
109113
@if.AddAssignmentStatement("var claimsPrincipal", new CSharpStatement("new ClaimsPrincipal(claimsIdentity);"));
110-
@if.AddStatement("await _httpContextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,claimsPrincipal, new AuthenticationProperties { IsPersistent = rememberMe });");
114+
@if.AddStatement("await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,claimsPrincipal, new AuthenticationProperties { IsPersistent = rememberMe });");
111115
@if.AddStatement("_redirectManager.RedirectTo(returnUrl);");
112116
}).AddElseStatement(@else =>
113117
{

Modules/Intent.Modules.Blazor.Authentication/Templates/Templates/Server/Login/LoginTemplatePartial.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public LoginTemplate(IOutputTarget outputTarget, object model = null) : base(Tem
3939
file.AddPageDirective($"/Account/Login");
4040

4141
file.AddUsing("System.ComponentModel.DataAnnotations");
42+
file.AddUsing("Microsoft.AspNetCore.Mvc");
4243
file.AddUsing("Microsoft.AspNetCore.Authentication");
4344
file.AddInjectDirective(GetTypeName(AuthServiceInterfaceTemplate.TemplateId), "AuthService");
4445
file.AddInjectDirective("Microsoft.AspNetCore.Components.NavigationManager", "NavigationManager");
@@ -126,25 +127,10 @@ public LoginTemplate(IOutputTarget outputTarget, object model = null) : base(Tem
126127
input.AddAttribute("SupplyParameterFromQuery");
127128
});
128129

129-
code.AddMethod("Task", "OnInitializedAsync", onValidSubmitAsync =>
130-
{
131-
onValidSubmitAsync.Protected().Async().Override();
132-
133-
onValidSubmitAsync.AddIfStatement("HttpMethods.IsGet(HttpContext.Request.Method)", @if =>
134-
{
135-
if (ExecutionContext.GetSettings().GetBlazor().Authentication().IsAspnetcoreIdentity())
136-
{
137-
@if.AddStatement($"await HttpContext.SignOutAsync({code.Template.UseType("Microsoft.AspNetCore.Identity.IdentityConstants")}.ExternalScheme);");
138-
}
139-
else
140-
{
141-
@if.AddStatement("await HttpContext.SignOutAsync();");
142-
}
143-
});
144-
});
145130

146131
code.AddMethod("Task", "LoginUser", onValidSubmitAsync =>
147132
{
133+
onValidSubmitAsync.AddAttribute("[IgnoreAntiforgeryToken]");
148134
onValidSubmitAsync.Async();
149135

150136
onValidSubmitAsync.AddStatement("await AuthService.Login(Input.Email, Input.Password, Input.RememberMe, ReturnUrl);");

Modules/Intent.Modules.Blazor.Authentication/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Version 1.0.5
22

3+
- Improvement: Fixed AntiForgery exception when re-logging in.
34
- Improvement: Updated module documentation to use centralized documentation site.
45

56
### Version 1.0.4

Modules/Intent.Modules.Blazor/FactoryExtensions/BlazorAspNetCoreStartupInstaller.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ private static void RegisterStartup(IApplication application)
9393

9494
if (ifDevelopmentStatement is not null)
9595
{
96+
if (startup.ExecutionContext.GetSettings().GetBlazor().RenderMode().IsInteractiveWebAssembly() || startup.ExecutionContext.GetSettings().GetBlazor().RenderMode().IsInteractiveAuto())
97+
{
98+
ifDevelopmentStatement.AddStatement("app.UseWebAssemblyDebugging();");
99+
}
100+
96101
ifDevelopmentStatement.InsertBelow(new CSharpElseStatement(), statement =>
97102
{
98103
var elseStatement = (CSharpElseStatement)statement;

Modules/Intent.Modules.Blazor/Intent.Blazor.imodspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.Blazor</id>
4-
<version>1.0.6-pre.0</version>
4+
<version>1.0.6-pre.1</version>
55
<supportedClientVersions>[4.5.0-a, 5.0.0-a)</supportedClientVersions>
66
<summary>Automates the bootstrapping and core patterns of a Blazor web application.</summary>
77
<description>Automates the bootstrapping and core patterns of a Blazor web application.</description>

Modules/Intent.Modules.Blazor/Templates/Templates/Client/Program/ProgramTemplatePartial.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public ProgramTemplate(IOutputTarget outputTarget, object model = null) : base(T
106106
CommandName = "Project",
107107
LaunchBrowser = true,
108108
ApplicationUrl = $"https://localhost:{x.SslPort};http://localhost:{x.Port}",
109-
PublishAllPorts = false,
110109
InspectUri = "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
111110
EnvironmentVariables = new Dictionary<string, string> { { "ASPNETCORE_ENVIRONMENT", "Development" } }
112111
});

Modules/Intent.Modules.Blazor/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Version 1.0.6
22

33
- Improvement: Updated module documentation to use centralized documentation site.
4+
- Improvement: Improved WASM configuration for debugging.
45

56
### Version 1.0.5
67

0 commit comments

Comments
 (0)