This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4175a4
commit 9e1165a
Showing
8 changed files
with
250 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Config> options | ||
) | ||
{ | ||
_logger = loggerFactory.CreateLogger(typeof(Application)); | ||
_redisClientsManager = redisClientsManager; | ||
_config = options.CurrentValue; | ||
} | ||
} | ||
} |
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,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<GetXblIdentityRes> GetXblIdentity(HttpContext ctx, GetXblIdentityReq req) | ||
{ | ||
var useCache = !req.IgnoreCache; | ||
|
||
using (var client = _redisClientsManager.GetClient()) | ||
{ | ||
return new GetXblIdentityRes | ||
{ | ||
CacheInfo = null, | ||
}; | ||
} | ||
} | ||
} | ||
} |
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,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", | ||
}; | ||
} | ||
} | ||
} |
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,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 | ||
} | ||
``` | ||
|
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,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<GetXblIdentityRes> GetXblIdentity(HttpContext ctx, GetXblIdentityReq req) | ||
{ | ||
return _app.GetXblIdentity(ctx, req); | ||
} | ||
} | ||
} |
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,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; | ||
} | ||
} | ||
} |
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,29 @@ | ||
using System.Threading.Tasks; | ||
using Branch.Global.Contracts; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Branch.Services.Identity | ||
{ | ||
public interface IIdentityService | ||
{ | ||
Task<GetXblIdentityRes> 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; } | ||
} | ||
} |
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,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<Config>(Configuration); | ||
|
||
var redisConnectionString = Configuration.GetSection("RedisConnectionString").Get<string>(); | ||
|
||
services.AddSingleton<IRedisClientsManager>(new BasicRedisClientManager(redisConnectionString)); | ||
|
||
services.AddCrpc<Application, RpcServer>(opts => | ||
{ | ||
opts.InternalKeys = Configuration.GetSection("InternalKeys").Get<string[]>(); | ||
}); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.UseCrpcHealthCheck(); | ||
app.UseCrpc<RpcServer>("/1", (c, s) => { | ||
c.Authentication = AuthenticationType.AllowInternalAuthentication; | ||
|
||
c.Register<GetXblIdentityReq, GetXblIdentityRes>( | ||
"get_xbl_identity", "preview", s.GetXblIdentity, s.GetXblIdentitySchema | ||
); | ||
}); | ||
} | ||
|
||
[ServiceEntry("service-identity")] | ||
public static async Task Entry(string[] args) => | ||
await CrpcHost.CreateCrpcHost<Startup>(Config.CreateDefault()) | ||
.UseConsoleLifetime() | ||
.Build() | ||
.RunAsync(); | ||
} | ||
} |