public ActionResult Index(string state, string code)
        {
            string error        = string.Empty;
            var    sessionState = HttpContext.Session["state"];

            if (sessionState.Equals(state))
            {
                OidcModel oauthModel = SuperOfficeAuthHelper.GetOAuthModel(code);

                if (SuperOfficeAuthHelper.TryLogin(oauthModel, out error))
                {
                    var context = SuperOfficeAuthHelper.Context;

                    //Store the System User Information in the Database
                    CustomerDataSource dataSource = new CustomerDataSource();
                    var customer = dataSource.Customers.FirstOrDefault(c => c.ContextIdentifier == context.ContextIdentifier);

                    //var databaseContext = new PartnerDatabaseContext();
                    //var customer = databaseContext.Customers.FirstOrDefault(c => c.ContextIdentifier == context.ContextIdentifier);
                    if (customer == null)
                    {
                        dataSource.Customers.Add(new CustomerInfo
                        {
                            AssociateID       = context.AssociateId,
                            ContextIdentifier = context.ContextIdentifier,
                            IsActive          = true,
                            LastSync          = new DateTime(2000, 1, 1),
                            SystemUserToken   = context.SystemToken
                        });
                        dataSource.Save();
                    }

                    // Redirect to original request
                    var redirectUr = Session["RedirectUrl"] as string;

                    if (!String.IsNullOrEmpty(redirectUr))
                    {
                        return(Redirect(redirectUr));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            return(RedirectToAction("Welcome", "Home", new { Error = error }));
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string error = string.Empty;

            SetupVisibleParts();

            var requestType = Context.Request.RequestType;

            if (requestType.ToUpper() == "POST")
            {
                var callbackModel = new CallbackModel
                {
                    Saml = Context.Request["saml"],
                    Jwt  = Context.Request["jwt"],
                };


                if (SuperOfficeAuthHelper.TryLogin(callbackModel, out error))
                {
                    var redirectUr = Context.Session["RedirectUrl"] as string;
                    Context.Session["RedirectUrl"] = "";

                    if (!String.IsNullOrEmpty(redirectUr))
                    {
                        Context.Response.Redirect(redirectUr);
                    }
                }
                else
                {
                    explanationText.Visible   = true;
                    explanationText.InnerText = "Login unsuccessful, reason: " + error;
                }
            }
            else
            {
                var code  = Context.Request["code"];
                var state = Context.Request["state"];

                var sessionState = Context.Session["state"] as string;

                if (sessionState.Equals(state))
                {
                    OidcModel oauthModel = SuperOfficeAuthHelper.GetOAuthModel(code);

                    if (SuperOfficeAuthHelper.TryLogin(oauthModel, out error))
                    {
                        var redirectUr = Context.Session["RedirectUrl"] as string;
                        Context.Session["RedirectUrl"] = "";

                        if (!String.IsNullOrEmpty(redirectUr))
                        {
                            Context.Response.Redirect(redirectUr);
                        }
                    }
                }
                else
                {
                    explanationText.Visible   = true;
                    explanationText.InnerText = "Login unsuccessful, reason: " + error;
                }
            }
        }