How to use the lsat-js.Lsat.fromChallenge function in lsat-js

To help you get started, we’ve selected a few lsat-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tierion / boltwall / tests / paywall.spec.ts View on Github external
const middlename = req.body?.middlename
          if (caveat.value === middlename) return true
          return false
        },
      },
    }
    // get an express App with our custom options
    const middlename = 'danger'
    app = getApp(options)
    let resp = await request
      .agent(app)
      .get(protectedRoute)
      .send({ middlename })
      .expect(402)

    const lsat = Lsat.fromChallenge(resp.header['www-authenticate'])

    // make a valid lsat with secret
    lsat.setPreimage(invoiceResponse.secret)

    // make a request with the wrong body parameter
    // which should fail authorization (because macaroon won't validate)
    resp = await request
      .agent(app)
      .get(protectedRoute)
      .set('Authorization', lsat.toToken())
      .send({ middlename: 'scott' })
      .expect(401)

    // make a request with a valid request body
    resp = await request
      .agent(app)
github Tierion / boltwall / tests / paywall.spec.ts View on Github external
it('should return 402 if request has LSAT with a macaroon but no secret', async () => {
    const resp: request.Response = await request
      .agent(app)
      .get(protectedRoute)
      .set('Authorization', lsat.toToken())
      .expect(402)

    const lsatFromChallenge = Lsat.fromChallenge(resp.header['www-authenticate'])
    expect(lsatFromChallenge.baseMacaroon).to.include(
      macaroon,
      'Expected response to include the macaroon sent in Authorization header'
    )
  })

lsat-js

Utility library for working with LSAT auth tokens in javascript

MIT
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis

Similar packages