async function processPutRequest(ctx, req, res, permissions) {
  let token;
  if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
    token = req.headers.authorization.split(' ')[1];
  } else {
    token = req.query && req.query.access_token;
  }
  let ip;
  if (req.query.ip) {
    ip = req.query.ip;
  } else {
    ip = proxyaddr.all(req).slice(-1)[0];
  }
  if (!isIp.v4(ip)) {
    res.writeHead(400, { 'Content-Type': 'text/plain' });
    res.end("ip parameter is not a valid IPv4 address");
  }
  try {
    jwt.verify(token,
      ctx.secrets.API_SECRET,
      {
        audience: ctx.secrets.API_ID,
        issuer: 'https://' + ctx.secrets.AUTH0_DOMAIN + '/'
      });
    const result = await permissions.authorize(ip);
    await permissions.revokeExpired().catch((error) => { console.log(error) });
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end(JSON.stringify(result, null, 2));
  } catch (error) {
    console.log(error);
    res.writeHead(500, { 'Content-Type': 'text/plain' });
    res.end((error instanceof Error) ? error.stack : JSON.stringify(error, null, 2));
  }
}
/**
 * PUT -> Add IP from other script.  
 * Valid token needs to be present.  (client credentials grant can be used)
 */
> Add IP from other script.
Valid token needs to be present.  (client credentials grant can be used)
> Add IP from other script . Valid token needs to be present . ( client credentials grant can be used )
async function processPutRequest(ctx, req, res, permissions) {
  let token;
  if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
    token = req.headers.authorization.split(' ')[1];
  } else {
    token = req.query && req.query.access_token;
  }
  let ip;
  if (req.query.ip) {
    ip = req.query.ip;
  } else {
    ip = proxyaddr.all(req).slice(-1)[0];
  }
  if (!isIp.v4(ip)) {
    res.writeHead(400, { 'Content-Type': 'text/plain' });
    res.end("ip parameter is not a valid IPv4 address");
  }
  try {
    jwt.verify(token,
      ctx.secrets.API_SECRET,
      {
        audience: ctx.secrets.API_ID,
        issuer: 'https://' + ctx.secrets.AUTH0_DOMAIN + '/'
      });
    const result = await permissions.authorize(ip);
    await permissions.revokeExpired().catch((error) => { console.log(error) });
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end(JSON.stringify(result, null, 2));
  } catch (error) {
    console.log(error);
    res.writeHead(500, { 'Content-Type': 'text/plain' });
    res.end((error instanceof Error) ? error.stack : JSON.stringify(error, null, 2));
  }
}
async function processPutRequest ( ctx , req , res , permissions ) { let token ; if ( req . headers . authorization && req . headers . authorization . split ( ' ' ) [ 0 ] === 'Bearer' ) { token = req . headers . authorization . split ( ' ' ) [ 1 ] ; } else { token = req . query && req . query . access_token ; } let ip ; if ( req . query . ip ) { ip = req . query . ip ; } else { ip = proxyaddr . all ( req ) . slice ( - 1 ) [ 0 ] ; } if ( ! isIp . v4 ( ip ) ) { res . writeHead ( 400 , { 'Content-Type' : 'text/plain' } ) ; res . end ( "ip parameter is not a valid IPv4 address" ) ; } try { jwt . verify ( token , ctx . secrets . API_SECRET , { audience : ctx . secrets . API_ID , issuer : 'https://' + ctx . secrets . AUTH0_DOMAIN + '/' } ) ; const result = await permissions . authorize ( ip ) ; await permissions . revokeExpired ( ) . catch ( ( error ) => { console . log ( error ) } ) ; res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ; res . end ( JSON . stringify ( result , null , 2 ) ) ; } catch ( error ) { console . log ( error ) ; res . writeHead ( 500 , { 'Content-Type' : 'text/plain' } ) ; res . end ( ( error instanceof Error ) ? error . stack : JSON . stringify ( error , null , 2 ) ) ; } }
PUT -> Add IP from other script.
PUT - > Add IP from other script .