Compare commits
2 Commits
4f1d771659
...
527e01b3e8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
527e01b3e8 | ||
|
|
86e403ab5f |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
nostr-login/
|
||||||
1
app.js
1
app.js
@@ -19,6 +19,7 @@ const CLIENT_SECRET = 'gitea-secret';
|
|||||||
|
|
||||||
// Nostr relays for fetching user metadata
|
// Nostr relays for fetching user metadata
|
||||||
const NOSTR_RELAYS = [
|
const NOSTR_RELAYS = [
|
||||||
|
'wss://relay.laantungir.net',
|
||||||
'wss://relay.damus.io',
|
'wss://relay.damus.io',
|
||||||
'wss://nos.lol',
|
'wss://nos.lol',
|
||||||
'wss://relay.nostr.band',
|
'wss://relay.nostr.band',
|
||||||
|
|||||||
1
nostr-login
Submodule
1
nostr-login
Submodule
Submodule nostr-login added at a679422d07
@@ -2,9 +2,6 @@
|
|||||||
"folders": [
|
"folders": [
|
||||||
{
|
{
|
||||||
"path": "."
|
"path": "."
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "../nostr-login"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
|
|||||||
4
upload.sh
Executable file
4
upload.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
rsync -avz ./app.js ubuntu@laantungir.net:~/nostr-oidc-bridge/app.js
|
||||||
|
rsync -avz ./views/login.ejs ubuntu@laantungir.net:~/nostr-oidc-bridge/views/
|
||||||
102
views/login.ejs
102
views/login.ejs
@@ -3,7 +3,13 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Nostr Login - OIDC Bridge v2.1</title>
|
<title>OIDC Bridge v2.4</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: black
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="login-container">
|
<div id="login-container">
|
||||||
@@ -19,22 +25,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
<!-- Version header -->
|
|
||||||
<div style="text-align: center; margin: 10px 0; padding: 8px; background: #e3f2fd; border: 1px solid #2196f3; border-radius: 4px; font-weight: bold; color: #1976d2;">
|
|
||||||
🚀 Nostr OIDC Bridge v2.1 - Form Auth + event_json fix
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Target div for nostr-login widget -->
|
<!-- Target div for nostr-login widget -->
|
||||||
<div id="nostr-login"></div>
|
<div id="nostr-login"></div>
|
||||||
|
|
||||||
<!-- Version info -->
|
<!-- Version info -->
|
||||||
<div style="position: fixed; bottom: 10px; right: 10px; font-size: 14px; color: #333; background: rgba(255,255,255,0.95); padding: 6px 12px; border-radius: 6px; border: 1px solid #ddd; font-weight: bold;">
|
|
||||||
v2.1 - Form Auth + event_json fix
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Load your hosted nostr-login with full permissions -->
|
<!-- Load your hosted nostr-login with custom laan theme configuration -->
|
||||||
<script src='https://laantungir.net/nostr-login/unpkg.js'></script>
|
<script src='https://laantungir.net/nostr-login/unpkg.js'
|
||||||
|
data-theme='laan'
|
||||||
|
data-start-screen='welcome'
|
||||||
|
data-no-banner='true'></script>
|
||||||
|
|
||||||
<!-- Import nostr-tools for proper npub encoding -->
|
<!-- Import nostr-tools for proper npub encoding -->
|
||||||
<script type="module">
|
<script type="module">
|
||||||
@@ -46,35 +49,16 @@
|
|||||||
<script>
|
<script>
|
||||||
let isProcessing = false;
|
let isProcessing = false;
|
||||||
|
|
||||||
// Initialize nostr-login widget
|
// Widget initialization is now handled automatically by the script data attributes
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
console.log('Nostr-login widget will initialize automatically with laan theme and immediate login display');
|
||||||
console.log('Initializing nostr-login widget...');
|
|
||||||
|
// Auto-launch the login modal immediately when page loads
|
||||||
// Create nostr-login options
|
window.addEventListener('load', () => {
|
||||||
const nostrLoginOptions = {
|
// Small delay to ensure nostr-login widget is fully initialized
|
||||||
bunkers: 'all',
|
setTimeout(() => {
|
||||||
methods: 'all',
|
console.log('Auto-launching nostr-login modal...');
|
||||||
noBanner: true,
|
document.dispatchEvent(new CustomEvent('nlLaunch', { detail: 'login' }));
|
||||||
startScreen: 'welcome-login',
|
}, 100);
|
||||||
theme: 'default'
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log('nostr-login options', nostrLoginOptions);
|
|
||||||
|
|
||||||
// Initialize the widget
|
|
||||||
if (window.NostrLogin) {
|
|
||||||
window.NostrLogin.init(nostrLoginOptions);
|
|
||||||
} else {
|
|
||||||
console.error('NostrLogin not found on window object');
|
|
||||||
|
|
||||||
// Fallback: try to initialize after a delay
|
|
||||||
setTimeout(() => {
|
|
||||||
if (window.NostrLogin) {
|
|
||||||
console.log('Retrying NostrLogin initialization...');
|
|
||||||
window.NostrLogin.init(nostrLoginOptions);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for nostr-login authentication events
|
// Listen for nostr-login authentication events
|
||||||
@@ -144,7 +128,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Submit to backend
|
// Submit to backend
|
||||||
await submitAuthToBackend(sessionId, pubkey, signedEvent);
|
await submitAuthToBackend(sessionId, pubkey, signedEvent, npub);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Authentication error:', error);
|
console.error('Authentication error:', error);
|
||||||
@@ -155,9 +139,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitAuthToBackend(sessionId, pubkey, signedEvent) {
|
async function submitAuthToBackend(sessionId, pubkey, signedEvent, npub) {
|
||||||
try {
|
try {
|
||||||
console.log('Submitting auth to backend...');
|
console.log('✅ Submitting auth to backend...');
|
||||||
|
console.log('📋 Form data:', {
|
||||||
|
sessionId,
|
||||||
|
npub: npub ? `${npub.substring(0, 20)}... (length: ${npub.length})` : 'undefined',
|
||||||
|
pubkey: pubkey ? `${pubkey.substring(0, 20)}... (length: ${pubkey.length})` : 'undefined',
|
||||||
|
eventContent: signedEvent.content.substring(0, 20) + '...'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Validate inputs before submission
|
||||||
|
if (!npub) {
|
||||||
|
throw new Error('npub is required but not provided');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!signedEvent || !signedEvent.sig) {
|
||||||
|
throw new Error('Valid signed event is required');
|
||||||
|
}
|
||||||
|
|
||||||
// Create a form and submit it traditionally to allow proper redirects
|
// Create a form and submit it traditionally to allow proper redirects
|
||||||
// This avoids CORS issues when redirecting to external domains like Gitea
|
// This avoids CORS issues when redirecting to external domains like Gitea
|
||||||
@@ -169,7 +168,7 @@
|
|||||||
const npubField = document.createElement('input');
|
const npubField = document.createElement('input');
|
||||||
npubField.type = 'hidden';
|
npubField.type = 'hidden';
|
||||||
npubField.name = 'npub';
|
npubField.name = 'npub';
|
||||||
npubField.value = npub; // Use the properly encoded npub
|
npubField.value = npub;
|
||||||
form.appendChild(npubField);
|
form.appendChild(npubField);
|
||||||
|
|
||||||
const eventField = document.createElement('input');
|
const eventField = document.createElement('input');
|
||||||
@@ -180,11 +179,22 @@
|
|||||||
|
|
||||||
// Add form to document and submit
|
// Add form to document and submit
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
console.log('Submitting form for authentication...');
|
console.log('🚀 Submitting form for authentication...');
|
||||||
|
|
||||||
|
// Add timeout to prevent infinite waiting
|
||||||
|
setTimeout(() => {
|
||||||
|
if (isProcessing) {
|
||||||
|
console.warn('⚠️ Form submission timeout - authentication may have failed');
|
||||||
|
showError('Authentication timed out. Please try again.');
|
||||||
|
isProcessing = false;
|
||||||
|
document.body.removeChild(form);
|
||||||
|
}
|
||||||
|
}, 30000); // 30 second timeout
|
||||||
|
|
||||||
form.submit();
|
form.submit();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Backend submission error:', error);
|
console.error('❌ Backend submission error:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user