//------------------------------------------------------------------------------ // // This code was generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. // // Changes to this file may cause incorrect behavior and will be lost when // the code is regenerated. // //------------------------------------------------------------------------------ #nullable enable namespace PlexAPI { using Newtonsoft.Json; using PlexAPI.Models.Components; using PlexAPI.Models.Requests; using PlexAPI.Utils; using System.Net.Http.Headers; using System.Net.Http; using System.Threading.Tasks; using System; /// /// API Calls regarding authentication for Plex Media Server
/// /// /// /// ///
public interface IAuthentication { /// /// Get a Transient Token. /// /// /// This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted.
/// ///
///
Task GetTransientTokenAsync(GetTransientTokenQueryParamType type, Scope scope); /// /// Get Source Connection Information /// /// /// If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.
/// Note: requires Plex Media Server >= 1.15.4.
/// ///
///
Task GetSourceConnectionInformationAsync(string source); } /// /// API Calls regarding authentication for Plex Media Server
/// /// /// /// ///
public class Authentication: IAuthentication { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; private const string _sdkVersion = "0.2.1"; private const string _sdkGenVersion = "2.281.2"; private const string _openapiDocVersion = "0.0.3"; private const string _userAgent = "speakeasy-sdk/csharp 0.2.1 2.281.2 0.0.3 Plex-API"; private string _serverUrl = ""; private ISpeakeasyHttpClient _defaultClient; private Func? _securitySource; public Authentication(ISpeakeasyHttpClient defaultClient, Func? securitySource, string serverUrl, SDKConfig config) { _defaultClient = defaultClient; _securitySource = securitySource; _serverUrl = serverUrl; SDKConfiguration = config; } public async Task GetTransientTokenAsync(GetTransientTokenQueryParamType type, Scope scope) { var request = new GetTransientTokenRequest() { Type = type, Scope = scope, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/security/token", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetTransientTokenResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } public async Task GetSourceConnectionInformationAsync(string source) { var request = new GetSourceConnectionInformationRequest() { Source = source, }; string baseUrl = this.SDKConfiguration.GetTemplatedServerDetails(); var urlString = URLBuilder.Build(baseUrl, "/security/resources", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var client = _defaultClient; if (_securitySource != null) { client = SecuritySerializer.Apply(_defaultClient, _securitySource); } var httpResponse = await client.SendAsync(httpRequest); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; var response = new GetSourceConnectionInformationResponse { StatusCode = (int)httpResponse.StatusCode, ContentType = contentType, RawResponse = httpResponse }; if((response.StatusCode == 200) || (response.StatusCode == 400)) { return response; } if((response.StatusCode == 401)) { if(Utilities.IsContentTypeMatch("application/json",response.ContentType)) { response.Object = JsonConvert.DeserializeObject(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerSettings(){ NullValueHandling = NullValueHandling.Ignore, Converters = new JsonConverter[] { new FlexibleObjectDeserializer(), new EnumSerializer() }}); } return response; } return response; } } }