public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { // strip the .myshopify.com in case they added it string shopName = model.ShopName.Replace(".myshopify.com", String.Empty); // prepare the URL that will be executed after authorization is requested Uri requestUrl = this.Url.RequestContext.HttpContext.Request.Url; Uri returnURL = new Uri(string.Format("{0}{1}", ConfigurationManager.AppSettings["Shopify.AppUrl"], this.Url.Action("ShopifyAuthCallback", "Account"))); var authorizer = new ShopifyAPIAuthorizer(shopName, ConfigurationManager.AppSettings["Shopify.ConsumerKey"], ConfigurationManager.AppSettings["Shopify.ConsumerSecret"]); var authUrl = authorizer.GetAuthorizationURL(new string[] { ConfigurationManager.AppSettings["Shopify.Scope"] }, returnURL.ToString()); return Redirect(authUrl); } return View(model); }
public async Task<ActionResult> ShopifyAuthCallback(string code, string shop, string error) { if (!String.IsNullOrEmpty(error)) { this.TempData["Error"] = error; return RedirectToAction("Login"); } if (string.IsNullOrWhiteSpace(code) || string.IsNullOrWhiteSpace(shop)) return RedirectToAction("Index", "Home"); var shopName = shop.Replace(".myshopify.com", String.Empty); var authorizer = new ShopifyAPIAuthorizer(shopName, ConfigurationManager.AppSettings["Shopify.ConsumerKey"], ConfigurationManager.AppSettings["Shopify.ConsumerSecret"]); ShopifyAuthorizationState authState = await authorizer.AuthorizeClient(code); if (authState != null && authState.AccessToken != null) { Shopify.ShopifyAuthorize.SetAuthorization(this.HttpContext, authState); } return RedirectToAction("Index", "Home"); }