Пример #1
0
        public dynamic GetAccessToken(string code, string shopName)
        {
            authorizer = new ShopifyAPIAuthorizer(shopName, API_KEY, API_SECRET);
            var authState = authorizer.AuthorizeClient(code);

            return authState?.AccessToken;
        }
Пример #2
0
        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;
    }
Пример #4
0
        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");
                }
            }
        }
Пример #5
0
        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");
        }
        //
        // 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");
        }