Example #1
0
        public async Task <EcpState> InspurIdSSO(string auth)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Authorization", auth);
            InspurIdAuthResult ar = await HttpHelper.SendJsonData <InspurIdAuthResult>(HttpMethod.Get, getProfileUrl, null, headers);

            EcpUserService userSvr = new EcpUserService();
            SysUser        user    = userSvr.GetUserByInspurID(ar.ID);
            EcpState       state   = new EcpState()
            {
                User = user, TenantID = ar.Enterprise.ID, TenantName = ar.Enterprise.Name
            };

            return(state);
        }
Example #2
0
        public async Task <EcpState> SimpleAuthen(string account, string password)
        {
            Dictionary <string, string> postDataDic = new Dictionary <string, string>();

            postDataDic.Add("grant_type", "password");
            postDataDic.Add("username", account);
            postDataDic.Add("password", password);
            postDataDic.Add("client_id", "com.inspur.ecm.client.android");
            postDataDic.Add("client_secret", "6b3c48dc-2e56-440c-84fb-f35be37480e8");


            HttpResponseMessage resMsg = await HttpHelper.PostFormData(loginUrl, postDataDic);

            string str = await resMsg.Content.ReadAsStringAsync();

            if (resMsg.IsSuccessStatusCode)
            {
                Dictionary <string, string> responseDic = JsonConvert.DeserializeObject <Dictionary <string, string> >(str);

                string access_token = responseDic["access_token"];
                string token_type   = responseDic["token_type"];
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", string.Format("{0} {1}", token_type, access_token));

                InspurIdAuthResult ar = await HttpHelper.SendJsonData <InspurIdAuthResult>(HttpMethod.Get, getProfileUrl, null, headers);

                EcpUserService userSvr = new EcpUserService();
                SysUser        user    = userSvr.GetUserByInspurID(ar.ID);
                EcpState       state   = new EcpState()
                {
                    User = user, TenantID = ar.Enterprise.ID, TenantName = ar.Enterprise.Name
                };
                HttpContextProvider.Current.Session.Clear();
                EcpState.SetCurrent(state);
                return(state);
            }
            else
            {
                throw new RtfException(str);
            }
        }