70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using New_College.AuthHelper.OverWrite;
|
|
using New_College.Common;
|
|
using New_College.Common.Helper;
|
|
using New_College.Model;
|
|
using New_College.Model.ViewModels;
|
|
using NPOI.SS.Formula.Functions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace New_College.Controllers
|
|
{
|
|
|
|
[AllowAnonymous]
|
|
[Route("api/oauth")]
|
|
public class OauthController : Controller
|
|
{
|
|
|
|
public OauthController()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///Oauth2验证回调
|
|
/// </summary>
|
|
/// <param name="code"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("callback")]
|
|
public async Task<MessageModel<string>> Callback(string code, string state)
|
|
{
|
|
string jwtStr = string.Empty;
|
|
bool suc = false;
|
|
|
|
var gettoken = CasdoorHttpHelper.Post_AccessToken<CasdoorGetTokenResponse>(code);
|
|
//var user = await _sysUserInfoServices.GetUserRoleNameStr(name, MD5Helper.MD5Encrypt32(pass));
|
|
//if (user != null)
|
|
//{
|
|
|
|
TokenModelJwt tokenModel = new TokenModelJwt { Uid = 1, Role = gettoken.access_token };
|
|
|
|
jwtStr = JwtHelper.IssueJwt(tokenModel);
|
|
suc = true;
|
|
//}
|
|
//else
|
|
//{
|
|
// jwtStr = "login fail!!!";
|
|
//}
|
|
|
|
|
|
return new MessageModel<string>()
|
|
{
|
|
success = suc,
|
|
msg = suc ? "success" : "fail",
|
|
response = jwtStr
|
|
};
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|