// *********************************************************************** // Assembly : OpenAuth.WebApi // Author : yubaolee // Created : 07-11-2016 // // Last Modified By : yubaolee // Last Modified On : 07-11-2016 // Contact : // File: CheckController.cs // *********************************************************************** using System; using System.Web.Http; using Infrastructure; using Infrastructure.Cache; using OpenAuth.App; using OpenAuth.App.SSO; using System.Web.Mvc; using OpenAuth.App.Response; namespace OpenAuth.WebApi.Areas.SSO.Controllers { /// /// sso验证 /// 其他站点通过后台Post来认证 /// 或使用静态类OpenAuth.App.SSO.AuthUtil访问 /// public class CheckController : ApiController { public AuthorizeApp _app { get; set; } private ObjCacheProvider _objCacheProvider = new ObjCacheProvider(); /// /// 检验token是否有效 /// /// The token. /// 备用参数. [System.Web.Mvc.HttpGet] public bool GetStatus(string token, string requestid = "") { if (_objCacheProvider.GetCache(token) != null) { return true; } return false; } /// /// 根据token获取用户及用户可访问的所有资源 /// /// /// 备用参数. [System.Web.Mvc.HttpGet] public UserWithAccessedCtrls GetUser(string token, string requestid = "") { string userName = GetUserName(token, requestid); if (!string.IsNullOrEmpty(userName)) { return _app.GetAccessedControls(userName); } return null; } /// /// 根据token获取用户名称 /// /// /// 备用参数. [System.Web.Mvc.HttpGet] public string GetUserName(string token, string requestid = "") { var user = _objCacheProvider.GetCache(token); if (user != null) { return user.UserName; } return string.Empty; } /// /// 登录接口 /// /// 登录参数 /// [System.Web.Mvc.HttpPost] public LoginResult Login(PassportLoginRequest request) { return SSOAuthUtil.Parse(request); } /// /// 注销登录 /// /// /// 备用参数. [System.Web.Mvc.HttpPost] public bool Logout(string token, string requestid="") { try { _objCacheProvider.Remove(token); return true; } catch (Exception) { return false; } } } }