-
Notifications
You must be signed in to change notification settings - Fork 178
feat: add RedirectUriPrefix support to OpenIdConnectConfiguration for sub-path deployments #809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ffac1ad
910f72a
577bb8b
0572c9c
f561b4f
2b90d07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| namespace Elsa.Studio.Login.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// Provides a set of extension methods for <see cref="string"/>. | ||
| /// </summary> | ||
| internal static class StringExtensions | ||
| { | ||
| /// <summary> | ||
| /// Ensures the string starts with the specified character when non-empty. | ||
| /// </summary> | ||
| public static string EnsureStartsWith(this string? value, string prefix) | ||
| { | ||
| if (string.IsNullOrEmpty(value)) | ||
| return string.Empty; | ||
|
|
||
| return value.StartsWith(prefix) ? value : prefix + value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Ensures the string ends with the specified string when non-empty. | ||
| /// </summary> | ||
| public static string EnsureEndsWith(this string? value, string suffix) | ||
| { | ||
| if (string.IsNullOrEmpty(value)) | ||
| return string.Empty; | ||
|
|
||
| return value.EndsWith(suffix) ? value : value + suffix; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using Elsa.Studio.Login.Contracts; | ||
| using Elsa.Studio.Login.Contracts; | ||
| using Elsa.Studio.Login.Extensions; | ||
| using Elsa.Studio.Login.Models; | ||
| using Microsoft.AspNetCore.Components; | ||
| using Microsoft.AspNetCore.WebUtilities; | ||
|
|
@@ -21,7 +22,7 @@ public class OpenIdConnectAuthorizationService(IJwtAccessor jwtAccessor, IOption | |
| public async Task RedirectToAuthorizationServer() | ||
| { | ||
| var config = configuration.Value; | ||
| var redirectUri = new Uri(navigationManager.Uri).GetLeftPart(UriPartial.Authority) + "/signin-oidc"; | ||
| var redirectUri = new Uri(navigationManager.Uri).GetLeftPart(UriPartial.Authority) + config.RedirectUriPrefix.EnsureStartsWith("/") + "/signin-oidc"; | ||
| string url = config.AuthEndpoint + $"?client_id={WebUtility.UrlEncode(config.ClientId)}&redirect_uri={WebUtility.UrlEncode(redirectUri)}&response_type=code&scope={WebUtility.UrlEncode(String.Join(' ', config.Scopes))}"; | ||
| if (config.UsePkce) | ||
| { | ||
|
|
@@ -40,7 +41,7 @@ public async Task RedirectToAuthorizationServer() | |
| public async Task ReceiveAuthorizationCode(string code, string? state, CancellationToken cancellationToken) | ||
| { | ||
| var config = configuration.Value; | ||
| var redirectUri = new Uri(navigationManager.Uri).GetLeftPart(UriPartial.Authority) + "/signin-oidc"; | ||
| var redirectUri = new Uri(navigationManager.Uri).GetLeftPart(UriPartial.Authority) + config.RedirectUriPrefix.EnsureStartsWith("/") + "/signin-oidc"; | ||
|
|
||
| var formValues = new List<KeyValuePair<string, string>> | ||
| { | ||
|
|
@@ -50,7 +51,7 @@ public async Task ReceiveAuthorizationCode(string code, string? state, Cancellat | |
| new("redirect_uri", redirectUri) | ||
| }; | ||
|
|
||
| if(!string.IsNullOrWhiteSpace(config.ClientSecret)) | ||
| if (!string.IsNullOrWhiteSpace(config.ClientSecret)) | ||
| { | ||
| formValues.Add(new KeyValuePair<string, string>("client_secret", config.ClientSecret)); | ||
| } | ||
|
|
@@ -132,7 +133,7 @@ private static async Task<string> ReadErrorSummaryAsync(HttpContent content, Can | |
| if (summary.Length > MaxLoggedErrorLength) | ||
| summary = summary[..MaxLoggedErrorLength]; | ||
|
|
||
| return truncated ? $"{summary}…" : summary; | ||
| return truncated ? $"{summary}�" : summary; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original file (which had a UTF-8 BOM) contained the HORIZONTAL ELLIPSIS Prompt To Fix With AIThis is a comment left during a code review.
Path: src/modules/Elsa.Studio.Login/Services/OpenIdConnectAuthorizationService.cs
Line: 136
Comment:
**Corrupted ellipsis character**
The original file (which had a UTF-8 BOM) contained the HORIZONTAL ELLIPSIS `…` (U+2026) on this line. When the BOM was stripped in this PR, the multi-byte sequence for that character was corrupted to U+FFFD (the Unicode Replacement Character). At runtime, truncated error summaries logged by `ReadErrorSummaryAsync` will end with the replacement character `<?>` instead of `…`, producing garbled log output. Replace the character literal on this line with the correct `…` (U+2026), or use the escape `\u2026`.
How can I resolve this? If you propose a fix, please make it concise. |
||
| } | ||
|
|
||
| private static async Task<(string Content, bool Truncated)> ReadContentSnippetAsync(HttpContent content, CancellationToken cancellationToken) | ||
|
|
@@ -178,4 +179,5 @@ private static async Task<string> ReadErrorSummaryAsync(HttpContent content, Can | |
|
|
||
| return null; | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.