diff --git a/Kyoo/Models/IdentityContext.cs b/Kyoo/Models/IdentityContext.cs index 407fd640..9edca959 100644 --- a/Kyoo/Models/IdentityContext.cs +++ b/Kyoo/Models/IdentityContext.cs @@ -25,6 +25,7 @@ namespace Kyoo AllowedGrantTypes = GrantTypes.Code, RequirePkce = true, AllowAccessTokensViaBrowser = true, + AlwaysIncludeUserClaimsInIdToken = true, AllowOfflineAccess = true, RequireClientSecret = false, RequireConsent = false, diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index efeb089e..30bc848f 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -1,4 +1,5 @@ using System.Reflection; +using Kyoo.Api; using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Builder; @@ -71,6 +72,7 @@ namespace Kyoo .AddInMemoryIdentityResources(IdentityContext.GetIdentityResources()) .AddInMemoryApiResources(IdentityContext.GetApis()) .AddAspNetIdentity() + .AddProfileService() .AddDeveloperSigningCredential(); services.AddScoped(); diff --git a/Kyoo/Views/API/AccountAPI.cs b/Kyoo/Views/API/AccountAPI.cs index ca5d6ea5..a6b907f4 100644 --- a/Kyoo/Views/API/AccountAPI.cs +++ b/Kyoo/Views/API/AccountAPI.cs @@ -1,5 +1,9 @@ using System; +using System.Collections.Generic; +using System.Security.Claims; using System.Threading.Tasks; +using IdentityServer4.Extensions; +using IdentityServer4.Models; using IdentityServer4.Services; using Kyoo.Models; using Microsoft.AspNetCore.Authorization; @@ -26,7 +30,7 @@ namespace Kyoo.Api [Route("api/[controller]")] [ApiController] - public class AccountController : Controller + public class AccountController : Controller, IProfileService { private readonly UserManager _userManager; private readonly SignInManager _signInManager; @@ -69,26 +73,26 @@ namespace Kyoo.Api await _signInManager.SignOutAsync(); return Ok(); } - - [HttpGet] - [Authorize] - public async Task> Index() + + public async Task GetProfileDataAsync(ProfileDataRequestContext context) { - User account = await _userManager.GetUserAsync(HttpContext.User); - return new Account{ - Username = account.UserName, - Email = account.Email, - Picture = "api/account/picture/" + account.UserName - }; + User user = await _userManager.GetUserAsync(context.Subject); + if (user != null) + { + List claims = new List + { + new Claim("email", user.Email), + new Claim("username", user.UserName), + }; + + context.IssuedClaims.AddRange(claims); + } } - - [HttpGet("picture/{username}")] - public IActionResult Picture(string username) + + public async Task IsActiveAsync(IsActiveContext context) { - string path = $"account/{username}.png"; - if (System.IO.File.Exists(path)) - return new PhysicalFileResult(path, "image"); - return NotFound(); + User user = await _userManager.GetUserAsync(context.Subject); + context.IsActive = user != null; } } } \ No newline at end of file diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index ee0c1d6a..6d892fd4 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit ee0c1d6a4843ebbb5836c14be30ab06d895b8209 +Subproject commit 6d892fd46e7aa56a7cb0bebd94d4404899382f2b