feat: add authorize in OAuth
This commit is contained in:
38
Security/Common/Domain/OAuth2/UserInfo/GoogleUserInfo.cs
Normal file
38
Security/Common/Domain/OAuth2/UserInfo/GoogleUserInfo.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Mirea.Api.Security.Common.Interfaces;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Mirea.Api.Security.Common.Domain.OAuth2.UserInfo;
|
||||
|
||||
internal class GoogleUserInfo : IUserInfo
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public required string Id { get; set; }
|
||||
|
||||
[JsonPropertyName("email")]
|
||||
public required string Email { get; set; }
|
||||
|
||||
[JsonPropertyName("given_name")]
|
||||
public required string GivenName { get; set; }
|
||||
|
||||
[JsonPropertyName("family_name")]
|
||||
public required string FamilyName { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public required string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("picture")]
|
||||
public required string Picture { get; set; }
|
||||
|
||||
[JsonPropertyName("verified_email")]
|
||||
public bool? VerifiedEmail { get; set; }
|
||||
|
||||
public OAuthUser MapToInternalUser() =>
|
||||
new()
|
||||
{
|
||||
Id = Id,
|
||||
Email = VerifiedEmail.HasValue && VerifiedEmail.Value ? Email : null,
|
||||
FirstName = GivenName,
|
||||
LastName = FamilyName,
|
||||
IconUri = Picture
|
||||
};
|
||||
}
|
36
Security/Common/Domain/OAuth2/UserInfo/MailRuUserInfo.cs
Normal file
36
Security/Common/Domain/OAuth2/UserInfo/MailRuUserInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Mirea.Api.Security.Common.Interfaces;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Mirea.Api.Security.Common.Domain.OAuth2.UserInfo;
|
||||
|
||||
internal class MailRuUserInfo : IUserInfo
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public required string Id { get; set; }
|
||||
|
||||
[JsonPropertyName("email")]
|
||||
public required string Email { get; set; }
|
||||
|
||||
[JsonPropertyName("first_name")]
|
||||
public required string FirstName { get; set; }
|
||||
|
||||
[JsonPropertyName("last_name")]
|
||||
public required string LastName { get; set; }
|
||||
|
||||
[JsonPropertyName("nickname")]
|
||||
public required string Username { get; set; }
|
||||
|
||||
[JsonPropertyName("image")]
|
||||
public string? Image { get; set; }
|
||||
|
||||
public OAuthUser MapToInternalUser() =>
|
||||
new()
|
||||
{
|
||||
Id = Id,
|
||||
Email = Email,
|
||||
FirstName = FirstName,
|
||||
LastName = LastName,
|
||||
Username = Username,
|
||||
IconUri = Image
|
||||
};
|
||||
}
|
41
Security/Common/Domain/OAuth2/UserInfo/YandexUserInfo.cs
Normal file
41
Security/Common/Domain/OAuth2/UserInfo/YandexUserInfo.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Mirea.Api.Security.Common.Interfaces;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Mirea.Api.Security.Common.Domain.OAuth2.UserInfo;
|
||||
|
||||
internal class YandexUserInfo : IUserInfo
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public required string Id { get; set; }
|
||||
|
||||
[JsonPropertyName("login")]
|
||||
public required string Login { get; set; }
|
||||
|
||||
[JsonPropertyName("default_email")]
|
||||
public required string DefaultEmail { get; set; }
|
||||
|
||||
[JsonPropertyName("first_name")]
|
||||
public string? FirstName { get; set; }
|
||||
|
||||
[JsonPropertyName("last_name")]
|
||||
public string? LastName { get; set; }
|
||||
|
||||
|
||||
[JsonPropertyName("is_avatar_empty")]
|
||||
public bool IsAvatarEmpty { get; set; }
|
||||
|
||||
[JsonPropertyName("default_avatar_id")]
|
||||
public string? DefaultAvatarId { get; set; }
|
||||
|
||||
public OAuthUser MapToInternalUser() =>
|
||||
new()
|
||||
{
|
||||
Id = Id,
|
||||
Email = DefaultEmail,
|
||||
FirstName = FirstName,
|
||||
LastName = LastName,
|
||||
IconUri =
|
||||
IsAvatarEmpty ? null : $"https://avatars.yandex.net/get-yapic/{DefaultAvatarId}/islands-retina-50",
|
||||
Username = Login
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user