1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Merge constants

This commit is contained in:
Maksym Pavlenko
2017-01-06 18:06:17 -08:00
parent c2292f376f
commit dcfe1f6fc1
4 changed files with 18 additions and 20 deletions

View File

@@ -3,7 +3,7 @@ using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Podsync.Services.Patreon;
using Podsync.Services;
namespace Podsync.Helpers
{
@@ -53,7 +53,7 @@ namespace Podsync.Helpers
const int MinAmountCents = 100;
int amount;
if (int.TryParse(user.GetClaim(PatreonConstants.AmountDonated), out amount))
if (int.TryParse(user.GetClaim(Constants.Patreon.AmountDonated), out amount))
{
return amount >= MinAmountCents;
}

View File

@@ -7,5 +7,16 @@ namespace Podsync.Services
public const int DefaultPageSize = 50;
public const ResolveType DefaultFormat = ResolveType.VideoHigh;
public static class Patreon
{
public const string AuthenticationScheme = "Patreon";
public const string AuthorizationEndpoint = "https://www.patreon.com/oauth2/authorize";
public const string TokenEndpoint = "https://api.patreon.com/oauth2/token";
public const string AmountDonated = "Patreon/" + nameof(AmountDonated);
}
}
}

View File

@@ -1,13 +0,0 @@
namespace Podsync.Services.Patreon
{
public static class PatreonConstants
{
public const string AuthenticationScheme = "Patreon";
public const string AuthorizationEndpoint = "https://www.patreon.com/oauth2/authorize";
public const string TokenEndpoint = "https://api.patreon.com/oauth2/token";
public const string AmountDonated = "Patreon/" + nameof(AmountDonated);
}
}

View File

@@ -95,15 +95,15 @@ namespace Podsync
// Patreon authentication
app.UseOAuthAuthentication(new OAuthOptions
{
AuthenticationScheme = PatreonConstants.AuthenticationScheme,
AuthenticationScheme = Constants.Patreon.AuthenticationScheme,
ClientId = Configuration[$"Podsync:{nameof(PodsyncConfiguration.PatreonClientId)}"],
ClientSecret = Configuration[$"Podsync:{nameof(PodsyncConfiguration.PatreonSecret)}"],
CallbackPath = new PathString("/oauth-patreon"),
AuthorizationEndpoint = PatreonConstants.AuthorizationEndpoint,
TokenEndpoint = PatreonConstants.TokenEndpoint,
AuthorizationEndpoint = Constants.Patreon.AuthorizationEndpoint,
TokenEndpoint = Constants.Patreon.TokenEndpoint,
SaveTokens = true,
@@ -129,7 +129,7 @@ namespace Podsync
context.Identity.AddClaim(new Claim(ClaimTypes.Uri, user.Url));
var amountCents = user.Pledges.Sum(x => x.AmountCents);
context.Identity.AddClaim(new Claim(PatreonConstants.AmountDonated, amountCents.ToString()));
context.Identity.AddClaim(new Claim(Constants.Patreon.AmountDonated, amountCents.ToString()));
var telemetry = app.ApplicationServices.GetService<TelemetryClient>();
telemetry.TrackEvent("Login", new Dictionary<string, string>
@@ -147,7 +147,7 @@ namespace Podsync
builder.Run(async context =>
{
// Return a challenge to invoke the Patreon authentication scheme
await context.Authentication.ChallengeAsync(PatreonConstants.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
await context.Authentication.ChallengeAsync(Constants.Patreon.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
});
});