Ejemplo n.º 1
0
        public Guid GetUserID(string token)
        {
            Guid userID;

            try
            {
                IDictionary <string, object> tokenDic = JWTHelper.DecodeJWT(token, ApplicationConfig.IdentityServer.Secret);
                userID = Guid.Parse(tokenDic["sub"].ToString());
                if (userID == Guid.Empty)
                {
                    throw new InvalidOperationException("未找到用户ID");
                }
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Token错误", ex);
            }
            return(userID);
        }