Ejemplo n.º 1
0
        public IStepBuilder <TData, SubscriptionStepBody> WaitFor(string eventName, Expression <Func <TData, string> > eventKey)
        {
            var newStep = new SubscriptionStep <SubscriptionStepBody>();

            newStep.EventName = eventName;
            newStep.EventKey  = eventKey;
            WorkflowBuilder.AddStep(newStep);
            var stepBuilder = new StepBuilder <TData, SubscriptionStepBody>(WorkflowBuilder, newStep);

            Step.Outcomes.Add(new StepOutcome()
            {
                NextStep = newStep.Id
            });
            return(stepBuilder);
        }
Ejemplo n.º 2
0
        private AuthResponseCode RunAuthorizationProcess(string appId, string redirectUrl, string scope, PrivateAuthentication privateApiAuthData, string code = "code")
        {
            ResultOauthCode   = null;
            SubscriptionTrace = SubscriptionStep.NotStarted;
            var publicApiServerUri = new Uri(TestConfig.GetValueFromConfig("PublicServer"));
            var webServerUrl       = new Uri(TestConfig.GetValueFromConfig("BaseURI"));
            var cookiesCollector   = new Dictionary <string, string>();

            Log("Initialising Autherisation Process");
            var response = SendRequest(new Uri(publicApiServerUri, OverrideInitialRelativeUrl ?? string.Format(InitialRelativeUrlTemplate, appId, redirectUrl, scope, code)),
                                       cookiesCollector, null, null);

            SubscriptionTrace |= SubscriptionStep.FirstOauthReqeust;
            var errorCode = CheckErrors(response.Headers.Location, response, redirectUrl);

            if (errorCode.HasValue)
            {
                response.Dispose();
                return(errorCode.Value);
            }

            var memcacheSessionId   = OverrideMemcacheSessionCookie ?? cookiesCollector["jmemcachedsessionid"];
            var secondStepUrlEnding = response.Headers.Location.PathAndQuery;

            response.Dispose();

            Uri thirdStepUrl = null;

            if (privateApiAuthData.Session == null)
            {
                Log("2nd stage. No session, do manual login");
                thirdStepUrl       = DoManualLogin(privateApiAuthData.Company, privateApiAuthData.Username, privateApiAuthData.Password, cookiesCollector, publicApiServerUri, new Uri(webServerUrl, secondStepUrlEnding));
                SubscriptionTrace |= SubscriptionStep.ManualLogin;
                errorCode          = CheckErrors(thirdStepUrl, null, redirectUrl);
                if (errorCode.HasValue)
                {
                    return(errorCode.Value);
                }
            }
            else
            {
                Log("2nd stage. Use existing session.");
                var version       = GetVersion(privateApiAuthData);
                var useLoginToken = version.CompareTo(HrbcVersion.Parse("3.12.23")) >= 0;
                Log($"HRBC Version {version}. UseLoginToken={useLoginToken}.");
                response = SendRequest(new Uri(webServerUrl, secondStepUrlEnding), useLoginToken
                    ? new Dictionary <string, string> {
                    ["HRBCAUTH"] = privateApiAuthData.Session
                }
                    : new Dictionary <string, string> {
                    ["PHPSESSID"] = privateApiAuthData.Session, ["HRBCACCOUNT"] = privateApiAuthData.Account
                }, null, null);

                errorCode = CheckErrors(response.Headers.Location, response, redirectUrl);
                if (errorCode.HasValue)
                {
                    response.Dispose();
                    return(errorCode.Value);
                }

                thirdStepUrl = new Uri(publicApiServerUri, response.Headers.Location.PathAndQuery);
                response.Dispose();
            }

            if (!SkipAuthorisationConfirmation)
            {
                if (AuthSessionUrlQueryCustomisation != null && thirdStepUrl.Query.Contains("session="))
                {
                    thirdStepUrl = new Uri(new string(thirdStepUrl.AbsoluteUri.TakeWhile(x => x != '?').ToArray()) + AuthSessionUrlQueryCustomisation(thirdStepUrl.Query));
                }

                Log("Auth confimation");
                response = SendRequest(thirdStepUrl, new Dictionary <string, string> {
                    ["jmemcachedsessionid"] = memcacheSessionId
                }, null, null);
                SubscriptionTrace |= SubscriptionStep.AuthorisationConfirmation;

                errorCode = CheckErrors(response.Headers.Location, response, redirectUrl, false);
                response.Dispose();
                if (errorCode.HasValue)
                {
                    return(errorCode.Value);
                }
            }

            Log("Finalise");
            response = SendRequest(new Uri(publicApiServerUri, "/v1/authorization"), new Dictionary <string, string> {
                ["jmemcachedsessionid"] = memcacheSessionId
            }, null, DenyAuthorizaton ? "permission=deny" : "permission=accept");
            SubscriptionTrace |= SubscriptionStep.AuthorisationConfirmationChoiseMade;
            errorCode          = CheckErrors(response.Headers.Location, response, redirectUrl);
            response.Dispose();
            if (errorCode.HasValue)
            {
                return(errorCode.Value);
            }

            return(AuthResponseCode.Success);
        }