diff --git a/dotnet/Services/Identity/App/Application.cs b/dotnet/Services/Identity/App/Application.cs new file mode 100644 index 00000000..1b285669 --- /dev/null +++ b/dotnet/Services/Identity/App/Application.cs @@ -0,0 +1,25 @@ +using Branch.Services.Identity.Models; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using ServiceStack.Redis; + +namespace Branch.Services.Identity.App +{ + public partial class Application + { + private ILogger _logger { get; } + private IRedisClientsManager _redisClientsManager { get; } + private Config _config { get; } + + public Application( + ILoggerFactory loggerFactory, + IRedisClientsManager redisClientsManager, + IOptionsMonitor options + ) + { + _logger = loggerFactory.CreateLogger(typeof(Application)); + _redisClientsManager = redisClientsManager; + _config = options.CurrentValue; + } + } +} diff --git a/dotnet/Services/Identity/App/GetXblIdentity.cs b/dotnet/Services/Identity/App/GetXblIdentity.cs new file mode 100644 index 00000000..bc44b293 --- /dev/null +++ b/dotnet/Services/Identity/App/GetXblIdentity.cs @@ -0,0 +1,23 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; + +namespace Branch.Services.Identity.App +{ + public partial class Application + { + private readonly string XblRedisKey = "identity:xbox-live"; + + public async Task GetXblIdentity(HttpContext ctx, GetXblIdentityReq req) + { + var useCache = !req.IgnoreCache; + + using (var client = _redisClientsManager.GetClient()) + { + return new GetXblIdentityRes + { + CacheInfo = null, + }; + } + } + } +} diff --git a/dotnet/Services/Identity/Models/Config.cs b/dotnet/Services/Identity/Models/Config.cs new file mode 100644 index 00000000..220a57fc --- /dev/null +++ b/dotnet/Services/Identity/Models/Config.cs @@ -0,0 +1,18 @@ +namespace Branch.Services.Identity.Models +{ + public class Config + { + public string[] InternalKeys { get; set; } + + public string RedisConnectionString { get; set; } + + public static Config CreateDefault() + { + return new Config + { + InternalKeys = new string[] {"test"}, + RedisConnectionString = "redis://127.0.0.1:6379?db=1", + }; + } + } +} diff --git a/dotnet/Services/Identity/README.md b/dotnet/Services/Identity/README.md new file mode 100644 index 00000000..a2878387 --- /dev/null +++ b/dotnet/Services/Identity/README.md @@ -0,0 +1,42 @@ +# service-identity + +BaseURL: https://service-identity.branch.golf/1 + +## Versions + +- `preview`: Service created + +## Api + +### Index + +- `get_xbl_identity` + +### Methods + +#### `get_xbl_identity` + +##### Request + +```json +{ + "type": "gamertag", + "value": "PhoenixBanTrain" +} +``` + +The `type` key can be either `gamertag`, or `xuid`. + +##### Response + +```json +{ + "cache_overview": { + "cached_at": "2020-04-26T23:00:02.168Z", + "expires_at": "2020-04-26T23:15:13.614Z" + }, + "gamertag": "xxCoLLaTeRaLx", + "xuid": 2533274824126595 +} +``` + diff --git a/dotnet/Services/Identity/Server/GetXblIdentity.cs b/dotnet/Services/Identity/Server/GetXblIdentity.cs new file mode 100644 index 00000000..69471221 --- /dev/null +++ b/dotnet/Services/Identity/Server/GetXblIdentity.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; + +namespace Branch.Services.Identity.Server +{ + public partial class RpcServer : IIdentityService + { + public readonly string GetXblIdentitySchema = @" + { + ""type"": ""object"", + ""additionalProperties"": false, + + ""required"": [ + ""type"", + ""value"" + ], + + ""properties"": { + ""ignore_cache"": { + ""type"": ""boolean"" + }, + + ""type"": { + ""type"": ""string"", + ""enum"": [""gamertag"", ""xuid""] + }, + + ""value"": { + ""type"": ""string"", + ""minLength"": 1 + }, + } + } + "; + + public Task GetXblIdentity(HttpContext ctx, GetXblIdentityReq req) + { + return _app.GetXblIdentity(ctx, req); + } + } +} diff --git a/dotnet/Services/Identity/Server/RpcServer.cs b/dotnet/Services/Identity/Server/RpcServer.cs new file mode 100644 index 00000000..52e2cf67 --- /dev/null +++ b/dotnet/Services/Identity/Server/RpcServer.cs @@ -0,0 +1,14 @@ +using Branch.Services.Identity.App; + +namespace Branch.Services.Identity.Server +{ + public partial class RpcServer : IIdentityService + { + private Application _app; + + public RpcServer(Application app) + { + _app = app; + } + } +} diff --git a/dotnet/Services/Identity/Service.cs b/dotnet/Services/Identity/Service.cs new file mode 100644 index 00000000..6f125f70 --- /dev/null +++ b/dotnet/Services/Identity/Service.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; +using Branch.Global.Contracts; +using Microsoft.AspNetCore.Http; + +namespace Branch.Services.Identity +{ + public interface IIdentityService + { + Task GetXblIdentity(HttpContext ctx, GetXblIdentityReq req); + } + + public class GetXblIdentityReq + { + public bool IgnoreCache { get; set; } + + public string Type { get; set; } + + public string Value { get; set; } + } + + public class GetXblIdentityRes : IBranchResponse + { + public CacheInfo CacheInfo { get; set; } + + public string Gamertag { get; set; } + + public string Xuid { get; set; } + } +} diff --git a/dotnet/Services/Identity/Startup.cs b/dotnet/Services/Identity/Startup.cs new file mode 100644 index 00000000..aad85289 --- /dev/null +++ b/dotnet/Services/Identity/Startup.cs @@ -0,0 +1,58 @@ +using System.Threading.Tasks; +using Branch.Global.Attributes; +using Branch.Services.Identity.App; +using Branch.Services.Identity.Models; +using Branch.Services.Identity.Server; +using Crpc; +using Crpc.Registration; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using ServiceStack.Redis; + +namespace Branch.Services.Identity +{ + public class Startup + { + public IConfiguration Configuration { get; } + + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public void ConfigureServices(IServiceCollection services) + { + services.Configure(Configuration); + + var redisConnectionString = Configuration.GetSection("RedisConnectionString").Get(); + + services.AddSingleton(new BasicRedisClientManager(redisConnectionString)); + + services.AddCrpc(opts => + { + opts.InternalKeys = Configuration.GetSection("InternalKeys").Get(); + }); + } + + public void Configure(IApplicationBuilder app) + { + app.UseCrpcHealthCheck(); + app.UseCrpc("/1", (c, s) => { + c.Authentication = AuthenticationType.AllowInternalAuthentication; + + c.Register( + "get_xbl_identity", "preview", s.GetXblIdentity, s.GetXblIdentitySchema + ); + }); + } + + [ServiceEntry("service-identity")] + public static async Task Entry(string[] args) => + await CrpcHost.CreateCrpcHost(Config.CreateDefault()) + .UseConsoleLifetime() + .Build() + .RunAsync(); + } +}