Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Dec 28, 2024
1 parent 5fff8a9 commit 34c3ac1
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
"replaces": "use-your-server-url-here.com"
},
"webAppUrl": {
"displayName": "Server url",
"displayName": "web app url",
"type": "parameter",
"datatype": "string",
"defaultValue": "use-your-web-app-url-here.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Boilerplate.Client.Maui;
public class ClientMauiSettings : ClientCoreSettings
{
/// <summary>
/// Specify the web app url in if API server and web app are hosted separately for proper link/url generation (e.g., email confirmation, social sign-in).
/// When the maui app sends a request to the API server, and the API server and web app are hosted on different URLs,
/// the origin of the generated links (e.g., email confirmation links) will depend on `WebAppUrl` value.
/// </summary>
public string? WebAppUrl { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"WebAppUrl": "use-your-web-app-url-here.com",
"WebAppUrl_Comment": "Specify the origin in Blazor Hybrid (MAUI/Windows) if API and web are hosted separately for proper navigation (e.g., email confirmation, social sign-in).",
"WebAppUrl_Comment": "When the maui app sends a request to the API server, and the API server and web app are hosted on different URLs, the origin of the generated links (e.g., email confirmation links) will depend on `WebAppUrl` value.",
"$schema": "https://json.schemastore.org/appsettings.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Boilerplate.Client.Windows;
public class ClientWindowsSettings : ClientCoreSettings
{
/// <summary>
/// Specify the web app url in if API server and web app are hosted separately for proper link/url generation (e.g., email confirmation, social sign-in).
/// When the Windows app sends a request to the API server, and the API server and web app are hosted on different URLs,
/// the origin of the generated links (e.g., email confirmation links) will depend on `WebAppUrl` value.
/// </summary>
public string? WebAppUrl { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"WebAppUrl": "use-your-web-app-url-here.com",
"WebAppUrl_Comment": "Specify the origin in Blazor Hybrid (MAUI/Windows) if API and web are hosted separately for proper navigation (e.g., email confirmation, social sign-in).",
"WebAppUrl_Comment": "When the Windows app sends a request to the API server, and the API server and web app are hosted on different URLs, the origin of the generated links (e.g., email confirmation links) will depend on `WebAppUrl` value.",
"WindowsUpdate": {
"FilesUrl": null,
"AutoReload": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
style="padding:20px; text-align:center;">
<tr>
<td style="padding-bottom: 10px;">
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetClientUrl(), "images/icon.png"))" width="30" height="20" />
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetWebAppUrl(), "images/icon.png"))" width="30" height="20" />
</td>
</tr>
<tr>
<td>
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetClientUrl()">
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetWebAppUrl()">
@EmailLocalizer[nameof(EmailStrings.AppName)]
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
<table style="width:100%;text-align:center;margin-top:30px;">
<tr>
<td style="padding-bottom:10px;">
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetClientUrl(), "images/icon.png"))" width="30" height="20" />
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetWebAppUrl(), "images/icon.png"))" width="30" height="20" />
</td>
</tr>
<tr>
<td>
<a style="font-size:12px" href="@HttpContext.Request.GetClientUrl()">
<a style="font-size:12px" href="@HttpContext.Request.GetWebAppUrl()">
@EmailLocalizer[nameof(EmailStrings.AppName)]
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
style="padding:20px; text-align:center;">
<tr>
<td style="padding-bottom: 10px;">
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetClientUrl(), "images/icon.png"))" width="30" height="20" />
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetWebAppUrl(), "images/icon.png"))" width="30" height="20" />
</td>
</tr>
<tr>
<td>
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetClientUrl()">
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetWebAppUrl()">
@EmailLocalizer[nameof(EmailStrings.AppName)]
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
style="padding:20px; text-align:center;">
<tr>
<td style="padding-bottom: 10px;">
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetClientUrl(), "images/icon.png"))" width="30" height="20" />
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetWebAppUrl(), "images/icon.png"))" width="30" height="20" />
</td>
</tr>
<tr>
<td>
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetClientUrl()">
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetWebAppUrl()">
@EmailLocalizer[nameof(EmailStrings.AppName)]
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
style="padding:20px; text-align:center;">
<tr>
<td style="padding-bottom: 10px;">
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetClientUrl(), "images/icon.png"))" width="30" height="20" />
<img alt="Company Logo" src="@(new Uri(HttpContext.Request.GetWebAppUrl(), "images/icon.png"))" width="30" height="20" />
</td>
</tr>
<tr>
<td>
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetClientUrl()">
<a style="text-decoration:none; color:#0065EF; font-weight:400; font-size:12px; line-height:150%;" href="@HttpContext.Request.GetWebAppUrl()">
@EmailLocalizer[nameof(EmailStrings.AppName)]
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private async Task SendConfirmEmailToken(User user, string? returnUrl, Cancellat

var email = user.Email!;
var token = await userManager.GenerateUserTokenAsync(user, TokenOptions.DefaultPhoneProvider, FormattableString.Invariant($"VerifyEmail:{email},{user.EmailTokenRequestedOn?.ToUniversalTime()}"));
var link = new Uri(HttpContext.Request.GetClientUrl(), $"{Urls.ConfirmPage}?email={Uri.EscapeDataString(email)}&emailToken={Uri.EscapeDataString(token)}&culture={CultureInfo.CurrentUICulture.Name}&return-url={returnUrl}");
var link = new Uri(HttpContext.Request.GetWebAppUrl(), $"{Urls.ConfirmPage}?email={Uri.EscapeDataString(email)}&emailToken={Uri.EscapeDataString(token)}&culture={CultureInfo.CurrentUICulture.Name}&return-url={returnUrl}");

await emailService.SendEmailToken(user, email, token, link, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task SendResetPasswordToken(SendResetPasswordTokenRequestDto reques
var isEmail = string.IsNullOrEmpty(request.Email) is false;
var qs = $"{(isEmail ? "email" : "phoneNumber")}={Uri.EscapeDataString(isEmail ? request.Email! : request.PhoneNumber!)}";
var url = $"{Urls.ResetPasswordPage}?token={Uri.EscapeDataString(token)}&{qs}&culture={CultureInfo.CurrentUICulture.Name}";
var link = new Uri(HttpContext.Request.GetClientUrl(), url);
var link = new Uri(HttpContext.Request.GetWebAppUrl(), url);

List<Task> sendMessagesTasks = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<ActionResult> SocialSignInCallback(string? returnUrl = null, i
}

if (localHttpPort is not null) return Redirect(new Uri(new Uri($"http://localhost:{localHttpPort}"), url).ToString());
return Redirect(new Uri(Request.HttpContext.Request.GetClientUrl(), url).ToString());
return Redirect(new Uri(Request.HttpContext.Request.GetWebAppUrl(), url).ToString());
}

[LoggerMessage(Level = LogLevel.Error, Message = "Failed to perform {loginProvider} social sign in for {principal}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public async Task SendOtp(IdentityRequestDto request, string? returnUrl = null,

var (magicLinkToken, url) = await GenerateAutomaticSignInLink(user, returnUrl, originalAuthenticationMethod: "Email");

var link = new Uri(HttpContext.Request.GetClientUrl(), url);
var link = new Uri(HttpContext.Request.GetWebAppUrl(), url);

List<Task> sendMessagesTasks = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public async Task SendChangeEmailToken(SendEmailTokenRequestDto request, Cancell
FormattableString.Invariant($"ChangeEmail:{request.Email},{user.EmailTokenRequestedOn?.ToUniversalTime()}"));

var link = new Uri(
HttpContext.Request.GetClientUrl(),
HttpContext.Request.GetWebAppUrl(),
$"{Urls.SettingsPage}/{Urls.SettingsSections.Account}?email={Uri.EscapeDataString(request.Email!)}&emailToken={Uri.EscapeDataString(token)}&culture={CultureInfo.CurrentUICulture.Name}");

await emailService.SendEmailToken(user, request.Email!, token, link, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Microsoft.AspNetCore.Http;

public static partial class HttpRequestExtensions
{
internal static Uri GetClientUrl(this HttpRequest req)
internal static Uri GetWebAppUrl(this HttpRequest req)
{
var settings = req.HttpContext.RequestServices.GetRequiredService<ServerApiSettings>();

Expand All @@ -14,7 +14,7 @@ internal static Uri GetClientUrl(this HttpRequest req)
return new Uri(validOrigin);
}

return req.GetBaseUrl();
return req.GetBaseUrl(); // API server and web app are hosted on the same location.
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//+:cnd:noEmit
//#if (notification == true)
using System.Text.RegularExpressions;
using AdsPush.Abstraction.Settings;
//#endif
using System.Text.RegularExpressions;

namespace Boilerplate.Server.Api;

Expand Down

0 comments on commit 34c3ac1

Please sign in to comment.