-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tidusjar/develop
Bringing develop up to date
- Loading branch information
Showing
86 changed files
with
4,070 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace Ombi.Api.Plex.Models.OAuth | ||
{ | ||
public class OAuthPin | ||
{ | ||
public int id { get; set; } | ||
public string code { get; set; } | ||
public bool trusted { get; set; } | ||
public string clientIdentifier { get; set; } | ||
public Location location { get; set; } | ||
public int expiresIn { get; set; } | ||
public DateTime createdAt { get; set; } | ||
public DateTime expiresAt { get; set; } | ||
public string authToken { get; set; } | ||
} | ||
|
||
public class Location | ||
{ | ||
public string code { get; set; } | ||
public string country { get; set; } | ||
public string city { get; set; } | ||
public string subdivisions { get; set; } | ||
public string coordinates { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Ombi.Api.Plex; | ||
using Ombi.Api.Plex.Models; | ||
using Ombi.Api.Plex.Models.OAuth; | ||
using Ombi.Core.Settings; | ||
using Ombi.Helpers; | ||
using Ombi.Settings.Settings.Models; | ||
|
||
namespace Ombi.Core.Authentication | ||
{ | ||
public class PlexOAuthManager : IPlexOAuthManager | ||
{ | ||
public PlexOAuthManager(IPlexApi api, ISettingsService<CustomizationSettings> settings) | ||
{ | ||
_api = api; | ||
_customizationSettingsService = settings; | ||
} | ||
|
||
private readonly IPlexApi _api; | ||
private readonly ISettingsService<CustomizationSettings> _customizationSettingsService; | ||
|
||
public async Task<OAuthPin> RequestPin() | ||
{ | ||
var pin = await _api.CreatePin(); | ||
return pin; | ||
} | ||
|
||
public async Task<string> GetAccessTokenFromPin(int pinId) | ||
{ | ||
var pin = await _api.GetPin(pinId); | ||
if (pin.expiresAt < DateTime.UtcNow) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
if (pin.authToken.IsNullOrEmpty()) | ||
{ | ||
// Looks like we do not have a pin yet, we should retry a few times. | ||
var retryCount = 0; | ||
var retryMax = 5; | ||
var retryWaitMs = 1000; | ||
while (pin.authToken.IsNullOrEmpty() && retryCount < retryMax) | ||
{ | ||
retryCount++; | ||
await Task.Delay(retryWaitMs); | ||
pin = await _api.GetPin(pinId); | ||
} | ||
} | ||
return pin.authToken; | ||
} | ||
|
||
public async Task<PlexAccount> GetAccount(string accessToken) | ||
{ | ||
return await _api.GetAccount(accessToken); | ||
} | ||
|
||
public async Task<Uri> GetOAuthUrl(int pinId, string code) | ||
{ | ||
var settings = await _customizationSettingsService.GetSettingsAsync(); | ||
if (settings.ApplicationUrl.IsNullOrEmpty()) | ||
{ | ||
return null; | ||
} | ||
|
||
var url = _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl, false); | ||
return url; | ||
} | ||
|
||
public Uri GetWizardOAuthUrl(int pinId, string code, string websiteAddress) | ||
{ | ||
var url = _api.GetOAuthUrl(pinId, code, websiteAddress, true); | ||
return url; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.