public void Get_Auth_Result_Handler_Url_Should_Returl_Valid_Url()
        {
            var data = ShopifyUrlHelper.GetAuthResultHandlerUrl(settings);

            Assert.NotNull(data);
            Assert.Equal($"{APP_BASE_URL}/shopify/{SHOPIFY_ACTIONS.AuthResult}", data);
        }
Exemplo n.º 2
0
 /// <summary>
 /// This is the method that is called first when user tries to access or install your app.
 /// This method starts the installation process (by sending to authrization url) if user is not subscribed already otherwise
 /// tries to auto login the user and sends to the landing page(dashboard).
 /// </summary>
 /// <param name="shop">The store (URL) that is trying to access app.</param>
 /// <returns></returns>
 public virtual async Task <IActionResult> Handshake(string shop)
 {
     using (Logger.BeginScope(new { Shop = shop }))
     {
         try
         {
             Logger.LogInformation("Checking request authenticity.");
             if (ShopifyAPI.IsAuthenticRequest(Request))
             {
                 Logger.LogInformation("Request is authentic.");
                 Logger.LogInformation("Checking if shop is authorized.");
                 if (UserDbServiceHelper.ShopIsAuthorized(UserDbService, shop))
                 {
                     Logger.LogInformation("Shop is already authrorized.Calling _ProceedWithShopExists.");
                     return(await _ProceedWithShopExists(shop));
                 }
                 else
                 {
                     Logger.LogWarning("Shop is NOT authrorized.Either new shop or imcomplete installation from previous attempt.So let's install it.");
                     var handlerUrl = ShopifyUrlHelper.GetAuthResultHandlerUrl(Settings);
                     Logger.LogInformation("Getting permission list.");
                     var permissions = ListPermissions();
                     Logger.LogInformation("Permission list acquiring is done. {@list}.", permissions);
                     Logger.LogInformation("Getting authorization url.");
                     var authUrl = ShopifyAPI.GetAuthorizationUrl(shop, permissions, handlerUrl);
                     Logger.LogInformation($"Redirecting to authrization url '{authUrl}'.");
                     return(Redirect(authUrl.ToString()));
                 }
             }
             else
             {
                 Logger.LogWarning("Request is NOT authentic.Throwing Exception.");
                 throw new Exception("Request is not authentic.");
             }
         }
         catch (Exception ex)
         {
             Logger.LogWarning("Error occurred while handshaking.");
             throw ex;
         }
     }
 }