public dynamic GetAccessToken(string code, string shopName) { authorizer = new ShopifyAPIAuthorizer(shopName, API_KEY, API_SECRET); var authState = authorizer.AuthorizeClient(code); return authState?.AccessToken; }
protected void Button1_Click(object sender, EventArgs e) { var authorizer = new ShopifyAPIAuthorizer(shopName, ConsumerKey, ConsumerSecret); // get the Authorization URL and redirect the user var authUrl = authorizer.GetAuthorizationURL(new string[] { ShopifyScope }, Request.Url.AbsoluteUri); Response.Redirect(authUrl); }
public string GetAuthURL(string shopName, string currentUri) { var authorizer = new ShopifyAPIAuthorizer(shopName, ConsumerKey, ConsumerSecret); // get the Authorization URL and redirect the user var authUrl = authorizer.GetAuthorizationURL(new string[] { ShopifyScope }, currentUri); return authUrl; }
public string GetAccessToken(string code, string shopName) { authorizer = new ShopifyAPIAuthorizer(shopName, API_KEY, API_SECRET); var authState = authorizer.AuthorizeClient(code); if (authState != null && authState.AccessToken != null) { var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); return authState.AccessToken; } return null; }
public string ExchangeToken(string tempToken, string shopName) { var authorizer = new ShopifyAPIAuthorizer(shopName, ConsumerKey, ConsumerSecret); // get the authorization state ShopifyAuthorizationState authState = authorizer.AuthorizeClient(tempToken); if (authState != null && authState.AccessToken != null) { return authState.AccessToken; } else return null; }
protected void GetAuthorization_Click(Object sender, EventArgs e) { string shopName = this.ShopName.Text;// get the shop name from the user (i.e. a web form) // you will need to pass a URL that will handle the response from Shopify when it passes you the code parameter Uri returnURL = new Uri(Request.Url.ToString()); var authorizer = new ShopifyAPIAuthorizer(shopName, ConfigurationManager.AppSettings["Shopify.ConsumerKey"], // In this case I keep my key and secret in my config file ConfigurationManager.AppSettings["Shopify.ConsumerSecret"]); // get the Authorization URL and redirect the user var authUrl = authorizer.GetAuthorizationURL(new string[] { ConfigurationManager.AppSettings["Shopify.Scope"] }, returnURL.ToString()); Response.Redirect(authUrl); }
// // GET: /Shopify/finalize public ActionResult Finalize() { string appGuid = Request.Params["AppGuid"]; string shopName = Request.Params["ShopName"]; string apiKey = Request.Params["ApiKey"]; string sharedSecret = Request.Params["SharedSecret"]; var authorizer = new ShopifyAPIAuthorizer(shopName, apiKey, sharedSecret); // get the following variables from the Query String of the request string error = Request.QueryString["error"]; string code = Request.Params["code"]; string shop = Request.QueryString["shop"]; // check for an error first if (!String.IsNullOrEmpty(error)) { this.TempData["Error"] = error; return RedirectToAction("Login"); } // make sure we have the code if (string.IsNullOrWhiteSpace(code) || string.IsNullOrWhiteSpace(shop)) return RedirectToAction("Index", "Home"); // get the authorization state ShopifyAuthorizationState authState = authorizer.AuthorizeClient(code); if (authState != null && authState.AccessToken != null) { using (ShopifyAppsContext context = new ShopifyAppsContext()) { var app = context.ShopifyApps.Find(new Guid(appGuid)); if (app != null) { app.ShopName = shopName; app.ApiKey = apiKey; app.SharedSecret = sharedSecret; app.AccessToken = authState.AccessToken; context.SaveChanges(); } } } return RedirectToAction("Index"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // check if there is a code or error or shop name in the query string if (!String.IsNullOrEmpty(Request.QueryString["code"])) { string shopName = Request.QueryString["shop"].Replace(".myshopify.com", String.Empty); var authorizer = new ShopifyAPIAuthorizer(shopName, ConfigurationManager.AppSettings["Shopify.ConsumerKey"], // In this case I keep my key and secret in my config file ConfigurationManager.AppSettings["Shopify.ConsumerSecret"]); Session["Shopify.AuthState"] = authorizer.AuthorizeClient(Request.QueryString["code"]); Response.Redirect("Default.aspx"); } } }
public 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 = authorizer.AuthorizeClient(code); if (authState != null && authState.AccessToken != null) { Shopify.ShopifyAuthorize.SetAuthorization(this.HttpContext, authState); } return RedirectToAction("Index", "Home"); }
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}{2}", requestUrl.Scheme, requestUrl.Authority, 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 string GetLoginUrl(string shopName) { var returnURL = new Uri(CALLBACK_URL); authorizer = new ShopifyAPIAuthorizer(shopName, API_KEY, API_SECRET); var authUrl = authorizer.GetAuthorizationURL(RIGHTS, returnURL.ToString()); return authUrl; }
// // GET: /Shopify/init public ActionResult Init() { string appGuid = Request.Params["AppGuid"]; string shopName = Request.Params["ShopName"]; string apiKey = Request.Params["ApiKey"]; string sharedSecret = Request.Params["SharedSecret"]; var root = Request.Url.GetLeftPart(UriPartial.Authority); // you will need to pass a URL that will handle the response from Shopify when it passes you the code parameter Uri returnURL = new Uri(string.Format("{0}/Shopify/finalize?appGuid={1}&shopName={2}&apiKey={3}&sharedSecret={4}", root, appGuid, shopName, apiKey, sharedSecret)); var authorizer = new ShopifyAPIAuthorizer(shopName, apiKey, sharedSecret); // get the Authorization URL and redirect the user var authUrl = authorizer.GetAuthorizationURL(new string[] { "read_content", "write_content", "read_themes", "write_themes", "read_products", "write_products", "read_customers", "write_customers", "read_orders", "write_orders", "read_script_tags", "write_script_tags" }, returnURL.ToString()); return Redirect(authUrl); }