public void SystemTokenThrows() { SelectExpandPathToStringVisitor visitor = new SelectExpandPathToStringVisitor(); SystemToken systemToken = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => systemToken.Accept(visitor); visitSystemToken.ShouldThrow<NotSupportedException>().WithMessage(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It)); }
public void SystemTokenThrows() { RemoveWildcardVisitor visitor = new RemoveWildcardVisitor(); SystemToken token = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => token.Accept(visitor); visitSystemToken.ShouldThrow<NotSupportedException>().WithMessage(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It)); }
public void SystemTokensThrowNotSupportedError() { AddNewEndingTokenVisitor visitor = new AddNewEndingTokenVisitor(new NonSystemToken("stuff", null, null)); SystemToken token = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => token.Accept(visitor); visitSystemToken.ShouldThrow<NotSupportedException>().WithMessage(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It)); }
private static SuperIdToken GetSystemUserToken(string systemTokenString, string contextIdentifier) { // Grab hold of the system user token var systemToken = new SystemToken(systemTokenString); // Get certificate var certificatePath = ConfigManager.ApplicationKeyFile; if (!Path.IsPathRooted(certificatePath)) { certificatePath = Path.Combine(HostingEnvironment.MapPath(@"~"), certificatePath); } // sign the system user token var signedSystemToken = systemToken.Sign(privateKey: File.ReadAllText(certificatePath)); // Call the web service to exchange signed system user token with claims for the system user var federationGateway = ConfigManager.SoFederationGateway; var returnedToken = systemToken.AuthenticateWithSignedSystemToken(federationGateway, signedSystemToken, ConfigFile.Services.ApplicationToken, contextIdentifier, TokenType.Jwt); // Validate SuperId token for the system user var systemUserTokenHandler = new SuperIdTokenHandler(); var systemUserToken = systemUserTokenHandler.ValidateToken(returnedToken, TokenType.Jwt); return(systemUserToken); }
/// <summary> /// Get and validate claims for the system user from the SuperID web service /// </summary> /// <param name="userToken">System user token, not yet signed</param> /// <param name="contextIdentifier">Context identifier of the customer</param> /// <returns>Token with claims</returns> private static SuperIdToken GetSystemUserToken(string userToken, string contextIdentifier) { var systemToken = new SystemToken(userToken); // Get certificate var certificatePath = CertificatePath; // sign the system user token var signedSystemToken = systemToken.Sign(privateKey: File.ReadAllText(certificatePath)); // Call the web service to exchange signed system user token with claims for the system user var federationGateway = ConfigurationManager.AppSettings["SoFederationGateway"]; var returnedToken = systemToken.AuthenticateWithSignedSystemToken(federationGateway, signedSystemToken, ConfigFile.Services.ApplicationToken, contextIdentifier, TokenType.Saml); // Validate and return SuperId token for the system user var tokenHandler = new SuperIdTokenHandler(); tokenHandler.IssuerTokenResolver = new SuperOffice.SuperID.Client.Tokens.CertificateFileCertificateStoreTokenResolver( System.Web.HttpContext.Current.Server.MapPath("~/App_Data") ); tokenHandler.CertificateValidator = System.IdentityModel.Selectors.X509CertificateValidator.None; return(tokenHandler.ValidateToken(returnedToken, TokenType.Saml)); }
public void SystemTokensThrowNotSupportedError() { AddNewEndingTokenVisitor visitor = new AddNewEndingTokenVisitor(new NonSystemToken("stuff", null, null)); SystemToken token = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => token.Accept(visitor); visitSystemToken.ShouldThrow <NotSupportedException>().WithMessage(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It)); }
public static AndConstraint <SystemToken> ShouldBeSystemToken(this PathSegmentToken token, string tokenIdentifier) { token.Should().BeOfType <SystemToken>(); SystemToken systemToken = token.As <SystemToken>(); systemToken.Identifier.Should().Be(tokenIdentifier); return(new AndConstraint <SystemToken>(systemToken)); }
public void SystemTokenThrows() { SelectExpandPathToStringVisitor visitor = new SelectExpandPathToStringVisitor(); SystemToken systemToken = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => systemToken.Accept(visitor); visitSystemToken.ShouldThrow <NotSupportedException>().WithMessage(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It)); }
public static SystemToken ShouldBeSystemToken(this PathSegmentToken token, string tokenIdentifier) { Assert.NotNull(token); SystemToken systemToken = Assert.IsType <SystemToken>(token); Assert.Equal(tokenIdentifier, systemToken.Identifier); return(systemToken); }
public void SystemTokenThrows() { SelectExpandPathToStringVisitor visitor = new SelectExpandPathToStringVisitor(); SystemToken systemToken = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => systemToken.Accept(visitor); NotSupportedException exception = Assert.Throws <NotSupportedException>(visitSystemToken); Assert.Equal(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It), exception.Message); }
public void SystemTokenThrows() { RemoveWildcardVisitor visitor = new RemoveWildcardVisitor(); SystemToken token = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => token.Accept(visitor); NotSupportedException exception = Assert.Throws <NotSupportedException>(visitSystemToken); Assert.Equal(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It), exception.Message); }
public void SystemTokensThrowNotSupportedError() { AddNewEndingTokenVisitor visitor = new AddNewEndingTokenVisitor(new NonSystemToken("stuff", null, null)); SystemToken token = new SystemToken(ExpressionConstants.It, null); Action visitSystemToken = () => token.Accept(visitor); NotSupportedException exception = Assert.Throws <NotSupportedException>(visitSystemToken); Assert.Equal(Strings.ALinq_IllegalSystemQueryOption(ExpressionConstants.It), exception.Message); }
public static SuperIdToken GetSystemUserToken(string userToken, string contextIdentifier, string privateKey, string federationGateway, string applicationToken, string certificateString) { var tokenType = SuperOffice.SuperID.Contracts.SystemUser.V1.TokenType.Jwt; var systemToken = new SystemToken(userToken); // Get certificate // sign the system user ticket var signedSystemToken = systemToken.Sign(privateKey); // Call the web service to exchange signed system user ticket with claims for the system user var returnedToken = systemToken.AuthenticateWithSignedSystemToken(federationGateway, signedSystemToken, applicationToken, contextIdentifier, tokenType); if (returnedToken != null) { // Validate and return SuperId ticket for the system user var tokenHandler = new SuperIdTokenHandler(); var certificateResolverPath = AppDomain.CurrentDomain.BaseDirectory + "Certificates"; if (tokenType == SuperOffice.SuperID.Contracts.SystemUser.V1.TokenType.Saml) { tokenHandler.CertificateValidator = System.IdentityModel.Selectors.X509CertificateValidator.None; tokenHandler.IssuerTokenResolver = new CertificateFileCertificateStoreTokenResolver(certificateResolverPath); } else { // byte[] bytes = System.Convert.FromBase64String(certificateString); byte[] bytes = Encoding.ASCII.GetBytes(certificateString); tokenHandler.JwtIssuerSigningCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(bytes); } tokenHandler.ValidateAudience = false; SuperIdToken superToken = null; try { superToken = tokenHandler.ValidateToken(returnedToken, tokenType); } catch (Exception e) { Console.WriteLine(e); } return(superToken); } return(null); }
public async Task <SystemToken> JSWecharTokenList(string TokenType, SystemTokenIn accesstoken) { var SystemTokens = _repository.GetAll().Where(a => a.IsDelete == false && a.TokenType == TokenType).OrderByDescending(a => a.CreatedOn); var TokenInfos = await SystemTokens.ToListAsync(); var TokenInfo = TokenInfos.FirstOrDefault(); if (TokenInfo != null) { // 如果数据超时了重新获取 if (TokenInfo.EffectiveTime <= DateTime.Now.AddMinutes(5)) { var Tokens = await tencentToken.TencentTicket("jsapi", accesstoken.access_token); TokenInfo.access_token = Tokens.ticket; TokenInfo.EffectiveLength = Tokens.expires_in; TokenInfo.EffectiveTime = DateTime.Now.AddSeconds(TokenInfo.EffectiveLength); TokenInfo.TokenJson = JsonHelper.ToJson(Tokens); TokenInfo.RefreshEffectiveTime = DateTime.Now; TokenInfo = await _repository.UpdateAsync(TokenInfo); } if (string.IsNullOrEmpty(TokenInfo.access_token)) { var Tokens = await tencentToken.TencentTicket("jsapi", accesstoken.access_token); TokenInfo.access_token = Tokens.ticket; TokenInfo.EffectiveLength = Tokens.expires_in; TokenInfo.EffectiveTime = DateTime.Now.AddSeconds(TokenInfo.EffectiveLength); TokenInfo.TokenJson = JsonHelper.ToJson(Tokens); TokenInfo.RefreshEffectiveTime = DateTime.Now; TokenInfo = await _repository.UpdateAsync(TokenInfo); } } else { // 当没数据时先获取数据再保存 var Tokens = await tencentToken.TencentTicket("jsapi", accesstoken.access_token); TokenInfo = new SystemToken(); TokenInfo.access_token = Tokens.ticket; TokenInfo.EffectiveLength = Tokens.expires_in; TokenInfo.EffectiveTime = DateTime.Now.AddSeconds(TokenInfo.EffectiveLength); TokenInfo.TokenJson = JsonHelper.ToJson(Tokens); TokenInfo.TokenType = TokenType; TokenInfo.YaeherPlatform = accesstoken.YaeherPlatform; TokenInfo.Appid = accesstoken.Appid; TokenInfo.AppSecret = accesstoken.AppSecret; TokenInfo.RefreshEffectiveTime = DateTime.Now; TokenInfo.Id = await _repository.InsertAndGetIdAsync(TokenInfo); } return(TokenInfo); }
/// <summary> /// Reverse a SystemToken /// </summary> /// <param name="tokenIn">the SystemToken to reverse</param> /// <returns>the reversed SystemToken</returns> public override PathSegmentToken Visit(SystemToken tokenIn) { ExceptionUtils.CheckArgumentNotNull(tokenIn, "tokenIn"); if (tokenIn.NextToken != null) { SystemToken newNonSystemToken = new SystemToken(tokenIn.Identifier, this.childToken); return(BuildNextStep(tokenIn.NextToken, newNonSystemToken)); } else { return(new SystemToken(tokenIn.Identifier, this.childToken)); } }
/// <summary> /// Get and validate claims for the system user from the SuperID web service /// </summary> /// <param name="userToken">System user token, not yet signed</param> /// <param name="contextIdentifier">Context identifier of the customer</param> /// <returns>Token with claims</returns> private static SuperIdToken GetSystemUserToken(string userToken, string contextIdentifier) { var tokenType = SuperOffice.SuperID.Contracts.SystemUser.V1.TokenType.Jwt; var systemToken = new SystemToken(userToken); // Get certificate var certificatePath = ConfigurationManager.AppSettings["SystemTokenCertificatePath"]; // sign the system user token var signedSystemToken = systemToken.Sign(File.ReadAllText(certificatePath)); // Call the web service to exchange signed system user token with claims for the system user var federationGateway = ConfigurationManager.AppSettings["SoFederationGateway"]; var returnedToken = systemToken.AuthenticateWithSignedSystemToken(federationGateway, signedSystemToken, ConfigFile.Services.ApplicationToken, contextIdentifier, tokenType); if (returnedToken != null) { // Validate and return SuperId token for the system user var tokenHandler = new SuperIdTokenHandler(); var certificateResolverPath = AppDomain.CurrentDomain.BaseDirectory + "Certificates"; if (tokenType == SuperID.Contracts.SystemUser.V1.TokenType.Saml) { tokenHandler.CertificateValidator = System.IdentityModel.Selectors.X509CertificateValidator.None; tokenHandler.IssuerTokenResolver = new SuperOffice.SuperID.Client.Tokens.CertificateFileCertificateStoreTokenResolver(certificateResolverPath); } else { tokenHandler.JwtIssuerSigningCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2( certificateResolverPath + "\\SODSuperOfficeFederatedLogin.crt"); } tokenHandler.ValidateAudience = false; return(tokenHandler.ValidateToken(returnedToken, tokenType)); } return(null); }
/// <summary> /// 获取微信IP地址 /// </summary> /// <param name="systemToken"></param> /// <returns></returns> public async Task <WechaIP> WeCharIP(SystemToken systemToken) { try { string url = "https://api.weixin.qq.com/cgi-bin/getcallbackip?"; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(url); stringBuilder.Append("&access_token=" + systemToken.access_token); string Url = "http://admin." + systemToken.YaeherPlatform + ".com/api/TestWechar"; // 拼拼接访问url var body = "{\"url\":\"" + stringBuilder.ToString() + "\",\"content\":\"\"}"; var AccessToken = await httpHelper.PostResponseAsync(Url, body); return(JsonHelper.FromJson <WechaIP>(AccessToken)); } catch (Exception ex) { return(new WechaIP()); } }
/// <summary> /// TencentToken /// </summary> /// <returns></returns> public async Task <TencentTokens> TencentAccessToken(SystemToken systemToken) { try { string grant_type = "client_credential"; string appid = systemToken.Appid; string secret = systemToken.AppSecret; string url = "https://api.weixin.qq.com/cgi-bin/token?"; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(url); stringBuilder.Append("&grant_type=" + grant_type); stringBuilder.Append("&appid=" + appid); stringBuilder.Append("&secret=" + secret); string Url = "http://admin." + systemToken.YaeherPlatform + ".com/api/TestWechar"; // 拼拼接访问url var body = "{\"url\":\"" + stringBuilder.ToString() + "\",\"content\":\"\"}"; var AccessToken = await httpHelper.PostResponseAsync(Url, body); return(JsonHelper.FromJson <TencentTokens>(AccessToken)); } catch (Exception ex) { return(new TencentTokens()); } }
/// <summary> /// Translate a SystemToken, this is illegal so this always throws. /// </summary> /// <param name="tokenIn">The SystemToken to translate.</param> public void Visit(SystemToken tokenIn) { throw new NotSupportedException(Strings.ALinq_IllegalSystemQueryOption(tokenIn.Identifier)); }
public void IsNamespaceOrContainerQualifiedIsFalse() { SystemToken token = new SystemToken("more stuff", null); Assert.False(token.IsNamespaceOrContainerQualified()); }
public void IdentifierSetCorrectly() { SystemToken token = new SystemToken("stuff", null); token.Identifier.Should().Be("stuff"); }
/// <summary> /// Visit a System Token /// </summary> /// <param name="tokenIn">the system token to visit</param> public override void Visit(SystemToken tokenIn) { ExceptionUtils.CheckArgumentNotNull(tokenIn, "tokenIn"); throw new ODataException(ODataErrorStrings.SelectPropertyVisitor_SystemTokenInSelect(tokenIn.Identifier)); }
public void IsNamespaceOrContainerQualifiedIsFalse() { SystemToken token = new SystemToken("more stuff", null); token.IsNamespaceOrContainerQualified().Should().BeFalse(); }
/// <summary> /// Traverse a SystemToken. Always throws because a SystemToken is illegal in this case. /// </summary> /// <param name="tokenIn">The system token to traverse</param> public void Visit(SystemToken tokenIn) { throw new NotSupportedException(Strings.ALinq_IllegalSystemQueryOption(tokenIn.Identifier)); }
/// <summary> /// Visit an SystemToken /// </summary> /// <param name="tokenIn">The System token to visit</param> /// <returns>A user defined class</returns> public virtual T Visit(SystemToken tokenIn) { throw new NotImplementedException(); }
/// <summary> /// 公众号关注事件 /// </summary> /// <param name="requestDoc"></param> /// <returns></returns> public async Task <ObjectResultModule> FocusOn(XDocument requestDoc) { SystemToken systemToken = new SystemToken(); TencentUserManage usermanage = new TencentUserManage(); TencentWXPay tencentWXPay = new TencentWXPay(); using (var unitOfWork = _unitOfWorkManager.Begin()) { try { //关注 var openid = JsonHelper.GetXmlValue(requestDoc, "FromUserName"); if (openid == null) { return(new ObjectResultModule("", 401, "")); } // systemToken.TokenType = "Wechar"; var Tokens = _systemTokenService.SystemTokenList("Wechar").Result; string access_token = Tokens.access_token; var usermsg = usermanage.WeiXinUserInfoUtils(openid, Tokens.access_token).Result; if (usermsg.subscribe != 0) { #region 步操作 //var UserInfo = _yaeherUserService.YaeherUserInfo(openid, Tokens.access_token); //if (UserInfo.Id > 0) //{ // UserInfo= await usermanage.YaeherUserLable(usermsg,UserInfo,Tokens.access_token); // if (!UserInfo.IsPay) // { // var payment = await _yaeherUserPaymentService.YaeherUserPaymentByUserID(UserInfo.Id); // if (payment == null || payment.Id < 1) // { // //http请求微信信息,获取账户的信息 新增用户payment // var CreateUserPayment = new YaeherUserPayment() // { // UserID = UserInfo.Id, // FullName = UserInfo.FullName, // PayMethod = "wxpay", // PayMethodName = "微信支付", // PaymentAccout = UserInfo.WecharName, // BankName = "wx", // Subbranch = "wx", // BandAdd = "wx", // BankNo = "wx", // CreatedOn = DateTime.Now, // IsDefault = true, // }; // CreateUserPayment = await _yaeherUserPaymentService.CreateYaeherUserPayment(CreateUserPayment); // } // UserInfo.IsPay = true; // } // if (!UserInfo.IsUpdate) // { // var DoctorInfo = await _yaeherDoctorService.YaeherDoctorByUserID(UserInfo.Id); // if (DoctorInfo != null && DoctorInfo.IsSharing && UserInfo.IsProfitSharing == false) //医生角色切没有生成分账账号 // { // //查询分账配置 // SystemConfigsIn systemConfigsIn = new SystemConfigsIn(); // systemConfigsIn.AndAlso(a => a.IsDelete == false); // systemConfigsIn.AndAlso(a => a.SystemType == "TencentWechar"); // var configs = _systemConfigsService.SystemConfigsList(systemConfigsIn).Result; // // 查询医生信息 // var tencentparam = configs.ToList().FirstOrDefault(); // var receiver = new receiver(); // receiver.name = DoctorInfo.DoctorName; // receiver.type = "PERSONAL_OPENID"; // receiver.account = openid; // var addresult = tencentWXPay.ProfitSharingAddReceiver(receiver, tencentparam).Result; // if (addresult.result_code == "SUCCESS") //插入成功后更新状态 // { // UserInfo.IsProfitSharing = true; // } // } // } // UserInfo = await _yaeherUserService.UpdateYaeherUser(UserInfo); //} #endregion string OperType = "用户关注"; var UserInfo = await _yaeherUserService.YaeherUserInfo(usermsg, access_token, OperType); } StringBuilder Contentsb = new StringBuilder(); // 增加问医生 Contentsb.Append("欢迎关注怡禾健康!"); Contentsb.Append("\n"); Contentsb.Append("\n"); // 增加问医生 Contentsb.Append("<a href=\"" + Commons.WecharWeb + "?link=index-patient\">问医生</a>\n"); // 增加听课程 Contentsb.Append("\n"); Contentsb.Append("<a href=\"https://m.qlchat.com/wechat/page/live/210000155031160\">听课程</a>\n"); var textSingleMessage = new TextSingleMessage() { ToUser = openid, TextContent = Contentsb.ToString() == null ? "欢迎关注怡禾健康!" : Contentsb.ToString() }; textSingleMessage.Send(access_token).ToString(); unitOfWork.Complete(); } catch (Exception ex) { Logger.Info("我的一个关注的错误:" + ex.ToString() + "DateTime:" + DateTime.Now); } } return(new ObjectResultModule("", 200, "")); }
public void IdentifierSetCorrectly() { SystemToken token = new SystemToken("stuff", null); Assert.Equal("stuff", token.Identifier); }