public override Task <TokenResponseDTO> GetByCode(CodeExchangeTokenRequestDTO request, ServerCallContext context) { return(Task.Run(() => { TokenResponseDTO response = new TokenResponseDTO(); OpenOAuthProvider provider = new OpenOAuthProvider(request.Appid, request.Secret, request.Code, request.GrantType); if (!provider.OAuthAccess()) { response.RetCode = "0500"; response.RetMsg = provider.PromptInfo.CustomMessage; return response; } response.RetCode = "0000"; response.RetMsg = "ok"; response.Data = new TokenResponseDTO.Types.Result { Expires = provider.OAuthUser.Expire_In, Openid = provider.OAuthUser.Open_Id, RefreshExpires = provider.OAuthUser.Refresh_Expire_In, RefreshToken = provider.OAuthUser.Refresh_Token, Token = provider.OAuthUser.Token }; return response; })); }
/// <summary> /// 获取用户OPEN_ID /// </summary> /// <param name="appid"></param> /// <param name="secret"></param> /// <param name="code"></param> /// <param name="state"></param> /// <param name="grant_type"></param> /// <returns></returns> public ActionResult AccessToken(string appid, string secret, string code, string state, string grant_type) { OpenOAuthProvider provider = new OpenOAuthProvider(appid, secret, code, grant_type); if (!provider.OAuthAccess()) { var res = FailResult(provider.PromptInfo.CustomMessage); res.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return(res); } var suc = SuccessResult(provider.OAuthUser); suc.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return(suc); }
public ResponseResult <TokenResponseDTO> GetByCode(CodeExchangeTokenRequestDTO request) { OpenOAuthProvider provider = new OpenOAuthProvider(request.Appid, request.Secret, request.Code, request.GrantType); if (!provider.OAuthAccess()) { return(Fail <TokenResponseDTO>(provider.PromptInfo.CustomMessage)); } TokenResponseDTO response = new TokenResponseDTO { Expires = provider.OAuthUser.Expire_In, Openid = provider.OAuthUser.Open_Id, RefreshExpires = provider.OAuthUser.Refresh_Expire_In, RefreshToken = provider.OAuthUser.Refresh_Token, Token = provider.OAuthUser.Token }; return(Success(response)); }