Added the ability to get the ombi user via a Plex Token #2591

This commit is contained in:
Jamie 2018-10-26 21:07:43 +01:00
commit 07f3f4162a
3 changed files with 42 additions and 3 deletions

View file

@ -29,6 +29,7 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Ombi.Api.Emby;
@ -101,6 +102,22 @@ namespace Ombi.Core.Authentication
return true;
}
public async Task<OmbiUser> GetOmbiUserFromPlexToken(string plexToken)
{
var plexAccount = await _plexApi.GetAccount(plexToken);
// Check for a ombi user
if (plexAccount?.user != null)
{
var potentialOmbiUser = await Users.FirstOrDefaultAsync(x =>
x.ProviderUserId.Equals(plexAccount.user.id, StringComparison.InvariantCultureIgnoreCase));
return potentialOmbiUser;
}
return null;
}
/// <summary>
/// Sign the user into plex and make sure we can get the authentication token.
/// <remarks>We do not check if the user is in the owners "friends" since they must have a local user account to get this far</remarks>