Exemplo n.º 1
0
        public async Task <string> GetAccessToken(AuthenticationLogin input)
        {
            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(Resource.ServiceUriBase);
                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("grant_type", input.grant_type),
                    new KeyValuePair <string, string>("username", input.username),
                    new KeyValuePair <string, string>("password", input.password),
                    new KeyValuePair <string, string>("client_id", input.client_id),
                    new KeyValuePair <string, string>("client_secret", input.client_secret)
                });
                var response = client.PostAsync("Token", content).Result;
                if (response.IsSuccessStatusCode != true && response.StatusCode != HttpStatusCode.OK)
                {
                    response.EnsureSuccessStatusCode();
                }
                var result = await response.Content.ReadAsAsync <AuthenticationToken>();

                HttpContext.Current.Session["TOKEN"] = result.access_token;
                return(result.access_token);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void getAccessToken(AccountViewModel formData)
        {
            ApiClient           client = ApiClient.Instance;
            AuthenticationLogin model  = new AuthenticationLogin();

            model.client_id     = ApplicationResources.AppNameSumary;
            model.client_secret = formData.Password;
            model.grant_type    = "password";
            model.username      = formData.Username;
            model.password      = formData.Password;
            var result = client.GetAccessToken(model);
        }
        /// <summary>
        /// login to the API
        /// </summary>
        /// <param name="currentApiHttpClient"></param>
        /// <returns></returns>
        internal async Task <bool> ExecuteLoginAsync(HttpClient currentApiHttpClient)
        {
            try
            {
                string subPathUri = _configurationManager.GetValue("ApiAuthenticationPath");

                AuthenticationLogin authenticationLoginObject = new AuthenticationLogin
                {
                    UsernameOrEmailAddress = _configurationManager.GetValue("UserName"),
                    Password   = _configurationManager.GetValue("UserPassword"),
                    RememberMe = true
                };

                if (string.IsNullOrWhiteSpace(authenticationLoginObject.UsernameOrEmailAddress) ||
                    string.IsNullOrWhiteSpace(authenticationLoginObject.Password))
                {
                    return(false);
                }

                HttpResponseMessage authResponseResult = currentApiHttpClient.PostAsJsonAsync(subPathUri, authenticationLoginObject).Result;
                authResponseResult.EnsureSuccessStatusCode();

                AuthenticationResponse loginResponse = JsonConvert.DeserializeObject <AuthenticationResponse>(await authResponseResult.Content.ReadAsStringAsync());
                if (loginResponse.Result == 1)
                {
                    return(true);
                }
            }
            catch (Exception authenticationError)
            {
                _applicationLogTools.LogError(authenticationError, new Dictionary <string, dynamic> {
                    { "ClassName", "AzureApi.ApiAuthentication" }
                });
            }

            return(false);
        }
Exemplo n.º 4
0
        private void Initialize()
        {
            // TODO: Move this line to design.cs
            fileMain.FileOk += new CancelEventHandler(fileMain_FileOk);
            sfdExport.FileOk += new CancelEventHandler(sfdExport_FileOk);
            sfdExport.Filter = "Eml (*.eml)|*.eml|All File (*.*)|*.*";
            ofdImport.FileOk += new CancelEventHandler(ofdImport_FileOk);
            ofdImport.Filter = "Eml (*.eml)|*.eml|All File (*.*)|*.*";

            ExpandRecPanel(false);

            // TODO: Change to property
            ScrollLog(true);

            // Initialize for command mode
            cmdSMTPCommunicator = new SMTPCommunicator();
            m_authLogin = new AuthenticationLogin();
            cmdMgr = new SMTP.Commands.CommandManager();
            cmdMgr.UpdateMessage += new SMTP.Commands.CommandEvent.CommandEventHandler(OnCommandManagerUpdateMessage);
            cmdMgr.Attach(Commands.PackageCommands.Pack(this.cmdSMTPCommunicator));
            cmdMgr.Attach(new Commands.CmdHelp(cmdMgr));

            // Set accept key word command textbox
            acceptKeyHelper = new SMTP.Utility.TextboxAcceptKeyHelper(this.txtCommand);
            acceptKeyHelper.AcceptButton = this.btnCommand;

            // Initialize hex editor
            this.messageBodyBytes = new byte[0];
            textByteProvider = new Be.Windows.Forms.DynamicByteProvider(this.messageBodyBytes);

            this.hexMessage.ByteProvider = textByteProvider;

            this.CustomizeMessageBody = false;
        }
Exemplo n.º 5
0
 public FormAuthenLogin(AuthenticationLogin authLogin)
 {
     this.Authentication = authLogin;
     InitializeComponent();
 }
Exemplo n.º 6
0
		/// <summary>
		///   登入遠端伺服器
		/// </summary>
		/// <returns>返回值:true=登入程序已成功(等候onLogin事件通知), false=登入程序失敗</returns>
		public override bool Login() {
			if (this.IsLogin) {
				return true;
			}

			int iBufferSize = 1;
			byte[] bArray = new byte[64];

			if (logger.IsInfoEnabled) logger.InfoFormat("[QuoteService.Login] Login signer service... service={0}({1}), userId={2}", this.RemoteIP, this.RemotePort, this.UserId);
			AuthenticationLogin authLogin = new AuthenticationLogin(this.UserId, this.Password, 0, 0);
			try {
				Socket cLogin = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
				cLogin.Connect(new IPEndPoint(IPAddress.Parse(this.RemoteIP), this.RemotePort));
				cLogin.Send(MitakePacket.ToBuffer(authLogin));
				iBufferSize = cLogin.Receive(bArray);
				cLogin.Close();
			} catch (Exception __errExcep) {
				logger.ErrorFormat("{0}\r\n{1}", __errExcep.Message, __errExcep.StackTrace);
				return false;
			}

			if (iBufferSize == 0) {
				return false;
			} else {
				AuthenticationReturn authReturn = null;
				authReturn = MitakePacket.ToStructure<AuthenticationReturn>(bArray, iBufferSize);

				__sUserID = this.UserId;
				__sSessionKey = authReturn.SessionKey;

				string sServiceIP = authReturn.RemoteIP;
				int iPort = authReturn.RemotePort;
				if (logger.IsInfoEnabled) logger.InfoFormat("[QuoteService.Login] Register service... service={0}({1}), userId={2}, sessionKey:{3}", sServiceIP, iPort, __sUserID, __sSessionKey);

				if (__cSocket == null) {
					__cSocket = new ZSocket();
					__cSocket.ReceiveProc += SocketClient_onReceive;
					__cSocket.CloseProc += StockClient_onClose;
				}
				
				if (!RegisterServer(__cSocket, sServiceIP, iPort, 0x06)) {
					__cSocket.Close();  //關閉 Stream Socket
					__cSocket = null;
					return false;
				}

				if (__cSession == null) {
					__cSession = new ZSocket();
					__cSession.ReceiveProc += SocketClient_onReceive;
					__cSession.CloseProc += StockClient_onClose;
				}
				
				if (!RegisterServer(__cSession, sServiceIP, iPort, 0x05)) {  //如果註冊失敗
					__cSocket.Close();  //關閉 Stream Socket(一定要 Stream 與 Session 兩條通道都同時建立完成, 才算是連線成功) 
					__cSocket = null;

					__cSession.Close();  //關閉 Session Socket
					__cSession = null;
					return false;
				}

				lock (__cTimer) {
					__bTimeFlag = true;
					__cTimer.Start();
				}

				StockDecoder.TimerProc += StockClient_onTimer;
				StockDecoder.StockProc += StockClient_onStock;
				McpDecoder.McpPacketProc += StockClient_onMcpPacket;

				MitakeSymbolManager.DataSource = this.DataSource;
				MitakeSymbolManager.ExchangeName = this.ExchangeName;
				StockDecoder.TimerProc += GetTradeDateFromLogin;  //先取得最後交易日期之後再處理股票代號表之類的運作

				this.SendSubscribe();
			}
			return true;
		}