|
@@ -48,42 +48,38 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
return Ok(new { apis });
|
|
|
}
|
|
|
/// <summary>
|
|
|
- /// {"code":"hbcn学校编码"}
|
|
|
+ /// {"id":"uuid","code":"hbcn学校编码"}
|
|
|
/// </summary>
|
|
|
/// <param name="requert"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "admin")]
|
|
|
[HttpPost("create-token")]
|
|
|
- public async Task<IActionResult> CreateToken(OpenApp request) {
|
|
|
+ public async Task<IActionResult> CreateToken(JsonElement request) {
|
|
|
try
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- request.pk = "OpenApp";
|
|
|
- request.code = request.pk + "-" + request.code;
|
|
|
- request.ttl = -1;
|
|
|
- if (string.IsNullOrEmpty(request.id))
|
|
|
- {
|
|
|
- return BadRequest();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
|
|
|
+ //id
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ //
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(id.GetString(), new PartitionKey($"OpenApp-{code}")) ;
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
- //创建Token
|
|
|
- var auth_token = JwtAuthExtension.CreateAppToken(_option.HostName, request.id, _option.JwtSecretKey, request.school);
|
|
|
+
|
|
|
using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
var info = json.ToObject<OpenApp>();
|
|
|
+ //创建Token
|
|
|
+ var auth_token = JwtAuthExtension.CreateAppToken(_option.HostName, info.id, _option.JwtSecretKey, info.school);
|
|
|
info.token = auth_token;
|
|
|
- request = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(info, info.id, new PartitionKey($"{info.code}"));
|
|
|
+ info = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(info, info.id, new PartitionKey($"{info.code}"));
|
|
|
+ return Ok(auth_token);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return BadRequest();
|
|
|
}
|
|
|
- }
|
|
|
- return Ok(new { app = request });
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|