Skip to content

Commit 2aee684

Browse files
committed
chore: Update UriExtensions along Review suggestions
TODO: Decide which of both Query checking Methods should be used
1 parent 06a0e34 commit 2aee684

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

Yllibed.Handlers.Uno/Extensions/UriExtensions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
2+
using System.Collections.Specialized;
23
using System.Linq;
4+
using System.Web;
35

46
namespace Yllibed.Handlers.Uno.Extensions;
57

@@ -10,10 +12,19 @@ public static IDictionary<string, string> GetParameters(this Uri uri)
1012
{
1113

1214
return uri
13-
.OriginalString
15+
.Query
1416
.Split(_uriSplitChars, StringSplitOptions.RemoveEmptyEntries)
1517
.Select(p => p.Split('='))
1618
.Where(parts => parts.Length > 1)
1719
.ToDictionary(parts => parts[0], parts => string.Join('=', parts.Skip(1)), StringComparer.Ordinal);
1820
}
21+
public static NameValueCollection GetQuery(this Uri? redirectUri, Uri callbackUri) // TODO: Check if we maybe should exchange using GetParameters to this method
22+
{
23+
if (redirectUri is null)
24+
return [];
25+
return redirectUri.IsBaseOf(callbackUri) // Reused from Uno.Extensions.Authentication.Web.WebAuthenticationProvider and changed to use Uri instead of string
26+
? AuthHttpUtility.ExtractArguments(redirectUri.ToString()) // it's a fully qualified url, so need to extract query or fragment
27+
: AuthHttpUtility.ParseQueryString(redirectUri.ToString().TrimStart('#').TrimStart('?')); // it isn't a full url, so just process as query or fragment
28+
29+
}
1930
}

Yllibed.Handlers.Uno/IAuthCallbackHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ namespace Yllibed.Handlers.Uno;
33
public interface IAuthCallbackHandler : IHttpHandler
44
{
55
public Uri CallbackUri { get; }
6+
public Task<WebAuthenticationResult> WaitForCallbackAsync();
67
}

Yllibed.Handlers.Uno/OAuthCallbackHandler.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,23 @@ protected virtual WebAuthenticationResult GetWebAuthenticationResult(uint status
5151
_ => new WebAuthenticationResult(requestUriString, statusCode, WebAuthenticationStatus.ErrorHttp),
5252
};
5353
}
54+
//protected virtual uint GetStatusCode(NameValueCollection parameters) // TODO: Check if we maybe should exchange using GetParameters with return Dictionary to this method
55+
//{
56+
// if (parameters.Get(OAuthErrorResponseDefaults.ErrorKey) is string error)
57+
// {
58+
// return error switch
59+
// {
60+
// OAuthErrorResponseDefaults.AccessDenied => 403,
61+
// OAuthErrorResponseDefaults.InvalidClient or OAuthErrorResponseDefaults.UnauthorizedClient or OAuthErrorResponseDefaults.InvalidScope => 401,
62+
// OAuthErrorResponseDefaults.TemporarilyUnavailable => 503,
63+
// OAuthErrorResponseDefaults.UnsupportedGrantType => 500,
64+
// _ => 400 // For all others: Bad Request
65+
// };
5466

67+
// }
68+
69+
// return 200;
70+
//}
5571
protected virtual uint GetStatusCode(IDictionary<string, string> parameters)
5672
{
5773
if (parameters.TryGetValue(OAuthErrorResponseDefaults.ErrorKey, out var error))
@@ -79,8 +95,6 @@ protected virtual string GetWebAuthenticationResponseMessage(WebAuthenticationRe
7995
_ => "Authentication completed - you can close this browser now."
8096
};
8197
}
82-
public Task<WebAuthenticationResult> WaitForCallbackAsync()
83-
{
84-
return _tcs.Task;
85-
}
98+
public Task<WebAuthenticationResult> WaitForCallbackAsync() => _tcs.Task;
99+
86100
}

Yllibed.Handlers.Uno/Yllibed.Handlers.Uno.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
<Nullable>enable</Nullable>
77
<UnoFeatures>
88
Logging;
9-
Configuration;
9+
Authentication;
1010
</UnoFeatures>
1111
</PropertyGroup>
12-
<ItemGroup Label="Packages">
13-
<!-- <PackageReference Include="Uno.UI"/> TODO: Decide if using PackageReference or Uno.Sdk is able to provide the wanted Low dependency level.-->
14-
</ItemGroup>
1512
<ItemGroup Label="Projects">
1613
<ProjectReference Include="..\Yllibed.HttpServer\Yllibed.HttpServer.csproj" />
1714
</ItemGroup>

0 commit comments

Comments
 (0)