Exemplo n.º 1
0
        public async Task LogIn(string username, string password)//For Helprace Login (sso)
        {
            //mock data of users
            List <Employee> employeeList = new List <Employee>
            {
                new Employee {
                    Name = "shubham", Password = "******", Email = "*****@*****.**", Role = "user"
                },
                new Employee {
                    Name = "Ansh", Password = "******", Email = "*****@*****.**", Role = "user"
                },
                new Employee {
                    Name = "Arbaz", Password = "******", Email = "*****@*****.**", Role = "user"
                },
                new Employee {
                    Name = "Sumit", Password = "******", Email = "*****@*****.**", Role = "user"
                },
                new Employee {
                    Name = "Shubham", Password = "******", Email = "*****@*****.**", Role = "user"
                }
            };

            foreach (Employee employee in employeeList)
            {
                //If user is authenticated successfully then generate his token and redirect to helprace
                if (username == employee.Name & password == employee.Password)
                {
                    string token = TokenGeneration.GenerateToken(employee);
                    HttpContext.Response.Redirect("https://auth.helprace.com/jwt/csharp?jwt=" + token + "&return_to=https://csharp.helprace.com/");
                }
            }
            HttpContext.Response.Redirect("https://jwt20180415100039.azurewebsites.net/Home/Error");
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Login(LogInModel LogModel, String returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(LogModel));
            }

            SessionWrapper newSession = null;

            try {
                var Token = await TokenGeneration.FetchToken(LogModel.Username, LogModel.Password);

                Token = (JObject.Parse(Token))["message"].ToString();


                if (Token.Split('.').Length != 3)
                {
                    throw new Exception();
                }

                newSession = new SessionWrapper(LogModel.Username, LogModel.Password, Token, LogModel, Session);
            }
            catch {
                newSession = null;
            }

            if (newSession != null && newSession.LogIn())
            {
                _Session = newSession;

                var loginClaim     = new Claim(ClaimTypes.NameIdentifier, LogModel.Username);
                var claimsIdentity = new ClaimsIdentity(
                    new[] {
                    loginClaim,
                    new Claim(ClaimTypes.Name, LogModel.Username)
                },

                    DefaultAuthenticationTypes.ApplicationCookie
                    );

                var ctx = Request.GetOwinContext();
                var authenticationManager = ctx.Authentication;
                authenticationManager.SignIn(claimsIdentity);

                _UserNotifications = newSession.WorkstationSession.GetAllNotifications((int)newSession.CurrentUser.id);
                _UserRights        = RightsReader.Decode(newSession.CurrentUser.rights) as Dictionary <String, bool>;

                Session.Add("HubInitialized", false);
                NotificationHub.MyUsers.TryAdd(newSession.CurrentUser.username, newSession);

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "Either the username or the password is incorrect!");
            }
            return(View(LogModel));
        }
Exemplo n.º 3
0
        public string QueryPayCode(String SessionKey, String payCode, String subscriberId)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            ServicePointManager.SecurityProtocol =
                (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls) | (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12);

            var iswResponse = string.Empty;

            try
            {
                String additionalParameters = "";


                QueryPayCodeStatus req = new QueryPayCodeStatus();
                req.paycode      = payCode;
                req.subscriberID = subscriberId;

                //String hashKey = Hash512("GENTOKEN" + tokenrequest.accountNo + tokenrequest.oneTimePin + tokenrequest.subscriberId);

                TokenGeneration generation = new TokenGeneration();
                iswResponse = generation.QueryPaycode("", subscriberId, req);
                nLogger.Info("Before Getting Authorisation");
                nLogger.Info("response :::::: " + iswResponse);
            }
            catch (WebException ex)
            {
                nLogger.Info(ex.ToString());
                try
                {
                    using (WebResponse response = ex.Response)
                    {
                        HttpWebResponse httpResponse = (HttpWebResponse)response;
                        nLogger.Info("Error code: {0}", httpResponse.StatusCode);
                        nLogger.Info("Status Description: {0}", httpResponse.StatusDescription);
                        string text = "";
                        using (Stream data = response.GetResponseStream())
                        {
                            text = new StreamReader(data).ReadToEnd();
                            nLogger.Info(text);
                        }
                    }
                }
                catch
                { nLogger.Info("Something went wrong"); }

                nLogger.Error(ex);
            }
            catch (Exception ex)
            {
                nLogger.Error(ex);
            }

            return(iswResponse);
        }
Exemplo n.º 4
0
        public CardlessWithdrawalTransaction GeneratePayCode(String SessionKey, String SourceChannel, String AccountNumber, String subscriberID, String oneTimePin, String CIF, decimal Amount)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            ServicePointManager.SecurityProtocol =
                (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls) | (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12);



            int tokenLifeTimeInMinute = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["tokenLifeExpiryInMinutes"]);

            String accountType = "00";//00- All 10-Savings 20-Current
            CardlessWithdrawalTransaction transaction = new CardlessWithdrawalTransaction();

            try
            {
                String additionalParameters = "";

                MobileTokenRequest tokenrequest = new MobileTokenRequest();

                tokenrequest.subscriberId = subscriberID;//Mandatory - AccountNumber


                String transactionreference = DateTime.Now.ToString("yyMMddHHmmssfff");
                String otp = DateTime.Now.ToString("yyMMddHHmmssfff");
                tokenrequest.oneTimePin    = oneTimePin;
                tokenrequest.providerToken = otp;// GeneratedToken;//

                if (IsLive())
                {
                    nLogger.Info("is live  credential");
                    tokenrequest.paymentMethodTypeCode = PaymentMethodTypes.MMO;   //Mandatory this is for production,
                    tokenrequest.frontEndPartnerId     = FrontEndPartners.Octopus; //Mandatory this is for production,
                    tokenrequest.paymentMethodCode     = PaymentMethods.Octopus;   //Mandatory
                }
                else
                {
                    nLogger.Info("is test  credential");
                    tokenrequest.frontEndPartnerId     = FrontEndPartners.HbOnline; //Mandatory:  this code needs to be agreed with ISW
                    tokenrequest.paymentMethodTypeCode = PaymentMethodTypes.MMO;    //Mandatory t
                    tokenrequest.paymentMethodCode     = PaymentMethods.Octopus;    //Mandatory
                }

                //tokenrequest.paymentMethodTypeCode = PaymentMethodTypes.MMO ;//Mandatory this is for test


                tokenrequest.tokenLifeTimeInMinutes = tokenLifeTimeInMinute;
                tokenrequest.payWithMobileChannel   = PayWithMobileChannels.ATM;//ATM, POS,MOBILE and WEB.
                //tokenrequest.autoEnroll = "true";
                //tokenrequest.accountNo = AccountNumber;
                //tokenrequest.accountType = accountType;
                tokenrequest.ttid = "1234";

                tokenrequest.transactionType       = TransactionTypes.CashWithdrawal; //A code to indicate the transaction type e.g Payment, Cash Withdrawal, Deposit
                tokenrequest.codeGenerationChannel = CodeGenerationChannels.Mobile;   //Conditional//A code to identify the channel where the code is generated e.g. USSD, Mobile et al
                tokenrequest.Amount = Amount;                                         // 9000.00;//Conditional


                //if (SessionKey != Hash512("GENTOKEN" + AccountNumber + Amount + subscriberID + oneTimePin + SourceChannel + CIF))
                if (false)

                {
                    transaction.TransactionReference = "67|Security Validation Failed";
                }
                else
                if ((Amount % 1000) != 0)
                {
                    transaction.TransactionReference = "67|Amount must be in multiples of 1000 (NGN).";
                }
                else if (Amount > 20000 || Amount < 1000)
                {
                    transaction.TransactionReference = "67|Amount cannot be greater than 20000 and less than 1000.";
                }
                else
                {
                    String hashKey = Hash512("GENTOKEN" + tokenrequest.oneTimePin + tokenrequest.subscriberId);
                    nLogger.Info("token request payload  :::::: " + JsonSerializer(tokenrequest));
                    TokenGeneration generation = new TokenGeneration();
                    String          response   = generation.GetAuthorizationToken(hashKey, additionalParameters, tokenrequest);
                    nLogger.Info("Before Getting AUthorisation");
                    nLogger.Info("response :::::: " + response);

                    if ((response + "").StartsWith("67|"))
                    {
                        transaction.TransactionReference = response;
                    }
                    else
                    if (response.Length > 3)
                    {
                        nLogger.Info("response :::2::: " + response);
                        TokenRequest retobject = JsonConvert.DeserializeObject <TokenRequest>(response);

                        //Send WICODE to registered Phone Number
                        //Place Lien On Account
                        //Check Available Balance
                        nLogger.Info("response :::3::: " + response);
                        transaction = new CardlessWithdrawalTransaction()
                        {
                            SourceChannel         = SourceChannel,
                            AccountNumber         = AccountNumber,
                            CodeGenerationChannel = tokenrequest.codeGenerationChannel,
                            CIF = CIF,
                            FrontEndPartnerId      = tokenrequest.frontEndPartnerId,
                            OneTimePassword        = Hash512(tokenrequest.oneTimePin),
                            PaymentMethodCode      = tokenrequest.paymentMethodCode,
                            PaymentMethodTypeCode  = tokenrequest.paymentMethodTypeCode,
                            PayWithMobileChannel   = tokenrequest.payWithMobileChannel,
                            ProviderToken          = tokenrequest.providerToken,
                            RequestDate            = DateTime.Now,
                            TokenUsageCount        = 0,
                            AmountAuthorized       = 0,
                            TokenLifeTimeInMinutes = tokenrequest.tokenLifeTimeInMinutes,
                            TransactionAmount      = tokenrequest.Amount,
                            TransactionType        = tokenrequest.transactionType,
                            TransactionReference   = transactionreference,
                            PayWithMobileToken     = retobject.payWithMobileToken,
                            IsCanceled             = false,
                            IsExpired   = false,
                            IsTokenUsed = false
                        };



                        String        signatureMethod = "SHA1";
                        String        CypherKey       = String.Format("{0}|{1}|{2}", transaction.AccountNumber, transaction.ProviderToken, transaction.TransactionType);
                        MessageDigest messageDigest   = MessageDigest
                                                        .GetInstance(signatureMethod);
                        byte[] signatureBytes = messageDigest
                                                .Digest(Encoding.UTF8.GetBytes(CypherKey)); // encode signature as base 64
                        String signature = Convert.ToBase64String(signatureBytes);
                        nLogger.Info("response :::5::: " + signature);
                        transaction.AuthorizationSessionKey = signature;


                        DateTime ExpiryDate = transaction.RequestDate.Value.AddMinutes(Convert.ToInt32(transaction.TokenLifeTimeInMinutes));


                        transaction.ExpiryDate = ExpiryDate;
                        nLogger.Info("response :::6::: " + ExpiryDate);
                        nLogger.Info("response :::7:: " + JsonConvert.SerializeObject(transaction));
                        var clearPayCode = transaction.PayWithMobileToken;

                        //send mail and sms
                    }
                    else
                    {
                        nLogger.Info(response);
                        transaction.TransactionReference = "67|Cannot generate Paycode at the moment. Please try again later.";//Could not generate WICode
                    }
                }
            }
            catch (WebException ex)
            {
                nLogger.Info(ex.ToString());
                try
                {
                    using (WebResponse response = ex.Response)
                    {
                        HttpWebResponse httpResponse = (HttpWebResponse)response;
                        nLogger.Info("Error code: {0}", httpResponse.StatusCode);
                        nLogger.Info("Status Description: {0}", httpResponse.StatusDescription);
                        string text = "";
                        using (Stream data = response.GetResponseStream())
                        {
                            text = new StreamReader(data).ReadToEnd();
                            nLogger.Info(text);
                        }
                    }
                }
                catch
                { nLogger.Info("Something went wrong"); }


                transaction.TransactionReference = "67|Cannot generate Paycode at the moment. Please try again later.";
                nLogger.Error(ex);
            }
            catch (Exception ex)
            {
                transaction.TransactionReference = "67|Cannot generate Paycode at the moment. Please try again later.";
                nLogger.Error(ex);
            }

            return(transaction);
        }