Код: Выделить всё
[System.Web.Http.AcceptVerbs("GET")]
[System.Web.Http.Route("api/shopify/install")]
public IHttpActionResult Install(string shop)
{
logger.Info("Start Install : ");
//string req = string.Format("https://{0}/admin/oauth/authorize?client_id={1}&scope={2}&redirect_uri=https://{3}/api/shopify/auth", shop, AppKey, Scope, CurrentURL);
var installUrl = $"https://{shop}/admin/oauth/authorize" + $"?client_id={AppKey}&scope={Scope}&redirect_uri=https://{CurrentURL}/api/shopify/auth";
return Redirect(installUrl);
}
Auth function
[System.Web.Http.AcceptVerbs("GET")]
[System.Web.Http.Route("api/shopify/auth")]
public HttpResponseMessage auth(string shop, string code, string host)
{
logger.Info("Start auth");
if (!VerifyShopifyRequest(null))
{
logger.Info("install method: Unauthorized shopify request");
//return Redirect($"https://{shop}/admin/apps");
return new HttpResponseMessage(HttpStatusCode.Unauthorized)
{
Content = new StringContent(Helper.ApiResponse("error", "Unauthorized"))
};
}
var AccessToken = GetToken(shop, code);
HttpResponseMessage responseUrl = null;
string WebHookToken = Guid.NewGuid().ToString("N").ToLower();
#region Insert Details to our Database
if (AccessToken != null)
{
//got the Access token
responseUrl = SetWebHookDynamic(shop, AccessToken, WebHookToken);
return responseUrl;
}
Отказался создать кадр «xx.myshopify.com/», потому что предок нарушает следующую директиву Политики безопасности контента: «frame-ancestors 'none'». Затем я использовал Appbridge для устранения этой ошибки и создал такую функцию установки.
Код: Выделить всё
Install Function
[System.Web.Http.AcceptVerbs("GET")]
[System.Web.Http.Route("api/shopify/install")]
public HttpResponseMessage install(string shop, string host = "")
{
logger.Info("Start Install : ");
if (!VerifyShopifyRequest(null))
{
logger.Info("install method: Unauthorized shopify request");
return new HttpResponseMessage(HttpStatusCode.Unauthorized)
{
Content = new StringContent(Helper.ApiResponse("error", "Unauthorized"))
};
}
string authRedirectUrl = string.Format("https://{0}/admin/oauth/authorize?client_id={1}&scope={2}&redirect_uri=https://{3}/api/shopify/auth", shop, AppKey, Scope, CurrentURL);
string htmlContent = $@"
document.addEventListener('DOMContentLoaded', function () {{
var AppBridge = window['app-bridge'];
var createApp = AppBridge.default;
if (window.top == window.self) {{
window.location.assign('{authRedirectUrl}');
}} else {{
var app = createApp({{
apiKey: '{AppKey}',
host: '{host}',
shopOrigin: '{shop}',
forceRedirect: true
}});
var Redirect = AppBridge.actions.Redirect;
Redirect.create(app).dispatch(Redirect.Action.REMOTE, '{authRedirectUrl}');
window.location.assign('{authRedirectUrl}');
}}
}});
";
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(htmlContent, System.Text.Encoding.UTF8, "text/html")
};
}
После перекрестной проверки URL-адреса ApiKey, SecretKey, Scope и Redirect верны. Не могли бы вы обратить внимание на эту проблему? Дайте мне знать, если вам нужна дополнительная информация или что-то в этом роде.
Подробнее здесь: https://stackoverflow.com/questions/791 ... hopify-app