private void HandleLogins(RestDataRequestMessage message, ref RestResponse response, RestRequestMessage request) { var loginMessage = message.GetMessage() as InitializeSession; var session = new SessionCredentials(loginMessage.PeerId, SessionKey.NewGuid()); var playerdata = new PlayerData(); playerdata.FillWithNewPlayer(loginMessage.PlayerId, new [] { "FreeForAll", "Captain", "Siege", "Duel", "TeamDeathMatch", "FreeForAll" }); playerdata.LastPlayerName = loginMessage.PlayerName; playerdata.LastGameTypes = new[] { "Captain" }; var user = new User { Id = session, QueuedMessages = new Queue <RestResponseMessage>(), PlayerData = playerdata }; this._context.Users.Add(user); var initializeSessionResponse = new InitializeSessionResponse(playerdata, _context.Status); response.FunctionResult = new RestDataFunctionResult(new LoginResult(session.PeerId, session.SessionKey, initializeSessionResponse)); response.UserCertificate = session.SessionKey.ToByteArray(); response.SetSuccessful(true, "ResultFromServerTask"); }
public async Task FromSessionCredentialsTest() { string xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <response> <control> <status>success</status> <senderid>testsenderid</senderid> <controlid>sessionProvider</controlid> <uniqueid>false</uniqueid> <dtdversion>3.0</dtdversion> </control> <operation> <authentication> <status>success</status> <userid>testuser</userid> <companyid>testcompany</companyid> <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp> </authentication> <result> <status>success</status> <function>getSession</function> <controlid>testControlId</controlid> <data> <api> <sessionid>fAkESesSiOnId..</sessionid> <endpoint>https://unittest.intacct.com/ia/xml/xmlgw.phtml</endpoint> </api> </data> </result> </operation> </response>"; HttpResponseMessage mockResponse1 = new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.OK, Content = new StringContent(xml) }; List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage> { mockResponse1, }; MockHandler mockHandler = new MockHandler(mockResponses); SdkConfig config = new SdkConfig() { SessionId = "fAkESesSiOnId..", EndpointUrl = "https://unittest.intacct.com/ia/xml/xmlgw.phtml", MockHandler = mockHandler, }; SessionCredentials sessionCreds = new SessionCredentials(config, senderCreds); SessionCredentials newSessionCreds = await provider.FromSessionCredentials(sessionCreds); Assert.AreEqual("fAkESesSiOnId..", newSessionCreds.SessionId); StringAssert.Equals("https://unittest.intacct.com/ia/xml/xmlgw.phtml", newSessionCreds.Endpoint); Assert.IsInstanceOfType(newSessionCreds.SenderCreds, typeof(SenderCredentials)); }
public void CredsFromArrayNoSessionTest() { SdkConfig config = new SdkConfig { SessionId = null }; SessionCredentials sessionCreds = new SessionCredentials(config, senderCreds); }
private static void writeToFile(SessionCredentials cred) { string serialized = JsonConvert.SerializeObject(cred); var storage = Mvx.Resolve <IMvxFileStore>(); storage.WriteFile(_credentialFileName, serialized); }
public static void LogIn(int userId, string username, string authToken) { cred = new SessionCredentials { username = username, user_id = userId, auth_token = authToken }; writeToFile(cred); }
public void CredsFromArrayNoEndpointTest() { ClientConfig config = new ClientConfig { SessionId = "faKEsesSiOnId..", EndpointUrl = "" }; SessionCredentials sessionCreds = new SessionCredentials(config, this.SenderCreds); Assert.Equal("faKEsesSiOnId..", sessionCreds.SessionId); Assert.Equal("https://api.intacct.com/ia/xml/xmlgw.phtml", sessionCreds.Endpoint.ToString()); }
public void CredsFromArrayNoEndpointTest() { SdkConfig config = new SdkConfig { SessionId = "faKEsesSiOnId..", EndpointUrl = null }; SessionCredentials sessionCreds = new SessionCredentials(config, senderCreds); Assert.AreEqual("faKEsesSiOnId..", sessionCreds.SessionId); StringAssert.Equals("https://api.intacct.com/ia/xml/xmlgw.phtml", sessionCreds.Endpoint); }
public static void LogIn(int userId, string username) { cred = new SessionCredentials { username = username, user_id = userId }; string serialized = JsonConvert.SerializeObject(cred); var storage = Mvx.Resolve <IMvxFileStore>(); storage.WriteFile(_credentialFileName, serialized); }
/// <summary> /// 进行证书类转换(从java 拷贝过来,感觉编译类型原因在dotnet 无用,目前做代码兼容保留) /// </summary> /// <param name="credentials">证书信息</param> /// <returns>证书信息</returns> protected Credentials SanitizeCredentials(Credentials credentials) { String accessKeyId = credentials.AccessKeyId().Trim(); String secretKey = credentials.SecretAccessKey().Trim(); if (credentials.GetType() == typeof(SessionCredentials)) { SessionCredentials sessionCredentials = (SessionCredentials)credentials; return(new SessionCredentials(accessKeyId, secretKey, sessionCredentials.SessionToken().Trim())); } return(credentials); }
public void CredsFromArrayTest() { SdkConfig config = new SdkConfig { SessionId = "faKEsesSiOnId..", EndpointUrl = "https://p1.intacct.com/ia/xml/xmlgw.phtml" }; SessionCredentials sessionCreds = new SessionCredentials(config, senderCreds); Assert.AreEqual("faKEsesSiOnId..", sessionCreds.SessionId); StringAssert.Equals("https://p1.intacct.com/ia/xml/xmlgw.phtml", sessionCreds.Endpoint); Assert.IsInstanceOfType(sessionCreds.SenderCreds, typeof(SenderCredentials)); }
public static bool HasLoggedIn(out string username, out int user_id) { var storage = Mvx.Resolve<IMvxFileStore>(); if (storage.Exists(_credentialFileName)) { string contents; if (storage.TryReadTextFile(_credentialFileName, out contents)) { try { var sessionObj = JsonConvert.DeserializeObject<SessionCredentials>(contents); username = sessionObj.username; user_id = sessionObj.user_id; //Set global variable UserId cred = new SessionCredentials { username = username, user_id = user_id }; return true; } catch (Exception e) { Mvx.Trace("Could not deserialize credentials " + e.Message); } } else { Mvx.Trace("Could not open file! inside HasLoggedIn"); } } //Hasn't logged in username = ""; user_id = 0; return false; }
public static bool HasLoggedIn(out string username, out int user_id) { var storage = Mvx.Resolve <IMvxFileStore>(); if (storage.Exists(_credentialFileName)) { string contents; if (storage.TryReadTextFile(_credentialFileName, out contents)) { try { var sessionObj = JsonConvert.DeserializeObject <SessionCredentials>(contents); username = sessionObj.username; user_id = sessionObj.user_id; //Set global variable UserId cred = new SessionCredentials { username = username, user_id = user_id }; return(true); } catch (Exception e) { Mvx.Trace("Could not deserialize credentials " + e.Message); } } else { Mvx.Trace("Could not open file! inside HasLoggedIn"); } } //Hasn't logged in username = ""; user_id = 0; return(false); }
private void HandleLogin(RestDataRequestMessage message, InitializeSession messageContent, ref RestResponse response, RestRequestMessage request) { var session = new SessionCredentials(messageContent.PeerId, SessionKey.NewGuid()); var playerdata = new PlayerData(); playerdata.FillWithNewPlayer(messageContent.PlayerId, new[] { "FreeForAll", "Captain", "Siege", "Duel", "TeamDeathMatch", "FreeForAll" }); playerdata.LastPlayerName = messageContent.PlayerName; playerdata.LastGameTypes = new[] { "Captain" }; var user = new User { Id = session, QueuedMessages = new Queue <RestResponseMessage>(), PlayerData = playerdata }; if (messageContent.PlayerId.IsValidSteamId()) { if (_context.SteamIDS.Contains(messageContent.PlayerId.Id2)) { user.CanHost = true; } } var userStatus = GetServerStatusForUser(user); _context.Users.Add(user); var initializeSessionResponse = new InitializeSessionResponse(playerdata, userStatus ); response.FunctionResult = new RestDataFunctionResult(new LoginResult(session.PeerId, session.SessionKey, initializeSessionResponse)); response.UserCertificate = session.SessionKey.ToByteArray(); response.SetSuccessful(true, "ResultFromServerTask"); }
public void GetMockHandlerTest() { HttpResponseMessage mockResponse = new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.OK, }; List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage> { mockResponse, }; MockHandler mockHandler = new MockHandler(mockResponses); SdkConfig config = new SdkConfig() { SessionId = "faKEsesSiOnId..", EndpointUrl = "https://p1.intacct.com/ia/xml/xmlgw.phtml", MockHandler = mockHandler, }; SessionCredentials sessionCreds = new SessionCredentials(config, senderCreds); Assert.IsInstanceOfType(sessionCreds.MockHandler, typeof(MockHandler)); }
public OperationBlock(ClientConfig clientConfig, RequestConfig requestConfig, List <IFunction> content) { this.Transaction = requestConfig.Transaction; ICredentials credentials = clientConfig.Credentials; if (credentials != null && credentials.GetType() == typeof(SessionCredentials)) { SessionCredentials sessionCreds = credentials as SessionCredentials; this.Authentication = new SessionAuthentication(sessionCreds.SessionId); } else if (credentials != null && credentials.GetType() == typeof(LoginCredentials)) { LoginCredentials loginCreds = credentials as LoginCredentials; this.Authentication = new LoginAuthentication(loginCreds.UserId, loginCreds.CompanyId, loginCreds.Password, loginCreds.EntityId); } else if (!string.IsNullOrEmpty(clientConfig.SessionId)) { this.Authentication = new SessionAuthentication(clientConfig.SessionId); } else if ( !string.IsNullOrEmpty(clientConfig.CompanyId) && !string.IsNullOrEmpty(clientConfig.UserId) && !string.IsNullOrEmpty(clientConfig.UserPassword) ) { Authentication = new LoginAuthentication(clientConfig.UserId, clientConfig.CompanyId, clientConfig.UserPassword, clientConfig.EntityId); } else { throw new ArgumentException("Authentication credentials [Company ID, User ID, and User Password] " + "or [Session ID] are required and cannot be blank"); } this.Content = content; }
private async Task InitializeAsync(SdkConfig config) { if (String.IsNullOrWhiteSpace(config.ProfileName)) { config.ProfileName = Environment.GetEnvironmentVariable(ProfileEnvName); } SessionProvider provider = new SessionProvider(); SenderCredentials senderCreds = new SenderCredentials(config); if (!String.IsNullOrWhiteSpace(config.SessionId)) { SessionCredentials session = new SessionCredentials(config, senderCreds); sessionCreds = await provider.FromSessionCredentials(session); } else { LoginCredentials login = new LoginCredentials(config, senderCreds); sessionCreds = await provider.FromLoginCredentials(login); } }
public bool RemoveUserBySessionCredentials(SessionCredentials credentials) { User findUserBySessionCredentials = this.FindUserBySessionCredentials(credentials); return(findUserBySessionCredentials != default && Users.Remove(findUserBySessionCredentials)); }
private static void writeToFile(SessionCredentials cred) { string serialized = JsonConvert.SerializeObject(cred); var storage = Mvx.Resolve<IMvxFileStore>(); storage.WriteFile(_credentialFileName, serialized); }
public static void LogIn(int userId, string username) { cred = new SessionCredentials { username = username, user_id = userId }; string serialized = JsonConvert.SerializeObject(cred); var storage = Mvx.Resolve<IMvxFileStore>(); storage.WriteFile(_credentialFileName, serialized); }
/// <summary> /// 添加session 认证信息 /// </summary> /// <param name="mutableRequest">http请求信息</param> /// <param name="credentials">session 认证信息</param> protected override void AddSessionCredentials(SdkHttpFullRequestBuilder mutableRequest, SessionCredentials credentials) { mutableRequest.Header(ParameterConstant.X_JDCLOUD_SECURITY_TOKEN, credentials.SessionToken()); }
public User FindUserBySessionCredentials(SessionCredentials credentials) { return(Users.FirstOrDefault(x => x.Id.SessionKey == credentials.SessionKey)); }
/// <summary> /// Adds session credentials to the request given. /// </summary> /// <param name="mutableRequest">request 构建对象</param> /// <param name="credentials">session 认证的 akey 和 skey 信息</param> protected abstract void AddSessionCredentials(SdkHttpFullRequestBuilder mutableRequest, SessionCredentials credentials);