Former-commit-id: f133576a16388cccbbf5dc41882b2734eaaf8b9c
Former-commit-id: 24fd458e15ff925ae8ee90c3120454ef3fd9c900
1.0
wanggang 4 years ago
parent a1172d8140
commit 524a4a8e46

@ -19,7 +19,7 @@ namespace Infrastructure.Extensions
public static Guid? GetOrganId(this ClaimsPrincipal user)
{
var value = user?.Claims?.FirstOrDefault(o => o.Type == "OrganId")?.Value;
return Guid.TryParse(value, out Guid id) ? id : null;
return value == null ? null : Guid.Parse(value);
}
}
}

@ -301,7 +301,7 @@ namespace Infrastructure.Web
else
{
var jwtCookieName = context.HttpContext.GetJwtCookieName();
if (!context.Request.Headers.ContainsKey("Authorization") && context.Request.Cookies.Keys.Contains(jwtCookieName))
if (context.Request.Cookies.Keys.Contains(jwtCookieName))
{
context.Token = context.Request.Cookies[jwtCookieName];
}

@ -13,6 +13,7 @@ using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;
using Microsoft.EntityFrameworkCore;
namespace Platform.Apis
{
@ -120,6 +121,15 @@ namespace Platform.Apis
return Unauthorized(ModelState.AddModelError("已过期"));
}
var userName = token.Claims.FirstOrDefault(o => o.Type == this._parameters.NameClaimType).Value;
var user = this._userRepo.Table()
.Include(o => o.OrganUsers)
.ThenInclude(o => o.Organ)
.FirstOrDefault(o => o.UserName == userName);
var userMainOrgan = user.OrganUsers.OrderByDescending(o => o.IsDefault).ThenBy(o => o.OrganId).FirstOrDefault();
var claims = new List<Claim> {
new Claim(this._parameters.NameClaimType, userName),
new Claim("OrganId", userMainOrgan.OrganId.ToString())
};
return Ok(CreateToken(userName));
}
catch (Exception ex)

@ -29,13 +29,14 @@ axios.interceptors.response.use(function (response) {
var data = '"' + store.state.token.refreshToken + '"';
return axios.post(url, data, { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
.then(function (response) {
store.commit('setToken', response.data);
store.commit('login', response.data);
error.config.headers['Authorization'] = 'Bearer ' + store.state.accessToken;
console.log('redo request after refresh token');
return axios(error.config);
})
.catch(function (error) {
if (error.response.status === 401) {
store.commit('logout', response.data);
console.log('refreshToken 已过期');
router.push('components/views/areas/default/login.vue');
}

Loading…
Cancel
Save