btcpayserver/BTCPayServer/Extensions.cs

49 lines
1.1 KiB
C#
Raw Normal View History

2017-09-13 08:47:34 +02:00
using BTCPayServer.Authentication;
using BTCPayServer.Configuration;
2017-09-27 08:16:30 +02:00
using Microsoft.AspNetCore.Http;
2017-09-13 08:47:34 +02:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2017-09-13 08:47:34 +02:00
using System;
using System.Collections.Generic;
using System.Text;
namespace BTCPayServer
{
public static class Extensions
{
2017-09-27 08:16:30 +02:00
public static string WithTrailingSlash(this string str)
{
if(str.EndsWith("/"))
return str;
return str + "/";
}
public static string GetAbsoluteRoot(this HttpRequest request)
{
return string.Concat(
request.Scheme,
"://",
request.Host.ToUriComponent(),
request.PathBase.ToUriComponent());
}
public static IServiceCollection ConfigureBTCPayServer(this IServiceCollection services, IConfiguration conf)
{
services.Configure<BTCPayServerOptions>(o =>
{
o.LoadArgs(conf);
});
return services;
}
2017-09-13 08:47:34 +02:00
public static BitIdentity GetBitIdentity(this Controller controller)
{
if(!(controller.User.Identity is BitIdentity))
throw new UnauthorizedAccessException("no-bitid");
return (BitIdentity)controller.User.Identity;
}
}
}