2016-06-23 1 views
0

관리자 패널에 웹 페이지를 표시 할 수있는 Embedded APP SDK (Shopify App 구축 용)를 사용하고 있습니다. Shopify App에/shopifyApp라는 URL이 있다고 가정 해 보겠습니다. 사용자가 해당 앱을 클릭 할 때마다 그는 "/ shopifyApp"로 리디렉션됩니다. GET 요청은 /shopifyApp? HMAC = b20934d6b66cxxx & 프로토콜과 같은 = HTTPS % 3A % 2F % 2F & 가게 = dev-store-61.myshopify.com & 타임 스탬프 = I가 있는지 확인하려고 1,466,715,935Shopify Admin Panel 내에서 요청이 왔는지 감지

hmac가 유효합니다. 유효성 검사에 아래 코드를 사용하고 있지만 불행히도 작동하지 않습니다.

var map = JSON.parse(JSON.stringify(req.query)); 
    delete map['hmac']; 
    var message = querystring.stringify(map); 
    var generated_hash = require('crypto').createHmac('sha256', "myAppSecret").update(message).digest('hex'); 
    if (generated_hash === req.query.hmac) { 
     //show Authenticated page 
    } else { 
     //Show unauthenticated page 
    } 

생성 된 생성물은 어떤 이유로 hmac와 절대로 같지 않습니다. 누군가 내가 잘못하고있는 것에 관해서 나에게 조언 할 수 있습니까?

답변

0

당신은 HMAC 및 서명

function verifyRequest(req, res, next) { 
var map = JSON.parse(JSON.stringify(req.query)); 
delete map['signature']; 
delete map['hmac']; 

var message = querystring.stringify(map); 
var generated_hash = crypto.createHmac('sha256', config.oauth.client_secret).update(message).digest('hex'); 
if (generated_hash === req.query.hmac) { 
    next(); 
} else { 
    return res.json(400); 
} 

}

+0

나는 서명을 수신하지 못하는 경우를 삭제해야 – Abhik

관련 문제