Commit ab70f537 by ruyun.zhang

授权修改

parent a7f8bcb7
using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;
using System;
using Microsoft.AspNetCore.Mvc;
using Performance.DtoModels;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Performance.Services;
using Microsoft.Extensions.Configuration;
namespace Performance.Api.Controllers
{
public class AppController : Controller
{
private readonly ILogger<AppController> _logger;
private readonly IConfiguration _configuration;
public AppController(ILogger<AppController> logger, IConfiguration configuration)
{
_logger = logger;
_configuration = configuration;
}
[AllowAnonymous, HttpGet, Route("api/app/options")]
public ActionResult AppOptions()
{
var OpenOAuth = _configuration.GetValue<bool>("AppOptions:OpenOAuth", false);
return Ok(new ApiResponse(ResponseType.OK, "", new { OpenOAuth }));
}
}
}
\ No newline at end of file
using System;
using System.Net;
using System.Security.Claims;
using System.Security.Policy;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
......@@ -35,14 +36,14 @@ public OAuthController(ILogger<OAuthController> logger, IOptions<Application> op
_logger.LogInformation("OAuth授权启动");
try
{
var res = await _service.Authorize();
return (res.StatusCode == (int)HttpStatusCode.OK) ? Ok() : BadRequest();
var url = await _service.Authorize();
return Ok(new ApiResponse(ResponseType.OK, "", url));
}
catch (Exception ex)
{
_logger.LogError($"OAuth授权启动:请求异常={ex}");
}
return BadRequest();
return Ok(new ApiResponse(ResponseType.Fail, ""));
}
/// <summary>
......
......@@ -10,6 +10,9 @@
"PerformanceConnectionString": "server=192.168.18.166;database=db_test_beiliu;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
//"PerformanceConnectionString": "server=116.62.245.55;database=db_performance;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
},
"AppOptions": {
"OpenOAuth": true
},
"oauth2": {
"authorize_url": "http://192.168.18.166:8038/oauth2/authorize",
"token_url": "http://192.168.18.166:8038/oauth2/token",
......
......@@ -64,6 +64,16 @@
开启反SQL注入白名单地址
</summary>
</member>
<member name="T:Performance.DtoModels.AppSettings.AppSQLEncrypt">
<summary>
数据库密码加密
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.AppSQLEncrypt.IsEncryption">
<summary>
是否加密 true 加密 false 明文
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.RateLimitingConfig.Endpoints">
<summary>
路径
......
......@@ -42,7 +42,7 @@ public class OAuthService : IAutoInjection
_hospitalRepository = hospitalRepository;
}
public async Task<OAuthResponse<IOAuthResponse>> Authorize()
public async Task<string> Authorize()
{
_logger.LogInformation("OAuth授权启动");
try
......@@ -66,27 +66,13 @@ public class OAuthService : IAutoInjection
_logger.LogInformation($"OAuth授权启动:authorize_url={url}");
var response = await client.GetAsync(url);
var resContent = await response.Content.ReadAsStringAsync();
_logger.LogInformation($"OAuth授权启动:响应状态:{(int)response.StatusCode};{resContent}");
if (response.StatusCode != System.Net.HttpStatusCode.OK)
{
var data = await response.Content.ReadFromJsonAsync<OAuthErrorResponse>();
_logger.LogInformation($"OAuth授权启动:请求结果={data}");
return new OAuthResponse<IOAuthResponse>((int)response.StatusCode, data);
}
else
{
_logger.LogInformation($"OAuth授权启动:请求成功");
return new OAuthResponse<IOAuthResponse>((int)response.StatusCode, null);
}
return url;
}
catch (Exception ex)
{
_logger.LogError($"OAuth授权启动:请求异常:{ex}");
}
return new OAuthResponse<IOAuthResponse>((int)HttpStatusCode.InternalServerError, null);
return "";
}
public async Task<OAuthResponse<IOAuthResponse>> Token(string code, string state)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment