/// <summary> /// 生成访问令牌 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccessToken GeneralTocken(SYSAccessTokenDTO accessToken) { //检查应用代码和密钥 var certificate = _certificateRepository.Get(item => item.ApiKey == accessToken.client_id && item.Secret == accessToken.client_secret); if (certificate.ID == null) { throw CFException.Create(STDAccessTokenResult.ClientIDOrSecretInvalid); } //验证授权码 var authorize = CacheService.Default.Get <SYSAuthorizeDTO>("STDAuthorizeDTO_" + accessToken.code); if (authorize.Equals(default(SYSAuthorizeDTO))) { throw CFException.Create(STDAccessTokenResult.CodeInvalid); } if (authorize.redirect_uri != accessToken.redirect_uri) { throw CFException.Create(STDAccessTokenResult.RedirectUriInvalid); } //验证用户登录 if (authorize.uid == null) { throw CFException.Create(STDAccessTokenResult.UIDInvalid); } //创建访问令牌 var token = new SYSAccessToken(certificate.SystemID.Value) //令牌有效期:2小时 { uid = authorize.uid.Value, scope = authorize.scope, }; return(token); }
/// <summary> /// 生成令牌 /// </summary> /// <param name="dto"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccessToken GeneralTocken(SYSAccessTokenDTO dto) { if (!Exist(dto.grant_type)) { throw CFException.Create(STDAccessTokenResult.GrantTypeInvalid); } try { //获得访问密钥 var auth = CreateAuth(dto.grant_type); var token = auth.GeneralTocken(dto); //保存访问密钥 var appToken = SaveToken(token); if (appToken.ID == null) { throw CFException.Create(STDAccessTokenResult.AccountNotFount); } return(token); } catch (DefinedException ex) { throw ex; } catch (Exception ex) { throw CFException.Create(STDAccessTokenResult.Fail, ex.Message, ex); } }
public SYSAccessToken GeneralTocken(SYSAccessTokenDTO accessToken) { //检查应用代码和密钥 var certificate = _certificateRepository.Get(item => item.ApiKey == accessToken.client_id && item.Secret == accessToken.client_secret); if (certificate.ID == null) { throw CFException.Create(STDAccessTokenResult.ClientIDOrSecretInvalid); } //创建访问令牌 var token = new SYSAccessToken(certificate.SystemID.Value); //令牌有效期:2小时 return(token); }
/// <summary> /// 生成更新令牌 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccessToken GeneralTocken(SYSAccessTokenDTO accessToken) { //检查更新令牌 var refreshToken = _tokenRepository.Get(item => item.RefreshToken == accessToken.refresh_token); if (refreshToken.ID == null) { throw CFException.Create(STDAccessTokenResult.ClientIDOrSecretInvalid); } //创建访问令牌 var token = new SYSAccessToken(refreshToken.SystemID.Value) { uid = refreshToken.PassportID, scope = refreshToken.Scope, }; return(token); }
/// <summary> /// 获取授权过的Access Token /// </summary> /// <param name="accessToken"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccessToken AccessToken(SYSAccessTokenDTO accessToken) { return(_tokenGenerator.GeneralTocken(accessToken)); }