Skip to content
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

Add LoginInfoConverter #15422

Merged
merged 25 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6bd5ee5
ad LoginInfoConverter
hyzx86 Feb 28, 2024
bd81d80
Merge branch 'main' into addLoginInfoConverter
hyzx86 Feb 28, 2024
d0d3391
Register the LoginInfoConverter
MikeAlhayek Feb 28, 2024
c440d87
rename class
MikeAlhayek Feb 28, 2024
4e75094
Rename LoginInfoConverter.cs to LoginInfoJsonConverter.cs
MikeAlhayek Feb 28, 2024
3b12193
Update LoginInfoJsonConverter.cs
MikeAlhayek Feb 28, 2024
8595132
Update LoginInfoJsonConverter.cs
MikeAlhayek Feb 28, 2024
da54778
move the converter to the abstraction project
MikeAlhayek Feb 28, 2024
6ceef77
cleanup
MikeAlhayek Feb 28, 2024
e1f56a0
move LoginInfoJsonConverter to JOption.Base
Feb 29, 2024
d98706e
Merge branch 'main' into addLoginInfoConverter
MikeAlhayek Feb 29, 2024
41d2e42
move around
MikeAlhayek Feb 29, 2024
0cf80d7
fix build
MikeAlhayek Feb 29, 2024
31d37d1
uncomment
MikeAlhayek Feb 29, 2024
07d8ed2
Update UsersServiceCollectionExtensions.cs
MikeAlhayek Feb 29, 2024
e8446ee
Merge branch 'main' into addLoginInfoConverter
MikeAlhayek Feb 29, 2024
cad7ddd
add QueryUserLoginInfoTest
Mar 1, 2024
168ab33
Add a simple test case
MikeAlhayek Mar 1, 2024
f30855f
Merge branch 'addLoginInfoConverter' of https://github.com/hyzx86/Orc…
MikeAlhayek Mar 1, 2024
41bb36d
fix LoginInfoJsonConverter Write
Mar 1, 2024
84e4747
Merge branch 'addLoginInfoConverter' of https://github.com/hyzx86/Orc…
Mar 1, 2024
80431fb
fix test
Mar 1, 2024
6fd5e3c
Merge branch 'main' into addLoginInfoConverter
hyzx86 Mar 1, 2024
0548788
cleanup tests
MikeAlhayek Mar 1, 2024
afc697f
Merge branch 'main' into addLoginInfoConverter
MikeAlhayek Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using OrchardCore.Users.Handlers;
using OrchardCore.Users.Indexes;
using OrchardCore.Users.Services;
using OrchardCore.Users.Core.Json;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -55,6 +56,11 @@ public static IServiceCollection AddUsers(this IServiceCollection services)
services.AddScoped<ITwoFactorAuthenticationHandler, DefaultTwoFactorAuthenticationHandler>();
services.AddScoped<ITwoFactorAuthenticationHandlerCoordinator, DefaultTwoFactorAuthenticationHandlerCoordinator>();

services.Configure<JsonSerializerOptions>(options =>
{
options.Converters.Add(new LoginInfoJsonConverter());
});

return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Identity;

namespace OrchardCore.Users.Core.Json;

public class LoginInfoJsonConverter : JsonConverter<UserLoginInfo>

Check failure on line 8 in src/OrchardCore/OrchardCore.Users.Core/Json/LoginInfoJsonConverter.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

'LoginInfoJsonConverter' does not implement inherited abstract member 'JsonConverter<UserLoginInfo>.Write(Utf8JsonWriter, UserLoginInfo, JsonSerializerOptions)'

Check failure on line 8 in src/OrchardCore/OrchardCore.Users.Core/Json/LoginInfoJsonConverter.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

'LoginInfoJsonConverter' does not implement inherited abstract member 'JsonConverter<UserLoginInfo>.Write(Utf8JsonWriter, UserLoginInfo, JsonSerializerOptions)'

Check failure on line 8 in src/OrchardCore/OrchardCore.Users.Core/Json/LoginInfoJsonConverter.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

'LoginInfoJsonConverter' does not implement inherited abstract member 'JsonConverter<UserLoginInfo>.Write(Utf8JsonWriter, UserLoginInfo, JsonSerializerOptions)'

Check failure on line 8 in src/OrchardCore/OrchardCore.Users.Core/Json/LoginInfoJsonConverter.cs

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

'LoginInfoJsonConverter' does not implement inherited abstract member 'JsonConverter<UserLoginInfo>.Write(Utf8JsonWriter, UserLoginInfo, JsonSerializerOptions)'
{
public static readonly LoginInfoJsonConverter Instance = new();

public override UserLoginInfo Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var loginInfo = new UserLoginInfo(string.Empty, string.Empty, string.Empty);

while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
{
break;
}

if (reader.TokenType == JsonTokenType.PropertyName)
{
var propertyName = reader.GetString();
reader.Read();

switch (propertyName)
{
case nameof(UserLoginInfo.LoginProvider):
loginInfo.LoginProvider = reader.GetString();
break;
case nameof(UserLoginInfo.ProviderKey):
loginInfo.ProviderKey = reader.GetString();
break;
case nameof(UserLoginInfo.ProviderDisplayName):
loginInfo.ProviderDisplayName = reader.GetString();
break;
default:
break;
}
}
}

return loginInfo;
}

// public override void Write(Utf8JsonWriter writer, UserLoginInfo objectToWrite, JsonSerializerOptions options)
// => JsonSerializer.Serialize(writer, objectToWrite, objectToWrite.GetType(), options);
}
Loading