Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions backend/Money.Api/Controllers/ExternalAuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ public async Task<IActionResult> Callback()
var userId = principal.FindFirst(OpenIddictConstants.Claims.Subject)?.Value
?? principal.FindFirst(ClaimTypes.NameIdentifier)?.Value;

// TODO: Не работает
var email = principal.FindFirst(ClaimTypes.Email)!.Value;
var email = principal.FindFirst(ClaimTypes.Email)?.Value
?? principal.FindFirst(OpenIddictConstants.Claims.Email)?.Value;

if (string.IsNullOrWhiteSpace(email))
{
return BadRequest("Email обязателен для внешней аутентификации.");
}

var name = principal.FindFirst(ClaimTypes.Name)?.Value;
var userNameCandidate = name?? BuildValidUserName(email, userId);
var userNameCandidate = name ?? BuildValidUserName(email, userId);

var providerName = result.Properties?.GetString(OpenIddictClientAspNetCoreConstants.Properties.ProviderName) ?? "GitHub";

Expand All @@ -96,7 +102,7 @@ public async Task<IActionResult> Callback()
{
UserName = uniqueUserName,
Email = email,
EmailConfirmed = email != null
EmailConfirmed = true,
};

var createResult = await userManager.CreateAsync(user);
Expand Down
42 changes: 29 additions & 13 deletions frontend/Money.Web/Pages/Account/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,36 @@
</EditForm>

<MudDivider Class="my-4" />
<MudButton Color="Color.Primary"
Variant="Variant.Filled"
StartIcon="@Icons.Material.Filled.Login"
OnClick="OnAuthLogin">
Войти через bob217.Auth
</MudButton>
<MudButton Color="Color.Secondary"
Variant="Variant.Outlined"
StartIcon="@Icons.Material.Filled.Login"
OnClick="OnGitHubLogin">
Войти через GitHub
</MudButton>

<MudGrid Class="mt-4">
<MudStack Spacing="2">
<MudText Typo="Typo.h6">Вход через внешние сервисы</MudText>
<MudText Typo="Typo.caption"
Color="Color.Info">
Используйте один из провайдеров ниже. Для входа требуется доступ к вашему email.
</MudText>

<MudStack AlignItems="AlignItems.Center">
<MudButton Color="Color.Secondary"
FullWidth
OnClick="OnAuthLogin"
StartIcon="@Icons.Material.Filled.Login"
Variant="Variant.Outlined">
Войти через bob217.Auth
</MudButton>

<MudButton Color="Color.Secondary"
FullWidth
OnClick="OnGitHubLogin"
StartIcon="@Icons.Custom.Brands.GitHub"
Variant="Variant.Outlined">
Войти через GitHub
</MudButton>
</MudStack>
</MudStack>

<MudDivider Class="my-4" />

<MudGrid>
<MudItem md="12"
xs="12">
<MudLink Href="@(NavigationManager.GetUriWithReturnUrl("Account/Register", ReturnUrl).ToString())">
Expand Down
Loading