Skip to content

Commit

Permalink
Updated dependencies, new Middleware option ("uriSchemaPrefix")
Browse files Browse the repository at this point in the history
  • Loading branch information
chill117 committed Jul 23, 2021
1 parent 2875a41 commit 6d185d8
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 66 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

* v1.3.0:
* Updated dependencies
* New option for Middleware - "uriSchemaPrefix"
* v1.2.2:
* Updated dependencies
* Create, use isolated handlebars to avoid conflicts
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ app.get('/login',
callbackUrl: 'http://localhost:3000/login',
// The URL of the "Cancel" button on the login page.
// When set to NULL or some other falsey value, the cancel button will be hidden.
cancelUrl: '/'
cancelUrl: '/',
// The URI schema prefix used before the encoded LNURL.
// e.g. "lightning:" or "LIGHTNING:" or "" (empty-string)
uriSchemaPrefix: 'LIGHTNING:',
// Options object passed to QRCode.toDataURL(data, options) - for further details:
// https://github.com/soldair/node-qrcode/#qr-code-options
qrcode: {
errorCorrectionLevel: 'L',
margin: 2,
type: 'image/png',
},
})
);
```
Expand Down
12 changes: 8 additions & 4 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const Middleware = function(options) {
// The URL of the "Cancel" button on the login page.
// When set to NULL or some other falsey value, the cancel button will be hidden.
cancelUrl: null,
// The URI schema prefix used before the encoded LNURL.
// e.g. "lightning:" or "LIGHTNING:" or "" (empty-string)
uriSchemaPrefix: 'LIGHTNING:',
});
options.qrcode = _.defaults(options.qrcode || {}, {
errorCorrectionLevel: 'L',
Expand Down Expand Up @@ -113,11 +116,12 @@ const getLoginPageHtml = function(k1, options) {
k1,
tag: 'login',
});
const encoded = lnurl.encode(options.callbackUrl);
return generateQrCode('lightning:' + encoded, options.qrcode).then(dataUri => {
const encoded = lnurl.encode(options.callbackUrl).toUpperCase();
const href = `${options.uriSchemaPrefix}${encoded}`;
return generateQrCode(href, options.qrcode).then(dataUri => {
const data = _.extend({}, {
encoded,
dataUri
dataUri,
href: options.uriSchemaPrefix === '' ? '#' : href,
}, _.pick(options, 'cancelUrl'));
return getTemplateHtml('login', data);
});
Expand Down
134 changes: 79 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
},
"homepage": "https://github.com/chill117/passport-lnurl-auth#readme",
"dependencies": {
"debug": "4.3.1",
"debug": "4.3.2",
"handlebars": "4.7.7",
"lnurl": "0.16.1",
"lnurl": "0.18.0",
"passport-strategy": "1.0.0",
"qrcode": "1.4.4",
"underscore": "1.13.1"
Expand All @@ -43,7 +43,7 @@
"chai": "4.3.4",
"express": "4.17.1",
"express-session": "1.17.2",
"mocha": "8.4.0",
"mocha": "9.0.2",
"passport": "0.4.1"
}
}
2 changes: 1 addition & 1 deletion templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<div class="wrap">
<h1>Login with lnurl-auth</h1>
<p>Scan the QR code with an app that supports lnurl-auth</p>
<a id="qrcode" href="lightning:{{encoded}}"><img src="{{dataUri}}"></a>
<a id="qrcode" href="{{href}}"><img src="{{dataUri}}"></a>
<div id="buttons">
{{#if cancelUrl}}
<a href="{{cancelUrl}}" class="button">Cancel</a>
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ module.exports = {
},

extractEncodedFromLoginPageHtml: function(html) {
const match = html.match(new RegExp('<a id="qrcode" href="lightning:([a-z0-9]+)">'));
return match && match[1] || null;
const match = html.match(new RegExp('<a id="qrcode" href="(lightning:|LIGHTNING:)?([a-zA-Z0-9]+)">'));
return match && match[2] || null;
},

extractSecretFromLoginPageHtml: function(html) {
Expand Down

0 comments on commit 6d185d8

Please sign in to comment.