예제 #1
0
        public async Task <UserAccount> ValidateCredentialsAsync(AuthParams param)
        {
            var user = await session.Query <UserAccount>()
                       .SingleOrDefaultAsync(u => u.Login == param.Login);

            return(user == null ? null : hashService.CompareHashes(param.Password, user.PasswordHash) ? user : null);
        }
예제 #2
0
        public void SaveAuthParams()
        {
            try
            {
                logger.Info("Saving auth params: {0}", _sAuthParamFileName);
                if (string.IsNullOrWhiteSpace(_sAuthParamFileName))
                {
                    throw new ArgumentNullException("fileName", "Filename cannot be empty!");
                }
                using (MemoryStream msStream = new MemoryStream())
                { // serialize into the memory stream
                    XmlSerializer ser = new XmlSerializer(AuthParams.GetType());
                    ser.Serialize(msStream, AuthParams);
                    msStream.Position = 0;

                    // encrypt
                    //string sEncrypted = CryptoUtils.EncryptString(msStream.ToArray());
                    string sEncrypted = CryptoUtils.SimpleEncrypt(msStream.ToArray());
                    // write to file
                    using (StreamWriter swWriter = new StreamWriter(_sAuthParamFileName, false))
                    {
                        swWriter.Write(sEncrypted);
                    }
                }
                logger.Debug("Saving done");
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error while saving OAuth2Parameters into file \"{0}\": {1}", _sAuthParamFileName, ex.Message);
                throw new Exception(string.Format("Error while saving OAuth2Parameters into file \"{0}\": {1}", _sAuthParamFileName, ex.Message), ex);
            }
        }
예제 #3
0
        public static CookieCollection DoAuthorize()
        {
            var cookieCollection = new CookieCollection();

            var aping = new AccountAPING(BetFairData.ApiKey);

            //var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            //webhost
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Storage", "LiveApp.p12");

            Log.Info("path " + path);

            var file = new MemoryStream(File.ReadAllBytes(path));

            var authParams = new AuthParams
            {
                Login          = BetFairData.Login,
                Password       = BetFairData.Password,
                UseCertificate = true,
                Certificate    = new X509Certificate2(file.ToArray(), BetFairData.CertificatePassword, X509KeyStorageFlags.MachineKeySet)
            };

            var token   = aping.GetSession(authParams);
            var appKeys = aping.GetDeveloperAppKeys(token);
            var app     = appKeys.First();

            cookieCollection.Add(new Cookie(AuthField.Token.ToString(), token, "/", "BetFair.com"));
            cookieCollection.Add(new Cookie(AuthField.ApiKey.ToString(), BetFairData.ApiKey, "/", "BetFair.com"));
            cookieCollection.Add(new Cookie(AuthField.Developer.ToString(), app.AppVersions[0].ApplicationKey, "/", "BetFair.com"));
            cookieCollection.Add(new Cookie(AuthField.Customer.ToString(), app.AppVersions[1].ApplicationKey, "/", "BetFair.com"));

            return(cookieCollection);
        }
예제 #4
0
        /// <summary>
        /// Получение сессии
        /// </summary>
        /// <param name="authParams"></param>
        /// <returns>Session Token (ssoid)</returns>
        public string GetSession(AuthParams authParams)
        {
            using (var wc = this.GetBetWebClient(this.ApiKey))
            {
                if (authParams.UseCertificate && authParams.Certificate != null)
                {
                    wc.BeforeRequest = x => x.ClientCertificates.Add(authParams.Certificate);
                }

                var values = new NameValueCollection
                {
                    { "username", authParams.Login },
                    { "password", authParams.Password }
                };


                var request = wc.Post <LoginResult>("https://identitysso-cert.betfair.com/api/certlogin", values);

                if (request.LoginStatus == "SUCCESS")
                {
                    return(request.SessionToken);
                }

                throw new System.Exception(request.LoginStatus);
            }
        }
예제 #5
0
        /// <summary>
        /// Asynchronously request an authentication key based on the provided username and password.  When the request completes
        /// AuthTokenRequestComplete will be fired.  This does not need to be called every time the user wishes to stream.  A valid
        /// auth token can be saved locally between sessions and restored by calling SetAuthToken.  If a request for a new auth token is made
        /// it will invalidate the previous valid auth token.  If successful, this will proceed to log the user in and will fire LoginAttemptComplete
        /// with the result.
        /// </summary>
        /// <param name="username">The account username</param>
        /// <param name="password">The account password</param>
        /// <returns>Whether or not the request was made</returns>
        public virtual bool RequestAuthToken(string username, string password)
        {
            if (this.IsIngestTesting || !m_SdkInitialized)
            {
                return(false);
            }

            Logout();

            m_UserName = username;

            AuthParams authParams = new AuthParams();

            authParams.UserName     = username;
            authParams.Password     = password;
            authParams.ClientSecret = this.ClientSecret;

            ErrorCode err = m_Stream.RequestAuthToken(authParams);

            CheckError(err);

            if (Error.Succeeded(err))
            {
                SetBroadcastState(BroadcastState.Authenticating);
                return(true);
            }

            return(false);
        }
예제 #6
0
        public async Task <Boolean> Auth(string restUrl, string username, string password)
        {
            if (client == null)
            {
                return(false);
            }
            AuthParams authParams = new AuthParams();

            authParams.username = username;
            authParams.password = password;

            string myContent = JsonConvert.SerializeObject(authParams);

            try
            {
                string str = await client.Post(_apiBaseUrl + restUrl, myContent);

                AuthResult objs = JsonConvert.DeserializeObject <AuthResult>(str);
                client.SetToken(objs.token);
                authResult = objs;
                return(objs.auth);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #7
0
        public async Task <IActionResult> Authenticate([FromBody] AuthParams authParams)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var signInResult = await SignInManager.PasswordSignInAsync(authParams.Name,
                                                                       authParams.Password,
                                                                       true,
                                                                       false);

            if (signInResult.Succeeded)
            {
                var userResult = await UserManager.FindByNameAsync(authParams.Name);

                var token = await TokenService.Create(authParams.Name, userResult.Alias);

                return(Ok(new ChatUserAuthDescription {
                    Alias = userResult.Alias, Token = token
                }));
            }

            return(Unauthorized());
        }
        public YtbVideoPageDownloadService(AuthParams authParams)
        {
            this.authParams = authParams;

            httpService          = new YtbVideoPageHttpService();
            firstPageHttpService = new YtbVideoFirstPageHttpService();

            urlTemplate  = $"{BaseUrl}/browse_ajax?ctoken={{0}}&continuation={{1}}";
            firstPageUrl = $"{BaseUrl}/feed/history?pbj=1";
        }
예제 #9
0
        public async Task SignIn(AuthParams param)
        {
            var user = await userSession.ValidateCredentialsAsync(param);

            if (user == null)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }
            await HttpContext.SignInAsync(user, param.RememberMe);
        }
예제 #10
0
        public string Post([FromBody] AuthParams value)
        {
            var user = _context.Users.Where(u => u.Email == value.email && u.Password == value.password).ToArray();

            if (user.Length == 0)
            {
                return("incorrect auth data");
            }

            var token = GenerateToken();

            return(token);
        }
예제 #11
0
 public void LoadAuthParams(string fileName)
 {
     try
     {
         logger.Info("Loading auth params: {0}", fileName);
         if (string.IsNullOrWhiteSpace(fileName))
         {
             throw new ArgumentNullException("fileName", "Filename cannot be empty!");
         }
         if (!File.Exists(fileName))
         {
             throw new FileNotFoundException(string.Format("File \"{0}\" does not exist!", fileName), fileName);
         }
         _sAuthParamFileName = fileName;
         string sDecrypted = string.Empty;
         using (StreamReader srReader = new StreamReader(_sAuthParamFileName))
         {
             string sEncrypted = srReader.ReadToEnd();
             logger.Debug("Loaded file. length:{0}", sEncrypted.Length);
             if (string.IsNullOrWhiteSpace(sEncrypted))
             {
                 throw new ArgumentNullException("File is empty!");
             }
             //sDecrypted = CryptoUtils.DecryptString(sEncrypted);
             // HACK - ProtectedData.Protect only works on the same machine. don't need anything extra, so a base64+rot13 will do... :(
             sDecrypted = CryptoUtils.SimpleDecrypt(sEncrypted);
         }
         using (MemoryStream msStream = new MemoryStream(Encoding.UTF8.GetBytes(sDecrypted)))
         {
             logger.Debug("Decrypted file. length:{0}", msStream.Length);
             if (msStream.Length == 0)
             {
                 throw new ArgumentException("Not a valid key file! (Decrypt error)");
             }
             XmlSerializer ser = new XmlSerializer(AuthParams.GetType());
             AuthParams = (OAuth2Parameters)ser.Deserialize(msStream);
         }
         logger.Debug("Loading done");
         if (!NeedsAuthorization)
         {
             _refreshToken();
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex, "Error while loading OAuth2Parameters from file \"{0}\": {1}", fileName, ex.Message);
         throw new Exception(string.Format("Error while loading OAuth2Parameters from file \"{0}\": {1}", fileName, ex.Message), ex);
     }
 }
예제 #12
0
 public static void Main(string[] args)
 {
     try
     {
         var authParams = new AuthParams(
             OAuthGrantType.ClientCredentials,
             new List <Scope> {
             Scope.BmbyhoodWriteScope
         },
             "",
             ""
             );
     }
     catch (Exception ex)
     {
     }
 }
예제 #13
0
        public string Post([FromBody] AuthParams value)
        {
            var users = _context.Users.Where(u => u.Email == value.email).ToArray();

            if (users.Length != 0)
            {
                return("user already exist");
            }

            var user = new User
            {
                Email    = value.email,
                Password = value.password
            };

            _context.Users.Add(user);
            _context.SaveChanges();
            return("success");
        }
예제 #14
0
        static async void Download()
        {
            var authParams = new AuthParams
            {
                Cookie                   = "VISITOR_INFO1_LIVE=WKRX3izQ8RI; YSC=6sVMmvB6EfI; LOGIN_INFO=AFmmF2swRgIhAMKT7RF2fCP2cWPwbk2FrH42Gqfq0iAxcdP7eRkgbD1fAiEAx8D-w06SKo8Fkg5Z45r849QsPn5LlkDq-d_pbJTLE48:QUQ3MjNmeVdGbkdkcHpHMHRzcGQyTTFRMlJ2Rm5lZzJHUllOMUpyTlJYYWcyZjJ4Y3UwU1o2RUk1cC10SWRYMHRYNFNCeE9QdXEtUjR6UnNpMUVvQVUtZ2xSNXJkcDZyNWlDcjNpR1d4WTlpM2FEZWxoU1ZmLWk3T2Y4ZkZkVzlJUTRMUlBITUp0bzh1bGNEWHFYb05KMl9BVzNtZ3RrV1Nnb0FUbTlDQXZVZjc5a0pKR3JVT0FV; SID=Pwafz7p6hFkKvNYQgpSucd39yWfK3eCtGUNMLszhYKIBbTrDFyUmVXo5Iqw6hLYw7rV1vA.; HSID=AKPbdY38rPNybw0_w; SSID=AmjCuxgeWr0MOd30D; APISID=MhrptDn8XqWzn9Pk/Ao5fY7xkvFzH5F2qa; SAPISID=w0WiLi2c4lzws6PX/As9Xumm0iTI2gw5en; wide=0; PREF=f1=50000000&al=en+ru&f5=30000&f6=1",
                CToken                   = "4qmFsgIZEglGRWhpc3RvcnkaDENPMnc1cHZRdXR3Qw%253D%253D",
                SessionToken             = "QUFFLUhqbVd3YzQzVDFVUUdpUlFud1psTHdBMGtMVVpvZ3xBQ3Jtc0ttUkdKSmlsQjFRSDVTbjdrZTdZVG9VZWhKQmNRdFRTbExIamp3NksxYTkwRGtRQ1NlUlEyZEVZbmlTLXYwMWdCTmdpdXZZUUUyamcxWHotSHRoY0tKNW5aTmZzUDZhbVhTX2o2WHZmYVRZcnhXZjdpcE1ORGNVUXlqSUN1bXZGQmFqakg1UEswc1BFX0Y3emRaOVFDMHJ5MzVDanc%3D",
                XClientData              = "CI+2yQEIo7bJAQjEtskBCKmdygEI2J3KAQjancoBCKijygEIgqTKAQiUp8oB",
                XYoutubeIdentityToken    = "QUFFLUhqbkhNVkc0NjNOaUJGNm0wOTN4N0o0Rkx6MGZ2d3w=",
                XYoutubePageCl           = "207856115",
                XYoutubePageLabel        = "youtube.ytfe.desktop_20180807_8_RC1",
                XYoutubeVariantsChecksum = "aea0182d8fdec10710d63a72f6917a1f"
            };

            var downloader = new YtbVideoPageDownloadService(authParams);

            var continuation = (string)null;
            // var continuation = "4qmFsgIZEglGRWhpc3RvcnkaDENOdkFvLTNLMnJ3Qw%3D%3D";
            var total = 0;
            var i     = 0;

            while (true)
            {
                var page = await downloader.GetPage(continuation);

                total += page.Videos.Count();
                Console.WriteLine(i++ + " - " + total);

                continuation = page.ContinuationToken;

                SavePage(page);

                if (String.IsNullOrWhiteSpace(continuation))
                {
                    break;
                }
            }

            Console.WriteLine("DONE");
        }
예제 #15
0
 public DreamsRest(string baseUrl, AuthParams authParams) : base(baseUrl, authParams)
 {
 }
예제 #16
0
 public ClientsRest(string baseUrl, AuthParams authParams) : base(baseUrl, authParams)
 {
 }
예제 #17
0
 public CrmTasksRest(string baseUrl, AuthParams authParams) : base(baseUrl, authParams)
 {
 }
예제 #18
0
 public ApiAuthAttribute(AuthParams mandatory = AuthParams.None)
     : base(mandatory | AuthParams.Mobile)
 {
 }
예제 #19
0
 public JsonAuthAttribute(AuthParams mandatory = AuthParams.None)
     : base(mandatory)
 {
 }
예제 #20
0
        /// <summary>
        /// Asynchronously request an authentication key based on the provided username and password.  When the request completes 
        /// AuthTokenRequestComplete will be fired.  This does not need to be called every time the user wishes to stream.  A valid 
        /// auth token can be saved locally between sessions and restored by calling SetAuthToken.  If a request for a new auth token is made
        /// it will invalidate the previous valid auth token.  If successful, this will proceed to log the user in and will fire LoginAttemptComplete
        /// with the result.
        /// </summary>
        /// <param name="username">The account username</param>
        /// <param name="password">The account password</param>
        /// <returns>Whether or not the request was made</returns>
        public virtual bool RequestAuthToken(string username, string password)
        {
            if (this.IsIngestTesting || !m_SdkInitialized)
            {
                return false;
            }

            Logout();

            m_UserName = username;

            AuthParams authParams = new AuthParams();
            authParams.UserName = username;
            authParams.Password = password;
            authParams.ClientSecret = this.ClientSecret;

            ErrorCode err = m_Stream.RequestAuthToken(authParams);
            CheckError(err);

            if (Error.Succeeded(err))
            {
                SetBroadcastState(BroadcastState.Authenticating);
                return true;
            }

            return false;
        }
예제 #21
0
 public EmailRest(string baseUrl, AuthParams authParams) : base(baseUrl, authParams)
 {
 }
예제 #22
0
 public BmbyhoodRest(string baseUrl, AuthParams authParams) : base(baseUrl, authParams)
 {
 }
예제 #23
0
 public MbeatRest(string baseUrl, AuthParams authParams)
 {
     _restClient = new RestClient(baseUrl);
     _authParams = authParams;
 }
예제 #24
0
 public OwnersRest(string baseUrl, AuthParams authParams) : base(baseUrl, authParams)
 {
 }
예제 #25
0
 public AuthAttribute(AuthParams mandatory = AuthParams.None)
 {
     this.mandatory = mandatory;
 }