コード例 #1
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string simulation_DATA(string outdatacode)
        {
            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = DoPost(ProgrameData.GameAdd + RequestUrls.coinBattleFinish, requeststring);

            return(result);
        }
コード例 #2
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public static string Establish_Build(string outdatacode)
        {
            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = DoPost(ProgrameData.GameAdd + RequestUrls.Establish_Build, requeststring);

            return(result);
        }
コード例 #3
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string GetRecoverBP()
        {
            string outdatacode   = AuthCode.Encode(ProgrameData.sign, ProgrameData.sign);//用自身作为密匙把自身加密
            string requeststring = String.Format("uid={0}&signcode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = DoPost(ProgrameData.GameAdd + RequestUrls.RecoverBp, requeststring);

            return(result);
        }
コード例 #4
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public static string eventDraw()
        {
            string outdatacode   = AuthCode.Encode(ProgrameData.sign, ProgrameData.sign);
            string requeststring = String.Format("uid={0}&signcode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = DoPost(ProgrameData.GameAdd + RequestUrls.eventDraw, requeststring);

            return(result);
        }
コード例 #5
0
        //public async Task<AuthCode> SendCode(string phone, AuthCodeMessageType messageType)
        //{
        //    if (string.IsNullOrEmpty(phone))
        //        throw new ApplicationException(Resx.AppResources.InvalidPhoneException);

        //    var code = OtpTools.GenRandomNumber(6);
        //    var authCode = new AuthCode()
        //    {
        //        Phone = phone,
        //        IsRegistered = false,
        //        MessageType = AuthCodeMessageType.SmsMessageWithCode,
        //        IsPassword = false,
        //        CodeHash = CryptoProvider.SHA1(CryptoProvider.SHA1(code)).ToLower(),
        //        //Token = CryptoProvider.HMACSHA1(phone, OtpTools.GetOtpTime()).ToLower(),
        //    };

        //    return await Task.Run<AuthCode>(async () =>
        //    {
        //        var user = _dataManager.Get<User>(new { Phone = phone });
        //        if (user != null)
        //        {
        //            authCode.IsRegistered = true;
        //        }

        //        authCode.CreateTime = DateTimeOffset.UtcNow;
        //        authCode.ExpieryTime = DateTimeOffset.UtcNow.AddSeconds(180);
        //        authCode.Id = _dataManager.Insert<AuthCode, long>(authCode);

        //        // Send Message
        //        _notificationProvider?.SendPhoneVerificationMessage(phone, code, user?.AppName, messageType);

        //        return authCode;
        //    });
        //}

        public async Task <AuthCode> SendCode(string recipient, AuthCodeMessageType messageType, string appName)
        {
            if (string.IsNullOrEmpty(recipient))
            {
                throw new ApplicationException("Invalid recipient.");
            }

            User user = null;

            if (messageType == AuthCodeMessageType.Email)
            {
                user = _dataManager.Get <User>(new { Email = recipient });
            }
            else
            {
                user = _dataManager.Get <User>(new { Phone = recipient });
            }

            var code     = OtpTools.GenRandomNumber(6);
            var authCode = new AuthCode()
            {
                Recipient    = recipient,
                IsRegistered = user != null,
                MessageType  = messageType,
                IsPassword   = false,
                CodeHash     = CryptoProvider.SHA1(CryptoProvider.SHA1(code)).ToLower(),
                //Token = CryptoProvider.HMACSHA1(phone, OtpTools.GetOtpTime()).ToLower(),
                CreateTime  = DateTimeOffset.UtcNow,
                ExpieryTime = messageType == AuthCodeMessageType.Email ? DateTimeOffset.UtcNow.AddDays(30) : DateTimeOffset.UtcNow.AddSeconds(180)
            };

            authCode.Id = _dataManager.Insert <AuthCode, long>(authCode);

            // Send Message
            switch (messageType)
            {
            case AuthCodeMessageType.SmsMessageWithCode:
            case AuthCodeMessageType.SmsMessageWithAppLink:
            case AuthCodeMessageType.ChatMessage:
            case AuthCodeMessageType.PhoneCall:
            case AuthCodeMessageType.PushMessage:
                await _notificationProvider?.SendPhoneVerificationMessage(recipient, user?.DisplayName, code, appName);

                break;

            case AuthCodeMessageType.Email:
                var token = Convert.ToBase64String(Encoding.Unicode.GetBytes($"{recipient}&{code}&{authCode.ExpieryTime}"));
                var link  = $"{EmailVerificationUrl}?token={HttpUtility.UrlEncode(token)}";
                await _notificationProvider?.SendEmailVerificationMessage(recipient, user?.DisplayName, link, appName);

                break;

            default:
                break;
            }

            return(authCode);
        }
コード例 #6
0
        /// <summary>
        /// 获取随机验证码
        /// </summary>
        /// <returns>验证码图片</returns>
        public FileContentResult GetRandomAuthCode()
        {
            AuthCode auCode = new AuthCode(4);
            string strCode = auCode.GetRandomCode();
            Session[SysContext.ConstKeys.Session_AuthCode] = strCode;
            byte[] imageByte = auCode.CreateJpegImage(strCode);

            return File(imageByte, @"image/jpeg");
        }
コード例 #7
0
        /// <summary>
        /// 获取随机验证码
        /// </summary>
        /// <returns>验证码图片</returns>
        public FileContentResult GetRandomAuthCode()
        {
            AuthCode auCode  = new AuthCode(4);
            string   strCode = auCode.GetRandomCode();

            Session[SysContext.ConstKeys.Session_AuthCode] = strCode;
            byte[] imageByte = auCode.CreateJpegImage(strCode);

            return(File(imageByte, @"image/jpeg"));
        }
コード例 #8
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string Click_Get_Material()
        {
            string outdatacode   = AuthCode.Encode(ProgrameData.sign, ProgrameData.sign);//用自身作为密匙把自身加密
            string requeststring = String.Format("uid={0}&signcode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.ClickKalina, requeststring);
            }
            return(result);
        }
コード例 #9
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string Get_Build_Coin(string v_user_id, string dorm_id)
        {
            //{"v_user_id":"54634","dorm_id":1}
            string outdatacode = "{\"v_user_id\":" + "\"" + v_user_id + "\"" + "," + "\"dorm_id\":" + dorm_id + "}";

            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());

            string result = DoPost(ProgrameData.GameAdd + RequestUrls.Get_Friend_Build_Coin, requeststring);

            return(result);
        }
コード例 #10
0
ファイル: AuthTokenService.cs プロジェクト: EagleSmith/hiwjcn
        public virtual async Task <_ <AuthCode> > CreateCodeAsync(
            string client_uid, List <string> scopes, string user_uid)
        {
            var data = new _ <AuthCode>();

            if (!ValidateHelper.IsPlumpList(scopes))
            {
                data.SetErrorMsg("scopes为空");
                return(data);
            }
            var now = DateTime.Now;

            var client = await this._AuthClientRepository.GetFirstAsync(x => x.UID == client_uid && x.IsRemove <= 0);

            if (client == null)
            {
                data.SetErrorMsg("授权的应用已被删除");
                return(data);
            }

            var code = new AuthCode()
            {
                UserUID    = user_uid,
                ClientUID  = client_uid,
                ScopesJson = scopes.ToJson()
            };

            code.Init("code");

            var border = now.GetDateBorder();

            var count = await this._AuthCodeRepository.GetCountAsync(x =>
                                                                     x.ClientUID == client_uid &&
                                                                     x.UserUID == user_uid &&
                                                                     x.CreateTime >= border.start &&
                                                                     x.CreateTime < border.end);

            if (count >= MaxCodeCreatedDaily)
            {
                data.SetErrorMsg("授权过多");
                return(data);
            }

            if (await this._AuthCodeRepository.AddAsync(code) > 0)
            {
                //clear old data
                await this.ClearOldCode(user_uid);

                data.SetSuccessData(code);
                return(data);
            }
            throw new MsgException("保存票据失败");
        }
コード例 #11
0
        private static RestRequest GetTokenRequest(AuthCode authCode)
        {
            var request = new RestRequest("token");

            request.AddParameter("grant_type", "authorization_code");
            request.AddParameter("code", authCode.Code);
            request.AddParameter("redirect_uri", authCode.App.RedirectUri);
            request.AddParameter("client_id", authCode.App.ClientId);
            request.AddParameter("client_secret", authCode.App.Secret);

            return(request);
        }
コード例 #12
0
ファイル: Form1.cs プロジェクト: Freedamage/myWorks
        private void AuthBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string          Connection = "Server=;Port=3;Database=td;Uid=te4id;password="******"Select MyKeysI from MyKey";

                conn.Open();


                MySqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    FromMySQL += reader["MyKeysI"].ToString() + " ";
                }

                code = AuthCode.Text;

                Properties.Settings.Default["Key"] = code;
                Properties.Settings.Default.Save();

                if (FromMySQL.Contains(code) && code.Length > 20 && !FromMySQL.Contains(code + "active"))
                {
                    string          Connectiona = "Server=temah;Port=3Database=teid;Uid=tema4id;password=vkq7";
                    MySqlConnection conna       = new MySqlConnection(Connectiona);
                    MySqlCommand    commandAd   = conna.CreateCommand();
                    commandAd.CommandText = ("UPDATE `MyKey` SET `MyKeysI`= '" + code + "active' WHERE MyKeysI = '" + code + "'");
                    conna.Open();
                    commandAd.ExecuteNonQuery();

                    buttonAgain.Hide();
                    toolStripContainer1.Hide();
                    AuthBtn.Hide();
                    AuthCode.Hide();
                    TypeCode.Hide();
                    ErrorOfKey.Hide();
                    button7.Hide();
                }
                else
                {
                    BaddConnection.Hide();
                    ErrorOfKey.Show();
                }
            }
            catch
            {
                ErrorOfKey.Hide();
                BaddConnection.Show();
            }
        }
コード例 #13
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string GetUserInfo()//api = index/index
        {
            string outdatacode   = AuthCode.Encode("{\"time\":" + CommonHelp.ConvertDateTime_China_Int(DateTime.Now).ToString() + "}", ProgrameData.sign);
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.GetUserInfo, requeststring);
            }
            return(result);
        }
コード例 #14
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string StartTrial(string teamids)
        {
            string outdatacode = "";

            outdatacode = "{\"team_ids\":" + "\"" + teamids.ToString() + "\"" + "," + "\"battle_team\":" + teamids.ToString() + "}";
            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());


            string result = DoPost(ProgrameData.GameAdd + RequestUrls.StartTrial, requeststring);

            return(result);
        }
コード例 #15
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string attendance()//api = index/index
        {
            string outdatacode   = AuthCode.Encode(ProgrameData.sign, ProgrameData.sign);
            string requeststring = String.Format("uid={0}&signcode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.GetAttendance, requeststring);//不需要解密 返回的是签到当月信息奖励
                //var jsonobj = DynamicJson.Parse(AuthCode.Decode(result, ProgrameData.sign));
            }
            return(result);
        }
コード例 #16
0
        public AzureADAuthRestResponse <AccessTokenClass, OAuthError> GetAccessToken_UserCredential(DatabaseManager dbmanager)
        {
            StateManager        _stateIdManager = new StateManager(Config.LoggedInUserEmail, Config.Scope);
            LocalStorageManager _localStorage   = new LocalStorageManager(Config, dbmanager);
            string _stateId = _stateIdManager.GetStateIdForCurrentUser(dbmanager);
            var    resp     = new AzureADAuthRestResponse <AccessTokenClass, OAuthError>();
            // try to look for the available token first
            // if token not available then use authorize code to download it
            // if token expires then download new token using refresh token and store in database
            // if authorize token not available send send the response then auhorize token not available
            AccessTokenClass token = _localStorage.GetAccessToken(_stateId);

            if (token == null)
            {
                // check if authcode available
                AuthCode authcode = _localStorage.GetAuthCode(_stateId);
                if (authcode == null)
                {
                    resp.OAuthError = OAuthErrors.AuthCodeNotFound;
                    return(resp);
                }
                var res = GetAccessToken(authcode.code, TokenRetrivalType.AuthorizationCode);
                // check for any error in response
                if (res.IsSucceeded)
                {
                    token = res.Result;
                    _localStorage.AddAccessToken(_stateId, token);
                    // add token into database
                }
                else
                {
                    // send status to front page that it is not authorized, authorization code has expired
                    resp.OAuthError = OAuthErrors.AuthCodeExpires;
                    return(resp);
                }
            }
            // check for token's validity, if expires then recalculate from refresh token
            if (!validateToken(token))
            {
                var res = GetAccessToken(token.RefreshToken, TokenRetrivalType.RefreshToken);
                // check for any error, if error is not present then cast to
                if (res.IsSucceeded)
                {
                    token = res.Result;
                    _localStorage.UpdateAccessToken(_stateId, token);
                }
            }
            resp.Result     = token;
            resp.OAuthError = OAuthErrors.None;
            return(resp);
        }
コード例 #17
0
        public static async Task <Token> GetTokenAsync(AuthCode authCode, string authUri = BaseUrls.OauthUrl)
        {
            var client = new RestClient(authUri);

            var request = GetTokenRequest(authCode);

            var response = await client.ExecuteGetAsync(request).ConfigureAwait(false);

            var token = DeserializeToken(response);

            token.Mode = authCode.Mode;

            return(token);
        }
コード例 #18
0
        public static Token GetToken(AuthCode authCode, string authUri = BaseUrls.OauthUrl)
        {
            var client = new RestClient(authUri);

            var request = GetTokenRequest(authCode);

            var response = client.Execute(request);

            var token = DeserializeToken(response);

            token.Mode = authCode.Mode;

            return(token);
        }
コード例 #19
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string GetOneMail_Type2(int mailwith_user_id)
        {
            string outdatacode = "{\"mailwith_user_id\":" + mailwith_user_id.ToString() + "}";

            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);//用自身作为密匙把自身加密
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());

            string result = "";

            result = DoPost(ProgrameData.GameAdd + RequestUrls.GetOneMail, requeststring);

            //result = AuthCode.Decode(result, ProgrameData.sign);
            return(result);
        }
コード例 #20
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string ifNewMail()
        {
            string outdatacode   = AuthCode.Encode(ProgrameData.sign, ProgrameData.sign);//用自身作为密匙把自身加密
            string requeststring = String.Format("uid={0}&signcode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.CheckNewMail, requeststring);
                //result = AuthCode.Decode(result, ProgrameData.sign);
                result = CommonHelp.DecodeAndMapJson(result);
            }
            return(result);
        }
コード例 #21
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string RecoverResource()                                                   //恢复资源
        {
            string outdatacode   = AuthCode.Encode(ProgrameData.sign, ProgrameData.sign); //用自身作为密匙把自身加密
            string requeststring = String.Format("uid={0}&signcode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());
            string result        = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.RecoverResource, requeststring);
                //var jsonobj = DynamicJson.Parse(AuthCode.Decode(result, ProgrameData.sign));
                var jsonobj = DynamicJson.Parse(CommonHelp.DecodeAndMapJson(result));
            }
            return(result);
        }
コード例 #22
0
ファイル: Auth.cs プロジェクト: SyruSTR/WorkShop-idle
    private void ThreadAuth()
    {
        new Thread(new ThreadStart(async() =>
        {
            IsAuth = await PostToken(loginField.text, passwordField.text);

            Dispatcher.Invoke(() =>
            {
                Debug.Log(IsAuth);

                ChangeStatusText();
            });
        })).Start();
    }
コード例 #23
0
ファイル: AuthCodeController.cs プロジェクト: BJDIIL/ola
        public async Task <ActionResult> GenerateQrCodeUrl(bool newAuthCode = false)
        {
            AuthCode authCode = null;

            if (!newAuthCode)
            {
                authCode = await db.AuthCodes.Where(w => w.IsExpired == false).OrderByDescending(w => w.Id).FirstOrDefaultAsync();

                if (authCode != null)
                {
                    return(Json(new { errno = 0, QrCodeUrl = authCode.QrCodeUrl, msg = "" }, JsonRequestBehavior.AllowGet));
                }
            }
            var olds = await db.AuthCodes.Where(w => w.IsExpired == false).ToListAsync();

            foreach (var item in olds)
            {
                item.IsExpired = true;
            }
            await db.SaveChangesAsync();

            authCode = new AuthCode
            {
                Code       = Guid.NewGuid().ToString("N"),
                CreateTime = DateTime.Now,
                IsExpired  = false,
                QrCodeUrl  = null,
            };

            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            var             plainText   = WebConfigs.WebSiteBaseUrl + "/Login/Index?authCode=" + authCode.Code;
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(plainText, QRCodeGenerator.ECCLevel.Q);
            QRCode          qrCode      = new QRCode(qrCodeData);
            Bitmap          qrCodeImage = qrCode.GetGraphic(20);
            var             baseDir     = AppDomain.CurrentDomain.BaseDirectory;
            var             dir         = "/Content/QRCodes/" + DateTime.Now.ToString("yyyyMMdd");

            if (!Directory.Exists(baseDir + dir))
            {
                Directory.CreateDirectory(baseDir + dir);
            }
            var fileName = "/" + authCode.Code + ".jpg";

            qrCodeImage.Save(baseDir + dir + fileName, ImageFormat.Jpeg);
            authCode.QrCodeUrl = dir + fileName;
            db.AuthCodes.Add(authCode);
            await db.SaveChangesAsync();

            return(Json(new { errno = 0, QrCodeUrl = authCode.QrCodeUrl, msg = "" }, JsonRequestBehavior.AllowGet));
        }
コード例 #24
0
        ///<summary>
        /// This method search for the AuthCode in database based on stateId.
        /// An stateId is the unique code generated for combination of a user and a particular scope.
        /// AuthCodes are stored in database with stateId as primary key.
        /// If no AuthCode available in database then it returns null.
        /// <code>
        /// string authCode= localStoreManager.GetAuthCode(stateId);
        /// </code>
        ///</summary>
        public AuthCode GetAuthCode(string _stateId)
        {
            AuthCode authCode = null;

            AuthCode[] authCodes = _dbManager.ExecuteSQLReader <AuthCode>("select * from AuthenticationCode where stateid like '" + _stateId + "'", x => new AuthCode()
            {
                code = x["code"].ToString(), session_state = x["session_state"].ToString(), stateid = x["stateid"].ToString()
            });
            if (authCodes.Length > 0)
            {
                authCode = authCodes.FirstOrDefault();
            }

            return(authCode);
        }
コード例 #25
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string GetOneMail_Type1(int mailwith_user_id)
        {
            System.Threading.Thread.Sleep(2500);
            string outdatacode = "{\"mail_with_user_id\":" + mailwith_user_id.ToString() + "}";

            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);//用自身作为密匙把自身加密

            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());

            string result = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.GetOneMail, requeststring);
            }
            return(result);
        }
コード例 #26
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        public string GetMailResource_Type2(int mailwith_user_id)
        {
            string outdatacode = "{\"mailwith_user_id\":" + mailwith_user_id.ToString() + "}";

            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);//用自身作为密匙把自身加密
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());

            string result = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.GetMailResource, requeststring);
            }
            //result = AuthCode.Decode(result, ProgrameData.sign);
            result = CommonHelp.DecodeAndMapJson(result);
            return(result);
        }
コード例 #27
0
ファイル: ServiceProxy.cs プロジェクト: mazloumi/BadgeScan
        public static async Task <AuthCode> Authenticate()
        {
            try
            {
                var service = DependencyService.Get <IAuth>();
                var auth    = await service.Authenticate(Settings.Authority, $"https://{Settings.Resource}", Settings.ApplicationId, new Uri($"https://{Settings.Resource}"));

                resultCode = AuthCode.Successful;
                client     = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", auth.AccessToken);
                client.BaseAddress = new Uri($"https://{Settings.Resource}/api/data/v8.1/");
                client.Timeout     = new TimeSpan(0, 2, 0);
                client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
                client.DefaultRequestHeaders.Add("OData-Version", "4.0");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            }
            catch (AdalException adalEx)
            {
                switch (adalEx.ErrorCode)
                {
                case "authentication_canceled":
                    resultCode = AuthCode.Cancelled;
                    break;

                case "access_denied":
                    resultCode = AuthCode.Denied;
                    break;

                case "multiple_matching_tokens_detected":
                    resultCode = AuthCode.Failed;
                    break;

                default:
                    resultCode = AuthCode.Failed;
                    break;
                }
            }

            catch (Exception ex)
            {
                resultCode = AuthCode.Failed;
                Debug.WriteLine($"{resultCode} - {ex.Message}: {ex.StackTrace}");
            }
            return(resultCode);
        }
コード例 #28
0
ファイル: FileAttribute.cs プロジェクト: whuanle/XFPanel
            public ResponseModel Show()
            {
                ResponseModel responseModel = new ResponseModel {
                    Code = 200, Result = "获取属性成功"
                };

                responseModel.Data = new Dictionary <string, string>();
                responseModel.Data.Add("文件路径", FilePath);
                responseModel.Data.Add("文件名称", FileName);
                responseModel.Data.Add("文件大小", FileSize);
                responseModel.Data.Add("MD5值", Md5);
                responseModel.Data.Add("创建时间", CreationTime);
                responseModel.Data.Add("最后访问时间", LastAccessTime);
                responseModel.Data.Add("最近一次编辑时间", LastWriteTime);
                responseModel.Data.Add("文件属性", AuthString);
                responseModel.Data.Add("属性代码", AuthCode.ToString());
                responseModel.Data.Add("属性说明", AuthRemark);
                return(responseModel);
            }
コード例 #29
0
ファイル: POST.cs プロジェクト: team-imasara/V2
        //"{\"item_id\":\"\",\"big_success\":0}"



        public string AbortOperation(int operationid)
        {
            //{\"operation_id\":5}
            string outdatacode = "";

            outdatacode = "{\"operation_id\":" + operationid.ToString() + "}";
            outdatacode = AuthCode.Encode(outdatacode, ProgrameData.sign);
            string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", ProgrameData.uid, System.Web.HttpUtility.UrlEncode(outdatacode), ProgrameData.req_id++.ToString());


            string result = "";

            while (string.IsNullOrEmpty(result) == true)
            {
                result = DoPost(ProgrameData.GameAdd + RequestUrls.AbortOperation, requeststring);//不需要解密
            }
            return(result);

            //"{\"item_id\":\"\",\"big_success\":0}"
        }
コード例 #30
0
    public static string EncodeWithGzip(string m, string key)
    {
        byte[] raw = Encoding.UTF8.GetBytes(m);
        byte[] dest;
        using (MemoryStream stream = new MemoryStream())
        {
            using (GZipOutputStream stream1 = new GZipOutputStream(stream))
            {
                stream1.IsStreamOwner = false;
                stream1.Write(raw, 0, raw.Length);
                stream1.Flush();
                stream1.Finish();
                dest = stream.ToArray();
            }
        }

        byte[] bytes = new byte[dest.Length + 0x1a];
        Array.Copy(dest, 0, bytes, 0x1a, dest.Length);
        Array.Copy(Encoding.UTF8.GetBytes("0000000000"), 0, bytes, 0, 10);
        //1
        //还有26byte待解决
        int lengthOfACode = 0;

        key = AuthCode.MD5(key);
        string str  = AuthCode.MD5(key.Substring(0x10, 0x10));
        string s    = AuthCode.MD5(key.Substring(0x0, 0x10));
        string str3 = (lengthOfACode > 0) ? m.Substring(0, lengthOfACode) : "";
        string pass = str + AuthCode.MD5(str + str3);

        //1
        byte[] buffer4 = new byte[(bytes.Length - 0x1a) + s.Length];
        Array.Copy(dest, 0, buffer4, 0, dest.Length);
        Array.Copy(Encoding.UTF8.GetBytes(s), 0, buffer4, dest.Length, s.Length);
        Array.Copy(Encoding.UTF8.GetBytes(AuthCode.MD5(buffer4)), 0, bytes, 10, 0x10);

        byte[] buffer = RC4(bytes, pass);

        string result = Convert.ToBase64String(buffer);

        return("#" + new string(new char[lengthOfACode]) + result);
    }
コード例 #31
0
        public static AuthCode GetAuthCode(string pnr)
        {
            AuthCode       AuthCode       = new AuthCode();
            GetAuthCodeDAL objGetAuthCode = new GetAuthCodeDAL();

            try
            {
                try
                {
                    AuthCode = objGetAuthCode.GetAuthCode(pnr, CommonENT.MYCTSDB_CONNECTION);
                }
                catch (Exception ex)
                {
                    new EventsManager.EventsManager(ex, EventsManager.EventsManager.OrigenError.BaseDeDatos);
                    AuthCode = objGetAuthCode.GetAuthCode(pnr, CommonENT.MYCTSDBBACKUP_CONNECTION);
                }
            }
            catch { }

            return(AuthCode);
        }
コード例 #32
0
ファイル: SettingsService.cs プロジェクト: alexhardwicke/Auth
        public void AddCode(AuthCode authCode)
        {
            if (RoamKeys)
            {
                _passwordHelper.Write(new SecureAuthCode(authCode));
            }

            var codes = AuthCodes;

            if (codes.Count == 0)
            {
                codes.Add(authCode);
            }
            else
            {
                for (int i = 0; i < codes.Count; ++i)
                {
                    if (i + 1 == codes.Count)
                    {
                        codes.Insert(i + 1, authCode);
                        break;
                    }

                    var code = codes[i];
                    var nextCode = codes[i + 1];

                    if (string.Compare(authCode.Name, code.Name, StringComparison.Ordinal) == -1 &&
                        string.Compare(authCode.Name, nextCode.Name, StringComparison.Ordinal) == 1)
                    {
                        codes.Insert(i + 1, authCode);
                        break;
                    }
                }
            }

            AuthCodes = codes;
        }
コード例 #33
0
ファイル: SettingsService.cs プロジェクト: alexhardwicke/Auth
        public void EditCode(AuthCode authCode, string oldName)
        {
            var codes = AuthCodes;
            var code = codes.FirstOrDefault(x => x.Name == oldName);
            code.Name = authCode.Name;

            if (RoamKeys)
            {
                _passwordHelper.UpdateName(oldName, authCode.Name);
            }

            WriteAuthCodes(codes);
        }
コード例 #34
0
ファイル: SecureAuthCode.cs プロジェクト: alexhardwicke/Auth
 public SecureAuthCode(AuthCode code)
 {
     Name = code.Name;
     Secret = code.Secret;
 }
コード例 #35
0
ファイル: SettingsService.cs プロジェクト: alexhardwicke/Auth
        public void DeleteCode(AuthCode authCode)
        {
            AuthCodes = AuthCodes.Where(x => x.Name != authCode.Name).ToList();

            if (RoamKeys)
            {
                _passwordHelper.Remove(new SecureAuthCode(authCode));
            }
        }
コード例 #36
0
 public StrippedAuthCode(AuthCode authCode)
 {
     Name = authCode.Name;
 }