-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLogoutHandler.cs
More file actions
64 lines (58 loc) · 2.35 KB
/
Copy pathLogoutHandler.cs
File metadata and controls
64 lines (58 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Npgsql;
namespace NpgsqlRest.Auth;
public static class LogoutHandler
{
public static async Task HandleAsync(NpgsqlCommand command, RoutineEndpoint endpoint, HttpContext context, CancellationToken cancellationToken = default)
{
var path = string.Concat(endpoint.Method.ToString(), " ", endpoint.Path);
command.LogCommand(path);
if (endpoint.Routine.IsVoid)
{
await command.ExecuteNonQueryWithRetryAsync(
endpoint.RetryStrategy,
cancellationToken,
errorCodePolicy: endpoint.ErrorCodePolicy ?? NpgsqlRestOptions.Options.ErrorHandlingOptions.DefaultErrorCodePolicy);
await Results.SignOut().ExecuteAsync(context);
await context.Response.CompleteAsync();
return;
}
List<string> schemes = new(5);
await using NpgsqlDataReader reader = await command.ExecuteReaderWithRetryAsync(
endpoint.RetryStrategy,
cancellationToken,
errorCodePolicy: endpoint.ErrorCodePolicy ?? NpgsqlRestOptions.Options.ErrorHandlingOptions.DefaultErrorCodePolicy);
while (await reader!.ReadAsync(cancellationToken))
{
for (int i = 0; i < reader?.FieldCount; i++)
{
if (await reader.IsDBNullAsync(i, cancellationToken) is true)
{
continue;
}
var descriptor = endpoint.Routine.ColumnsTypeDescriptor[i];
if (descriptor.IsArray)
{
object[]? values = reader?.GetValue(i) as object[];
for (int j = 0; j < values?.Length; j++)
{
var value = values[j]?.ToString();
if (value is not null)
{
schemes.Add(value);
}
}
}
else
{
string? value = reader?.GetValue(i)?.ToString();
if (value is not null)
{
schemes.Add(value);
}
}
}
}
await Results.SignOut(authenticationSchemes: schemes.Count == 0 ? null : schemes).ExecuteAsync(context);
await context.Response.CompleteAsync();
}
}