mirror of https://github.com/Radarr/Radarr
Add api endpoint to generate the required login cookie
Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
parent
0aebd90ac9
commit
9e7ad678b0
|
@ -1,7 +1,13 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Notifications.Plex.PlexTv;
|
using NzbDrone.Core.Notifications.Plex.PlexTv;
|
||||||
using Radarr.Http;
|
using Radarr.Http;
|
||||||
|
using Radarr.Http.Authentication.Plex;
|
||||||
|
|
||||||
namespace Radarr.Api.V3.Authentication
|
namespace Radarr.Api.V3.Authentication
|
||||||
{
|
{
|
||||||
|
@ -9,10 +15,14 @@ namespace Radarr.Api.V3.Authentication
|
||||||
public class AuthenticationController : Controller
|
public class AuthenticationController : Controller
|
||||||
{
|
{
|
||||||
private readonly IPlexTvService _plex;
|
private readonly IPlexTvService _plex;
|
||||||
|
private readonly IConfigService _configService;
|
||||||
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public AuthenticationController(IPlexTvService plex)
|
public AuthenticationController(IPlexTvService plex, IConfigService configService, IConfigFileProvider configFileProvider)
|
||||||
{
|
{
|
||||||
_plex = plex;
|
_plex = plex;
|
||||||
|
_configService = configService;
|
||||||
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("plex/resources")]
|
[HttpGet("plex/resources")]
|
||||||
|
@ -20,5 +30,32 @@ namespace Radarr.Api.V3.Authentication
|
||||||
{
|
{
|
||||||
return _plex.GetResources(accessToken);
|
return _plex.GetResources(accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("cookie")]
|
||||||
|
public async Task<IActionResult> GetCookie()
|
||||||
|
{
|
||||||
|
var authType = _configFileProvider.AuthenticationMethod;
|
||||||
|
|
||||||
|
var claims = new List<Claim>
|
||||||
|
{
|
||||||
|
new Claim("user", "Anonymous"),
|
||||||
|
new Claim("AuthType", authType.ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
if (authType == NzbDrone.Core.Authentication.AuthenticationType.Plex)
|
||||||
|
{
|
||||||
|
var claimType = _configService.PlexRequireOwner ? PlexConstants.ServerOwnedClaim : PlexConstants.ServerAccessClaim;
|
||||||
|
claims.Add(new Claim(claimType, _configService.PlexAuthServer));
|
||||||
|
}
|
||||||
|
|
||||||
|
var properties = new AuthenticationProperties
|
||||||
|
{
|
||||||
|
IsPersistent = true
|
||||||
|
};
|
||||||
|
|
||||||
|
await HttpContext.SignInAsync(authType.ToString(), new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies", "user", "identifier")), properties);
|
||||||
|
|
||||||
|
return StatusCode((int)HttpStatusCode.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue