Not authenticating with session tokens in App Distribution.

Not authenticating with session tokens in App Distribution.

Surendu
Shopify Partner
1 0 1

 

I am developing a Shopify app using Shopify C# (ShopifySharp), and it is working fine in the test environment. However, when I try to push the app to production, I encounter the error: "Not authenticating with session tokens" in App Distribution.
I do not understand how to implement session tokens in my application or the necessary steps. I have already validated the JWT token and request, but the issue in App Admin Distribution remains unresolved.

Please help me. Thank you in advance.

 

my code is:

public ActionResult Install(string shop, string signature, string timestamp, string host, string session, string id_token) {

var _shopifyRequestValidationUtility = new ShopifyRequestValidationUtility();

if (!_shopifyRequestValidationUtility.IsAuthenticRequest(Request.QueryString.ToString(), _secretKey)) {
return new ContentResult() {
Content = "",
StatusCode = StatusCodes.Status401Unauthorized,
};
}
if (!CommonHelperServices.ValidateJWTToken(id_token, _secretKey)) {
return new ContentResult() {
Content = "",
StatusCode = StatusCodes.Status401Unauthorized,
};
}

string redirectUrl = _appUrl + "/auth";
var _store = storeServices.GetStore(shop.Trim());

var _shopifyOauthUtility = new ShopifyOauthUtility();
Uri authUrl = _shopifyOauthUtility.BuildAuthorizationUrl(new AuthorizationUrlOptions() {
ClientId = _apiKey,
RedirectUrl = redirectUrl,
Scopes = new List < string > () {
"read_products",
"write_products",
"unauthenticated_read_product_listings",
"read_product_listings",
"read_collection_listings",
"unauthenticated_read_collection_listings",
"write_content",
"write_price_rules",
"read_discounts",
"write_discounts",
"read_orders",
"read_themes"
},
ShopDomain = shop,
State = session
});

string _host = Encription.Base64DecodeCrypto(host + "=");
bool UrlRedirection = false;
if (_host.Contains("admin.shopify.com")) {
UrlRedirection = true;
}

if (_store.StoreId > 0 && _store.IsActive && UrlRedirection) {
var url = authUrl.ToString() + "&host=" + shop + "&forceRedirect=true";
url = authUrl.ToString().Replace(shop, "admin.shopify.com/store/" + _store.MyShopifyDomain.ToLower().Replace(".myshopify.com", ""));
return Redirect(url);
} else {
return Redirect(authUrl.ToString());
}

}

public async Task < ActionResult > Auth(string shop, string code) {
string redirectUrl = "";

AuthOutputModel model = new AuthOutputModel() {
Shop = Encription.Encrypt(shop)
};
string shopAccessToken = string.Empty;

try {
var _shopifyRequestValidationUtility = new ShopifyRequestValidationUtility();
if (_shopifyRequestValidationUtility.IsAuthenticRequest(Request.QueryString.ToString(), _secretKey)) {
model.IsValidData = true;

var _shopifyOauthUtility = new ShopifyOauthUtility();
var AuthorizeResult = await _shopifyOauthUtility.AuthorizeAsync(code, shop, _apiKey, _secretKey);

if (!string.IsNullOrEmpty(AuthorizeResult.AccessToken)) {
// app business code here

} else {
return new ContentResult() {
Content = "",
StatusCode = StatusCodes.Status401Unauthorized,
};

}
}

return new ContentResult() {
Content = "",
StatusCode = StatusCodes.Status401Unauthorized,
};

} catch (Exception ex) {
return new ContentResult() {
Content = "",
StatusCode = StatusCodes.Status401Unauthorized,
};

}

 

Reply 1 (1)

KaustavDharmah
Shopify Partner
5 0 4

Did you manage to solve this?