D M Patel
D M Patel

Reputation: 86

Apple Wallet Web Service For Pass Update not getting valid pkpass file with AWS API Gateway + Proxy Lambda Integration

We have integrated Apple Wallet Pass webservice with API Gateway REST API + AWS Proxy Lambda Integration.

Sending response from lambda in base64 or utf-8 encoding format but pkpass file is not transforming proper valid data.

Using this npm module : passgenerator-js

Also provided AWS Api gateway setting binary media type : '*/*'

Can someone help to send valid pkpass file over AWS Api gateway response to wallet app ?

const passGenerator = new PassGenerator({
    appleWWDRCA: appleWWDRCA,
    signCert: signCert,
    password: passKey
  }); 

const pass = passGenerator.createPass();

  console.log('pass:', pass);

  pass.add("icon.png", filesFromS3[2].Body);
  pass.add("[email protected]", filesFromS3[3].Body);
  pass.add("[email protected]", filesFromS3[4].Body);
  pass.add("logo.png", filesFromS3[5].Body);
  pass.add("strip.png", filesFromS3[6].Body);

  pass.add('pass.json', '/tmp/pass.json');
  const pkpass = pass.generate();

  console.log('pkpass:', pkpass);
  let passName = "/tmp/ApplePassKit_" + passObject.serialNumber + ".pkpass";
  console.log('passName:', passName);

  fs.writeFileSync("/tmp/ApplePassKit_" + passObject.serialNumber + ".pkpass", pkpass);

  let file = fs.readFileSync('/tmp/ApplePassKit_' + passObject.serialNumber + '.pkpass');
  console.log('file::', file);

  console.log("Content Type Mime ", mime.getType(passName));
  let binaryFile = Buffer.from(file).toString('utf-8');
  let contentDispositionHeaderValue = `attachment; filename=${passObject.serialNumber}.pkpass`;

  let responseObj = {
    'statusCode': 200,
    'headers': {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "*",
      "Access-Control-Allow-Credentials": true,
      "Access-Control-Allow-Headers": "Content-Type,X-Requested-With,X-Amz-Date,Accept,Authorization,X-Api-Key,X-Amz-Security-Token,Last-Modified,If-Modified-Since",
      "Access-Control-Expose-Headers": "Content-Disposition",
      "Content-Disposition": contentDispositionHeaderValue,
      "Content-Type": mime.getType(passName),
      "If-Modified-Since":dbResponse[0].lastUpdated,
      "Last-Modified": dbResponse[0].lastUpdated
    },
    'body': binaryFile,
    isBase64Encoded: true              
  };
  console.log('responseObj ::', responseObj);
  
  callback(null, responseObj);

Upvotes: 0

Views: 362

Answers (1)

Eliran Siboni
Eliran Siboni

Reputation: 1

You should send it as an attachment, send the buffer as base64 and the right content type.

let binaryFile = Buffer.from(file).toString('base64');
let contentDispositionHeaderValue =`attachment;filename=${passObject.serialNumber}.pkpass`;

let responseObj = {
    'statusCode': 200,
    'headers': {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "*",
      "Access-Control-Allow-Credentials": true,
      "Access-Control-Allow-Headers": "Content-Type,X-Requested-With,X-Amz-Date,Accept,Authorization,X-Api-Key,X-Amz-Security-Token,Last-Modified,If-Modified-Since",
      "Access-Control-Expose-Headers": "Content-Disposition",
      "Content-Disposition": contentDispositionHeaderValue,
      "Content-Type": "application/vnd.apple.pkpass",
      "If-Modified-Since":dbResponse[0].lastUpdated,
      "Last-Modified": dbResponse[0].lastUpdated
    },
    'body': binaryFile,
    isBase64Encoded: true              
  };

If it's not working - try to console log the buffer and see if you get any value

Upvotes: 0

Related Questions