Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebec73d7aa | ||
|
|
878a13c229 | ||
|
|
cae4aedeae | ||
|
|
94a80e6a8e | ||
|
|
cea68cad17 | ||
|
|
717573aa9d | ||
|
|
8e8170a8dc | ||
|
|
4327c510e9 | ||
|
|
f40f5ca905 | ||
|
|
f11c9bdeee | ||
|
|
8c1eb882a3 |
@@ -0,0 +1,55 @@
|
|||||||
|
name: Publish PeerTube Plugin to npm
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
release:
|
||||||
|
types:
|
||||||
|
- published
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '24'
|
||||||
|
|
||||||
|
- name: Syntax check main plugin entrypoint
|
||||||
|
run: node --check main.js
|
||||||
|
|
||||||
|
- name: Check npm version and publish if new
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
NPM_TOKEN_SECRET: ${{ secrets.NPM_TOKEN }}
|
||||||
|
run: |
|
||||||
|
PKG_NAME=$(node -p "require('./package.json').name")
|
||||||
|
PKG_VER=$(node -p "require('./package.json').version")
|
||||||
|
PUBLISHED=$(npm view "${PKG_NAME}@${PKG_VER}" version 2>/dev/null || true)
|
||||||
|
|
||||||
|
if [ "$PUBLISHED" = "$PKG_VER" ]; then
|
||||||
|
echo "Version ${PKG_VER} of ${PKG_NAME} is already on npm. Skipping publish."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$NPM_TOKEN_SECRET" ]; then
|
||||||
|
printf "//registry.npmjs.org/:_authToken=%s\n" "$NPM_TOKEN_SECRET" > ~/.npmrc
|
||||||
|
npm publish --access public
|
||||||
|
else
|
||||||
|
npm install -g npm@latest
|
||||||
|
npm -v
|
||||||
|
npm publish --provenance --access public
|
||||||
|
fi
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
docs/
|
||||||
|
*.log
|
||||||
|
.git
|
||||||
|
.github
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||
[](https://joinpeertube.org)
|
[](https://joinpeertube.org)
|
||||||
[](https://auth.yakhub.com.tr)
|
[](https://developer-console.yakhub.com.tr)
|
||||||
|
|
||||||
**English** | [Türkçe](#türkçe)
|
**English** | [Türkçe](#türkçe)
|
||||||
|
|
||||||
@@ -43,7 +43,8 @@ In your PeerTube admin panel (**Administration > Plugins / Themes > Settings** f
|
|||||||
|
|
||||||
- **Client ID:** Your registered YakNet OAuth2 Application Client ID.
|
- **Client ID:** Your registered YakNet OAuth2 Application Client ID.
|
||||||
- **Client Secret:** Your YakNet OAuth2 Client Secret.
|
- **Client Secret:** Your YakNet OAuth2 Client Secret.
|
||||||
- **Auth Base URL:** Default is `https://auth.yakhub.com.tr`.
|
- **Auth Base URL:** Default is `https://developer-console.yakhub.com.tr`.
|
||||||
|
- **Auto-Redirect on Login:** Automatically bypass the standard login form and redirect users directly to YakNet SSO (also synchronizes `redirect_on_single_external_auth` in PeerTube configuration).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,309 @@
|
|||||||
function registerClient({ registerHook, peertubeHelpers }) {
|
async function register({ registerHook, peertubeHelpers }) {
|
||||||
// YakNet client script
|
try {
|
||||||
|
var currentStatus = {
|
||||||
|
autoRedirectLogin: true,
|
||||||
|
showAccountLink: true,
|
||||||
|
showLoginButton: true,
|
||||||
|
showErrorHints: true,
|
||||||
|
authBaseUrl: 'https://developer-console.yakhub.com.tr'
|
||||||
|
};
|
||||||
|
|
||||||
|
function hasPendingReturnUrl() {
|
||||||
|
try {
|
||||||
|
return Boolean(
|
||||||
|
localStorage.getItem('yaktube_return_url') ||
|
||||||
|
sessionStorage.getItem('yaktube_return_url') ||
|
||||||
|
sessionStorage.getItem('redirect-url-after-login')
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function announceSsoStatus(message) {
|
||||||
|
try {
|
||||||
|
var region = document.getElementById('yaknet-sso-live-region');
|
||||||
|
if (!region && document.body) {
|
||||||
|
region = document.createElement('div');
|
||||||
|
region.id = 'yaknet-sso-live-region';
|
||||||
|
region.setAttribute('role', 'status');
|
||||||
|
region.setAttribute('aria-live', 'polite');
|
||||||
|
region.setAttribute('aria-atomic', 'true');
|
||||||
|
region.style.cssText =
|
||||||
|
'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
|
||||||
|
document.body.appendChild(region);
|
||||||
|
}
|
||||||
|
if (region) {
|
||||||
|
region.textContent = '';
|
||||||
|
setTimeout(function () {
|
||||||
|
region.textContent = message;
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
var postLoginCheckTimer = null;
|
||||||
|
|
||||||
|
function stopPostLoginPolling() {
|
||||||
|
if (postLoginCheckTimer) {
|
||||||
|
clearInterval(postLoginCheckTimer);
|
||||||
|
postLoginCheckTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveReturnUrlBeforeLogin() {
|
||||||
|
try {
|
||||||
|
var currentPath = window.location.pathname + window.location.search + window.location.hash;
|
||||||
|
if (currentPath && !window.location.pathname.includes('/login')) {
|
||||||
|
localStorage.setItem('yaktube_return_url', currentPath);
|
||||||
|
localStorage.setItem('yaktube_return_url_time', String(Date.now()));
|
||||||
|
sessionStorage.setItem('yaktube_return_url', currentPath);
|
||||||
|
sessionStorage.setItem('redirect-url-after-login', currentPath);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkPendingPostLoginRedirect() {
|
||||||
|
try {
|
||||||
|
if (!hasPendingReturnUrl()) {
|
||||||
|
stopPostLoginPolling();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (window.location.pathname.includes('/login')) return;
|
||||||
|
var token = localStorage.getItem('access_token');
|
||||||
|
if (!token) return;
|
||||||
|
var savedUrl =
|
||||||
|
localStorage.getItem('yaktube_return_url') ||
|
||||||
|
sessionStorage.getItem('yaktube_return_url') ||
|
||||||
|
sessionStorage.getItem('redirect-url-after-login');
|
||||||
|
if (!savedUrl) {
|
||||||
|
stopPostLoginPolling();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var savedTime = parseInt(localStorage.getItem('yaktube_return_url_time') || '0', 10);
|
||||||
|
localStorage.removeItem('yaktube_return_url');
|
||||||
|
localStorage.removeItem('yaktube_return_url_time');
|
||||||
|
sessionStorage.removeItem('yaktube_return_url');
|
||||||
|
sessionStorage.removeItem('redirect-url-after-login');
|
||||||
|
stopPostLoginPolling();
|
||||||
|
if (savedTime && Date.now() - savedTime > 15 * 60 * 1000) return;
|
||||||
|
announceSsoStatus('YakNet hesabınızla oturum açıldı.');
|
||||||
|
var currentFull = window.location.pathname + window.location.search + window.location.hash;
|
||||||
|
if (
|
||||||
|
typeof savedUrl === 'string' &&
|
||||||
|
savedUrl.startsWith('/') &&
|
||||||
|
!savedUrl.startsWith('//') &&
|
||||||
|
!savedUrl.startsWith('/login') &&
|
||||||
|
savedUrl !== currentFull
|
||||||
|
) {
|
||||||
|
window.location.replace(savedUrl);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkPendingPostLoginRedirect();
|
||||||
|
window.addEventListener('popstate', checkPendingPostLoginRedirect);
|
||||||
|
if (hasPendingReturnUrl()) {
|
||||||
|
postLoginCheckTimer = setInterval(checkPendingPostLoginRedirect, 800);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Left Menu Hook for "YakNet Hesabım" Link (Configurable from Settings)
|
||||||
|
if (typeof registerHook === 'function') {
|
||||||
|
try {
|
||||||
|
registerHook({
|
||||||
|
target: 'filter:left-menu.links.create.result',
|
||||||
|
handler: function (sections) {
|
||||||
|
if (!currentStatus || currentStatus.showAccountLink === false) return sections;
|
||||||
|
var token = localStorage.getItem('access_token');
|
||||||
|
if (!token || !Array.isArray(sections)) return sections;
|
||||||
|
|
||||||
|
var targetSec =
|
||||||
|
sections.find(function (s) {
|
||||||
|
return s && (s.key === 'my-video-space' || s.key === 'in-my-library' || s.key === 'library');
|
||||||
|
}) || sections[0];
|
||||||
|
|
||||||
|
if (targetSec && Array.isArray(targetSec.links)) {
|
||||||
|
var already = targetSec.links.some(function (l) {
|
||||||
|
return l && (l.key === 'yaknet-account' || l.label === 'YakNet Hesabım');
|
||||||
|
});
|
||||||
|
if (!already) {
|
||||||
|
targetSec.links.push({
|
||||||
|
key: 'yaknet-account',
|
||||||
|
label: 'YakNet Hesabım',
|
||||||
|
url: (currentStatus.authBaseUrl || 'https://developer-console.yakhub.com.tr') + '/profile',
|
||||||
|
external: true,
|
||||||
|
svgIcon:
|
||||||
|
'<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sections;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (hookErr) {
|
||||||
|
console.warn('[YakNet SSO] Left menu hook register error:', hookErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dynamic UI Injector (Login Page Button, Error Hints & User Dropdown Link)
|
||||||
|
function injectYakNetUI() {
|
||||||
|
try {
|
||||||
|
var isLoginPage = window.location.pathname.includes('/login');
|
||||||
|
|
||||||
|
// 1. Error Hints on Login Page
|
||||||
|
if (
|
||||||
|
isLoginPage &&
|
||||||
|
currentStatus.showErrorHints !== false &&
|
||||||
|
window.location.search.includes('externalAuthError')
|
||||||
|
) {
|
||||||
|
if (!document.getElementById('yaknet-auth-error-box')) {
|
||||||
|
var targetContainer = document.querySelector('my-login, .login-container, .login-form, form');
|
||||||
|
if (targetContainer) {
|
||||||
|
var errBox = document.createElement('div');
|
||||||
|
errBox.id = 'yaknet-auth-error-box';
|
||||||
|
errBox.className = 'yaknet-auth-error-box';
|
||||||
|
errBox.setAttribute('role', 'alert');
|
||||||
|
errBox.innerHTML =
|
||||||
|
'<div class="yaknet-error-title">⚠️ YakNet ile Giriş Yapılamadı</div>' +
|
||||||
|
'<p class="yaknet-error-desc">' +
|
||||||
|
'YakNet oturum isteği tamamlanamadı. Hesabınızın e-posta doğrulamasını yapmamış olabilir veya giriş isteğini iptal etmiş olabilirsiniz.' +
|
||||||
|
'</p>' +
|
||||||
|
'<div class="yaknet-error-actions">' +
|
||||||
|
'<a href="/plugins/auth-yaknet/router/auth" class="yaknet-retry-btn">🔄 Tekrar Dene</a>' +
|
||||||
|
'<a href="' +
|
||||||
|
(currentStatus.authBaseUrl || 'https://developer-console.yakhub.com.tr') +
|
||||||
|
'" target="_blank" rel="noopener noreferrer" class="yaknet-help-btn">🌐 YakNet Hesabını Kontrol Et ↗</a>' +
|
||||||
|
'</div>';
|
||||||
|
targetContainer.prepend(errBox);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Prominent YakNet Button on Login Page
|
||||||
|
if (isLoginPage && currentStatus.showLoginButton !== false) {
|
||||||
|
if (!document.getElementById('yaknet-sso-login-btn')) {
|
||||||
|
var formElem = document.querySelector('form[name="loginForm"], .login-form, form');
|
||||||
|
if (formElem) {
|
||||||
|
var wrapper = document.createElement('div');
|
||||||
|
wrapper.id = 'yaknet-sso-login-btn';
|
||||||
|
wrapper.className = 'yaknet-sso-login-wrapper';
|
||||||
|
wrapper.innerHTML =
|
||||||
|
'<a href="/plugins/auth-yaknet/router/auth" class="yaknet-sso-btn" role="button">' +
|
||||||
|
'<svg aria-hidden="true" focusable="false" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>' +
|
||||||
|
'<span>YakNet ile Tek Tıkla Giriş Yap</span>' +
|
||||||
|
'</a>' +
|
||||||
|
'<div class="yaknet-divider"><span>veya yerel hesap şifresiyle</span></div>';
|
||||||
|
formElem.prepend(wrapper);
|
||||||
|
|
||||||
|
wrapper.querySelector('.yaknet-sso-btn').addEventListener('click', function () {
|
||||||
|
saveReturnUrlBeforeLogin();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. User Dropdown Menu Quick Link (when user is logged in)
|
||||||
|
if (currentStatus.showAccountLink !== false) {
|
||||||
|
var token = localStorage.getItem('access_token');
|
||||||
|
if (token) {
|
||||||
|
var userMenu = document.querySelector('.user-dropdown-menu, my-user-dropdown-content, .popover-content');
|
||||||
|
if (userMenu && !userMenu.querySelector('.yaknet-dropdown-item')) {
|
||||||
|
var accountLink = document.createElement('a');
|
||||||
|
accountLink.className = 'dropdown-item yaknet-dropdown-item yaknet-account-link';
|
||||||
|
accountLink.href = (currentStatus.authBaseUrl || 'https://developer-console.yakhub.com.tr') + '/profile';
|
||||||
|
accountLink.target = '_blank';
|
||||||
|
accountLink.rel = 'noopener noreferrer';
|
||||||
|
accountLink.innerHTML =
|
||||||
|
'<svg aria-hidden="true" focusable="false" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="vertical-align:-2px;"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg> ' +
|
||||||
|
'<span>YakNet Hesabımı Yönet ↗</span>';
|
||||||
|
userMenu.appendChild(accountLink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (uiErr) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
var uiInjectDebounce = null;
|
||||||
|
function scheduleInjectYakNetUI() {
|
||||||
|
if (uiInjectDebounce) return;
|
||||||
|
uiInjectDebounce = setTimeout(function () {
|
||||||
|
uiInjectDebounce = null;
|
||||||
|
injectYakNetUI();
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof MutationObserver === 'function' && document.body) {
|
||||||
|
var yaknetDomObserver = new MutationObserver(scheduleInjectYakNetUI);
|
||||||
|
yaknetDomObserver.observe(document.body, { childList: true, subtree: true });
|
||||||
|
}
|
||||||
|
setInterval(injectYakNetUI, 5000);
|
||||||
|
document.addEventListener('DOMContentLoaded', injectYakNetUI);
|
||||||
|
|
||||||
|
// Fetch Plugin Configuration from Backend
|
||||||
|
fetch('/plugins/auth-yaknet/router/status')
|
||||||
|
.then(function (r) {
|
||||||
|
return r.json();
|
||||||
|
})
|
||||||
|
.then(function (status) {
|
||||||
|
if (status) {
|
||||||
|
currentStatus = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
injectYakNetUI();
|
||||||
|
|
||||||
|
if (!status || status.autoRedirectLogin === false) {
|
||||||
|
return; // Auto redirect is disabled by administrator
|
||||||
|
}
|
||||||
|
|
||||||
|
var isLoginUrl = window.location.pathname.includes('/login');
|
||||||
|
var isLocal = window.location.search.includes('local=true');
|
||||||
|
var isError = window.location.search.includes('externalAuthError');
|
||||||
|
var isExternalToken = window.location.search.includes('externalAuthToken');
|
||||||
|
|
||||||
|
// CRITICAL: Never intercept /login when PeerTube is completing the externalAuthToken handshake!
|
||||||
|
if (isLoginUrl && !isLocal && !isError && !isExternalToken) {
|
||||||
|
window.location.replace('/plugins/auth-yaknet/router/auth');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept clicks on login links/buttons
|
||||||
|
document.addEventListener(
|
||||||
|
'click',
|
||||||
|
function (e) {
|
||||||
|
var el = e.target;
|
||||||
|
if (el && el.closest) {
|
||||||
|
var isLoginBtn = el.closest(
|
||||||
|
'my-login-link, .login-button, a[href*="/login"]:not(#yaktube-show-admin-login), a[aria-label*="Giriş"], a[title*="Giriş"], a[title*="login"], a[aria-label*="login"]'
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
isLoginBtn &&
|
||||||
|
!window.location.search.includes('local=true') &&
|
||||||
|
!window.location.search.includes('externalAuthToken')
|
||||||
|
) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
saveReturnUrlBeforeLogin();
|
||||||
|
window.location.href = '/plugins/auth-yaknet/router/auth';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(function () {});
|
||||||
|
|
||||||
|
// Alt+A shortcut for local admin login bypass
|
||||||
|
document.addEventListener('keydown', function (e) {
|
||||||
|
if (e.altKey && (e.key === 'a' || e.key === 'A')) {
|
||||||
|
if (!window.location.pathname.includes('/login')) {
|
||||||
|
window.location.href = '/login?local=true';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[YakNet SSO] Client init error:', err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { register, register as registerClient };
|
||||||
|
export default register;
|
||||||
@@ -4,11 +4,23 @@ const http = require('http');
|
|||||||
|
|
||||||
let clientId = '';
|
let clientId = '';
|
||||||
let clientSecret = '';
|
let clientSecret = '';
|
||||||
let authBaseUrl = 'https://auth.yakhub.com.tr';
|
let authBaseUrl = 'https://developer-console.yakhub.com.tr';
|
||||||
|
let customCallbackUrl = '';
|
||||||
|
|
||||||
function postRequest(urlStr, data) {
|
function normalizeAuthUrl(urlStr) {
|
||||||
|
if (typeof urlStr === 'string' && urlStr.includes('auth.yakhub.com.tr')) {
|
||||||
|
return urlStr.replace('auth.yakhub.com.tr', 'developer-console.yakhub.com.tr');
|
||||||
|
}
|
||||||
|
return urlStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function postRequest(urlStr, data, maxRedirects = 5) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const url = new URL(urlStr);
|
if (maxRedirects <= 0) {
|
||||||
|
return reject(new Error('Too many redirects while calling YakNet auth server'));
|
||||||
|
}
|
||||||
|
const safeUrlStr = normalizeAuthUrl(urlStr);
|
||||||
|
const url = new URL(safeUrlStr);
|
||||||
const postData = typeof data === 'string' ? data : new URLSearchParams(data).toString();
|
const postData = typeof data === 'string' ? data : new URLSearchParams(data).toString();
|
||||||
const lib = url.protocol === 'https:' ? https : http;
|
const lib = url.protocol === 'https:' ? https : http;
|
||||||
|
|
||||||
@@ -22,10 +34,15 @@ function postRequest(urlStr, data) {
|
|||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Length': Buffer.byteLength(postData),
|
'Content-Length': Buffer.byteLength(postData),
|
||||||
'User-Agent': 'YakTube-SSO/1.0'
|
'User-Agent': 'YakTube-SSO/1.1'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
res => {
|
res => {
|
||||||
|
if ([301, 302, 307, 308].includes(res.statusCode) && res.headers.location) {
|
||||||
|
const nextUrl = new URL(res.headers.location, safeUrlStr).toString();
|
||||||
|
return resolve(postRequest(nextUrl, data, maxRedirects - 1));
|
||||||
|
}
|
||||||
|
|
||||||
let body = '';
|
let body = '';
|
||||||
res.on('data', chunk => (body += chunk));
|
res.on('data', chunk => (body += chunk));
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
@@ -44,9 +61,13 @@ function postRequest(urlStr, data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRequest(urlStr, token) {
|
function getRequest(urlStr, token, maxRedirects = 5) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const url = new URL(urlStr);
|
if (maxRedirects <= 0) {
|
||||||
|
return reject(new Error('Too many redirects while calling YakNet auth server'));
|
||||||
|
}
|
||||||
|
const safeUrlStr = normalizeAuthUrl(urlStr);
|
||||||
|
const url = new URL(safeUrlStr);
|
||||||
const lib = url.protocol === 'https:' ? https : http;
|
const lib = url.protocol === 'https:' ? https : http;
|
||||||
|
|
||||||
const req = lib.request(
|
const req = lib.request(
|
||||||
@@ -58,10 +79,15 @@ function getRequest(urlStr, token) {
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: 'Bearer ' + token,
|
Authorization: 'Bearer ' + token,
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'User-Agent': 'YakTube-SSO/1.0'
|
'User-Agent': 'YakTube-SSO/1.1'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
res => {
|
res => {
|
||||||
|
if ([301, 302, 307, 308].includes(res.statusCode) && res.headers.location) {
|
||||||
|
const nextUrl = new URL(res.headers.location, safeUrlStr).toString();
|
||||||
|
return resolve(getRequest(nextUrl, token, maxRedirects - 1));
|
||||||
|
}
|
||||||
|
|
||||||
let body = '';
|
let body = '';
|
||||||
res.on('data', chunk => (body += chunk));
|
res.on('data', chunk => (body += chunk));
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
@@ -81,7 +107,13 @@ function getRequest(urlStr, token) {
|
|||||||
|
|
||||||
async function register({ registerExternalAuth, registerSetting, settingsManager, getRouter, peertubeHelpers }) {
|
async function register({ registerExternalAuth, registerSetting, settingsManager, getRouter, peertubeHelpers }) {
|
||||||
const logger = peertubeHelpers.logger;
|
const logger = peertubeHelpers.logger;
|
||||||
|
const webserverUrl = (peertubeHelpers.config.getWebserverUrl() || '').replace(/\/+$/, '');
|
||||||
|
const isOfficialYakTube = webserverUrl.includes('yaktube.yakhub.com.tr');
|
||||||
|
const defaultCallbackUrl = isOfficialYakTube
|
||||||
|
? `${webserverUrl}/plugins/peertube-plugin-auth-yaknet/router/auth-callback`
|
||||||
|
: `${webserverUrl}/plugins/auth-yaknet/router/auth-callback`;
|
||||||
|
|
||||||
|
// 1. Core OAuth2 Credentials
|
||||||
registerSetting({
|
registerSetting({
|
||||||
name: 'client-id',
|
name: 'client-id',
|
||||||
label: 'YakNet Client ID',
|
label: 'YakNet Client ID',
|
||||||
@@ -104,44 +136,278 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
|||||||
name: 'auth-base-url',
|
name: 'auth-base-url',
|
||||||
label: 'YakNet Auth URL',
|
label: 'YakNet Auth URL',
|
||||||
type: 'input',
|
type: 'input',
|
||||||
description: 'YakNet SSO Server URL (Default: https://auth.yakhub.com.tr)',
|
description: 'YakNet SSO Server URL (Default: https://developer-console.yakhub.com.tr)',
|
||||||
private: false,
|
private: false,
|
||||||
default: 'https://auth.yakhub.com.tr'
|
default: 'https://developer-console.yakhub.com.tr'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'callback-url',
|
||||||
|
label: 'OAuth Callback (Redirect) URL (Opsiyonel)',
|
||||||
|
type: 'input',
|
||||||
|
description: `Boş bırakılırsa otomatik olarak "${defaultCallbackUrl}" kullanılır. YakNet Geliştirici Konsolu'nda tanımladığınız Redirect URI adresini buraya yazabilirsiniz.`,
|
||||||
|
private: false,
|
||||||
|
default: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Navigation & Redirect Controls
|
||||||
|
registerSetting({
|
||||||
|
name: 'auto-redirect-login',
|
||||||
|
label: "Giriş Sayfasında Doğrudan YakNet SSO'ya Yönlendir",
|
||||||
|
type: 'input-checkbox',
|
||||||
|
description:
|
||||||
|
'Aktif olduğunda, kullanıcılar giriş butonuna veya /login sayfasına gittiğinde standart PeerTube şifre formu yerine doğrudan YakNet SSO sunucusuna yönlendirilir.',
|
||||||
|
private: false,
|
||||||
|
default: true
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'show-account-link',
|
||||||
|
label: 'Kullanıcı Menüsünde "YakNet Hesabım" Bağlantısı',
|
||||||
|
type: 'input-checkbox',
|
||||||
|
description:
|
||||||
|
'Aktif olduğunda, oturum açmış kullanıcıların sol menüsünde ve profil açılır menüsünde merkezi YakNet profil yönetim bağlantısı görüntülenir.',
|
||||||
|
private: false,
|
||||||
|
default: true
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'show-login-button',
|
||||||
|
label: 'Giriş Sayfasında Belirgin YakNet Butonu Göster',
|
||||||
|
type: 'input-checkbox',
|
||||||
|
description:
|
||||||
|
'Aktif olduğunda, doğrudan yönlendirme kapalıyken veya yerel admin girişinde (/login?local=true) giriş formunun üzerinde şık bir "YakNet ile Tek Tıkla Giriş Yap" butonu görüntülenir.',
|
||||||
|
private: false,
|
||||||
|
default: true
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'show-error-hints',
|
||||||
|
label: 'Giriş Hatalarında Yardımcı Açıklama Göster',
|
||||||
|
type: 'input-checkbox',
|
||||||
|
description:
|
||||||
|
'Giriş başarısız olduğunda (örneğin kullanıcının e-posta onayı eksikse veya iptal edildiyse) kullanıcıya bilgilendirici ve yönlendirici bir uyarı kutusu gösterir.',
|
||||||
|
private: false,
|
||||||
|
default: true
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'sync-display-name',
|
||||||
|
label: 'Görünen Adı (Display Name) Otomatik Eşitle',
|
||||||
|
type: 'input-checkbox',
|
||||||
|
description:
|
||||||
|
"Kullanıcının YakNet profilindeki ad ve soyadını her girişte PeerTube'daki görünen adıyla senkronize eder.",
|
||||||
|
private: false,
|
||||||
|
default: true
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'default-video-quota',
|
||||||
|
label: 'Yeni Üyeler İçin Toplam Video Kotası (MB)',
|
||||||
|
type: 'input',
|
||||||
|
description:
|
||||||
|
'YakNet ile kaydolan üyelere atanacak toplam video depolama alanı kotası (Megabayt). 0 bırakılırsa sunucunun genel varsayılan kotası kullanılır; sınırsız için -1 yazın.',
|
||||||
|
private: false,
|
||||||
|
default: '0'
|
||||||
|
});
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'default-daily-video-quota',
|
||||||
|
label: 'Yeni Üyeler İçin Günlük Video Kotası (MB)',
|
||||||
|
type: 'input',
|
||||||
|
description:
|
||||||
|
'YakNet ile kaydolan üyelere atanacak günlük video yükleme kotası (Megabayt). 0 bırakılırsa sunucunun genel varsayılan kotası kullanılır; sınırsız için -1 yazın.',
|
||||||
|
private: false,
|
||||||
|
default: '0'
|
||||||
|
});
|
||||||
|
|
||||||
|
let autoRedirectLogin = true;
|
||||||
|
let showAccountLink = true;
|
||||||
|
let showLoginButton = true;
|
||||||
|
let showErrorHints = true;
|
||||||
|
let syncDisplayName = true;
|
||||||
|
let defaultVideoQuota = 0;
|
||||||
|
let defaultDailyVideoQuota = 0;
|
||||||
|
|
||||||
|
function syncConfigFiles(enable) {
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Update in-memory PeerTube ServerConfig if accessible
|
||||||
|
try {
|
||||||
|
const srvCfg = peertubeHelpers.config.getServerConfig();
|
||||||
|
if (srvCfg && srvCfg.client && srvCfg.client.menu && srvCfg.client.menu.login) {
|
||||||
|
srvCfg.client.menu.login.redirectOnSingleExternalAuth = enable;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
// 1. Update local-production.json if present
|
||||||
|
const jsonCandidates = [
|
||||||
|
path.resolve(process.cwd(), 'config', 'local-production.json'),
|
||||||
|
path.resolve(__dirname, '..', '..', 'config', 'local-production.json'),
|
||||||
|
path.resolve(__dirname, '..', '..', '..', 'config', 'local-production.json'),
|
||||||
|
'c:/laragon/www/yaktube.yakhub.com.tr/config/local-production.json'
|
||||||
|
];
|
||||||
|
for (const jPath of jsonCandidates) {
|
||||||
|
if (fs.existsSync(jPath)) {
|
||||||
|
try {
|
||||||
|
const cfg = JSON.parse(fs.readFileSync(jPath, 'utf8'));
|
||||||
|
if (!cfg.menu) cfg.menu = {};
|
||||||
|
if (!cfg.menu.login) cfg.menu.login = {};
|
||||||
|
if (cfg.menu.login.redirect_on_single_external_auth !== enable) {
|
||||||
|
cfg.menu.login.redirect_on_single_external_auth = enable;
|
||||||
|
fs.writeFileSync(jPath, JSON.stringify(cfg, null, 2), 'utf8');
|
||||||
|
logger.info(`[YakNet SSO] Synced local-production.json redirect_on_single_external_auth = ${enable}`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn('[YakNet SSO] Error updating local-production.json:', e.message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Update production.yaml if present
|
||||||
|
const yamlCandidates = [
|
||||||
|
path.resolve(process.cwd(), 'config', 'production.yaml'),
|
||||||
|
path.resolve(__dirname, '..', '..', 'config', 'production.yaml'),
|
||||||
|
path.resolve(__dirname, '..', '..', '..', 'config', 'production.yaml'),
|
||||||
|
'c:/laragon/www/yaktube.yakhub.com.tr/config/production.yaml'
|
||||||
|
];
|
||||||
|
for (const yPath of yamlCandidates) {
|
||||||
|
if (fs.existsSync(yPath)) {
|
||||||
|
try {
|
||||||
|
let yContent = fs.readFileSync(yPath, 'utf8');
|
||||||
|
const pattern = /(redirect_on_single_external_auth:\s*)(true|false)/;
|
||||||
|
if (pattern.test(yContent)) {
|
||||||
|
const updated = yContent.replace(pattern, `$1${enable}`);
|
||||||
|
if (updated !== yContent) {
|
||||||
|
fs.writeFileSync(yPath, updated, 'utf8');
|
||||||
|
logger.info(`[YakNet SSO] Synced production.yaml redirect_on_single_external_auth = ${enable}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn('[YakNet SSO] Error updating production.yaml:', e.message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadSettings() {
|
async function loadSettings() {
|
||||||
const cid = await settingsManager.getSetting('client-id');
|
const cid = await settingsManager.getSetting('client-id');
|
||||||
const csec = await settingsManager.getSetting('client-secret');
|
const csec = await settingsManager.getSetting('client-secret');
|
||||||
const burl = await settingsManager.getSetting('auth-base-url');
|
const burl = await settingsManager.getSetting('auth-base-url');
|
||||||
if (cid) clientId = cid;
|
const cburl = await settingsManager.getSetting('callback-url');
|
||||||
if (csec) clientSecret = csec;
|
const autoRedir = await settingsManager.getSetting('auto-redirect-login');
|
||||||
if (burl) authBaseUrl = burl.replace(/\/+$/, '');
|
const sAccountLink = await settingsManager.getSetting('show-account-link');
|
||||||
|
const sLoginBtn = await settingsManager.getSetting('show-login-button');
|
||||||
|
const sErrorHints = await settingsManager.getSetting('show-error-hints');
|
||||||
|
const sSyncDisplay = await settingsManager.getSetting('sync-display-name');
|
||||||
|
const sQuota = await settingsManager.getSetting('default-video-quota');
|
||||||
|
const sDailyQuota = await settingsManager.getSetting('default-daily-video-quota');
|
||||||
|
|
||||||
|
if (cid) clientId = String(cid).trim();
|
||||||
|
if (csec) clientSecret = String(csec).trim();
|
||||||
|
if (burl && String(burl).trim()) {
|
||||||
|
authBaseUrl = normalizeAuthUrl(String(burl).trim().replace(/\/+$/, ''));
|
||||||
|
}
|
||||||
|
customCallbackUrl = cburl ? String(cburl).trim() : '';
|
||||||
|
|
||||||
|
if (autoRedir !== undefined && autoRedir !== null) {
|
||||||
|
autoRedirectLogin = autoRedir === true || autoRedir === 'true';
|
||||||
|
} else {
|
||||||
|
autoRedirectLogin = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sAccountLink !== undefined && sAccountLink !== null) {
|
||||||
|
showAccountLink = sAccountLink === true || sAccountLink === 'true';
|
||||||
|
} else {
|
||||||
|
showAccountLink = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sLoginBtn !== undefined && sLoginBtn !== null) {
|
||||||
|
showLoginButton = sLoginBtn === true || sLoginBtn === 'true';
|
||||||
|
} else {
|
||||||
|
showLoginButton = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sErrorHints !== undefined && sErrorHints !== null) {
|
||||||
|
showErrorHints = sErrorHints === true || sErrorHints === 'true';
|
||||||
|
} else {
|
||||||
|
showErrorHints = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sSyncDisplay !== undefined && sSyncDisplay !== null) {
|
||||||
|
syncDisplayName = sSyncDisplay === true || sSyncDisplay === 'true';
|
||||||
|
} else {
|
||||||
|
syncDisplayName = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sQuota !== undefined && sQuota !== null && String(sQuota).trim() !== '') {
|
||||||
|
defaultVideoQuota = parseInt(String(sQuota).trim(), 10) || 0;
|
||||||
|
} else {
|
||||||
|
defaultVideoQuota = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sDailyQuota !== undefined && sDailyQuota !== null && String(sDailyQuota).trim() !== '') {
|
||||||
|
defaultDailyVideoQuota = parseInt(String(sDailyQuota).trim(), 10) || 0;
|
||||||
|
} else {
|
||||||
|
defaultDailyVideoQuota = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
syncConfigFiles(autoRedirectLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
await loadSettings();
|
await loadSettings();
|
||||||
settingsManager.onSettingsChange(loadSettings);
|
settingsManager.onSettingsChange(loadSettings);
|
||||||
|
|
||||||
const webserverUrl = peertubeHelpers.config.getWebserverUrl();
|
function getActiveCallbackUrl() {
|
||||||
const callbackUrl = `${webserverUrl}/plugins/peertube-plugin-auth-yaknet/router/auth-callback`;
|
return customCallbackUrl || defaultCallbackUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function dbQuery(sql, bindParams = []) {
|
||||||
|
if (!peertubeHelpers || !peertubeHelpers.database || typeof peertubeHelpers.database.query !== 'function') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const res = await peertubeHelpers.database.query(sql, { bind: bindParams });
|
||||||
|
if (Array.isArray(res) && Array.isArray(res[0])) return res[0];
|
||||||
|
return Array.isArray(res) ? res : [];
|
||||||
|
}
|
||||||
|
|
||||||
const externalAuth = registerExternalAuth({
|
const externalAuth = registerExternalAuth({
|
||||||
authName: 'yaknet',
|
authName: 'yaknet',
|
||||||
authDisplayName: () => 'YakNet ile Giriş Yap',
|
authDisplayName: () => 'YakNet ile Giriş Yap',
|
||||||
onAuthRequest: (req, res) => {
|
onAuthRequest: (req, res) => {
|
||||||
const state = crypto.randomBytes(16).toString('hex');
|
const state = crypto.randomBytes(16).toString('hex');
|
||||||
const authUrl = `${authBaseUrl}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(callbackUrl)}&response_type=code&scope=&state=${state}`;
|
const cbUrl = getActiveCallbackUrl();
|
||||||
|
const authUrl = `${normalizeAuthUrl(authBaseUrl)}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(cbUrl)}&response_type=code&scope=&state=${state}`;
|
||||||
return res.redirect(authUrl);
|
return res.redirect(authUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const router = getRouter();
|
const router = getRouter();
|
||||||
|
|
||||||
|
router.get('/status', (req, res) => {
|
||||||
|
return res.json({
|
||||||
|
autoRedirectLogin: autoRedirectLogin !== false,
|
||||||
|
showAccountLink: showAccountLink !== false,
|
||||||
|
showLoginButton: showLoginButton !== false,
|
||||||
|
showErrorHints: showErrorHints !== false,
|
||||||
|
syncDisplayName: syncDisplayName !== false,
|
||||||
|
authBaseUrl: normalizeAuthUrl(authBaseUrl),
|
||||||
|
callbackUrl: getActiveCallbackUrl()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/auth', (req, res) => {
|
router.get('/auth', (req, res) => {
|
||||||
const state = crypto.randomBytes(16).toString('hex');
|
const state = crypto.randomBytes(16).toString('hex');
|
||||||
const authUrl = `${authBaseUrl}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(callbackUrl)}&response_type=code&scope=&state=${state}`;
|
const cbUrl = getActiveCallbackUrl();
|
||||||
|
const authUrl = `${normalizeAuthUrl(authBaseUrl)}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(cbUrl)}&response_type=code&scope=&state=${state}`;
|
||||||
return res.redirect(authUrl);
|
return res.redirect(authUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/auth-callback', async (req, res) => {
|
async function handleOAuthCallback(req, res) {
|
||||||
|
await loadSettings();
|
||||||
const code = req.query.code;
|
const code = req.query.code;
|
||||||
const error = req.query.error;
|
const error = req.query.error;
|
||||||
|
|
||||||
@@ -155,23 +421,25 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tokenRes = await postRequest(`${authBaseUrl}/oauth/token`, {
|
const targetAuthUrl = normalizeAuthUrl(authBaseUrl);
|
||||||
|
const cbUrl = getActiveCallbackUrl();
|
||||||
|
const tokenRes = await postRequest(`${targetAuthUrl}/oauth/token`, {
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
client_id: clientId,
|
client_id: clientId,
|
||||||
client_secret: clientSecret,
|
client_secret: clientSecret,
|
||||||
redirect_uri: callbackUrl,
|
redirect_uri: cbUrl,
|
||||||
code: code
|
code: code
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!tokenRes.data || !tokenRes.data.access_token) {
|
if (!tokenRes.data || !tokenRes.data.access_token) {
|
||||||
logger.error('Failed to get access token from YakNet:', tokenRes);
|
logger.error('Failed to get access token from YakNet: ' + JSON.stringify(tokenRes));
|
||||||
return res.redirect('/login?externalAuthError=true');
|
return res.redirect('/login?externalAuthError=true');
|
||||||
}
|
}
|
||||||
|
|
||||||
const accessToken = tokenRes.data.access_token;
|
const accessToken = tokenRes.data.access_token;
|
||||||
const userRes = await getRequest(`${authBaseUrl}/api/user`, accessToken);
|
const userRes = await getRequest(`${targetAuthUrl}/api/user`, accessToken);
|
||||||
if (!userRes.data || !userRes.data.email) {
|
if (!userRes.data || !userRes.data.email) {
|
||||||
logger.error('Failed to get user profile from YakNet:', userRes);
|
logger.error('Failed to get user profile from YakNet: ' + JSON.stringify(userRes));
|
||||||
return res.redirect('/login?externalAuthError=true');
|
return res.redirect('/login?externalAuthError=true');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,35 +465,92 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
|||||||
? 0
|
? 0
|
||||||
: 2;
|
: 2;
|
||||||
|
|
||||||
|
// Pre-sync with PeerTube DB so existing accounts or username collisions never fail without bridge.js
|
||||||
|
try {
|
||||||
|
const existingByEmail = await dbQuery(
|
||||||
|
`SELECT id, username FROM "user" WHERE LOWER(email) = LOWER($1) LIMIT 1`,
|
||||||
|
[email]
|
||||||
|
);
|
||||||
|
if (existingByEmail.length > 0) {
|
||||||
|
username = existingByEmail[0].username;
|
||||||
|
await dbQuery(
|
||||||
|
`UPDATE "user" SET "pluginAuth" = 'peertube-plugin-auth-yaknet', "emailVerified" = true WHERE id = $1`,
|
||||||
|
[existingByEmail[0].id]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const existingByUsername = await dbQuery(`SELECT id FROM "user" WHERE LOWER(username) = LOWER($1) LIMIT 1`, [
|
||||||
|
username
|
||||||
|
]);
|
||||||
|
if (existingByUsername.length > 0) {
|
||||||
|
username = (username.substring(0, 42) + '_' + crypto.randomBytes(2).toString('hex')).toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (dbErr) {
|
||||||
|
logger.warn('[YakNet SSO] Pre-sync DB warning: ' + dbErr.message);
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(`YakNet Authenticated user: ${username} (${email})`);
|
logger.info(`YakNet Authenticated user: ${username} (${email})`);
|
||||||
|
|
||||||
externalAuth.userAuthenticated({
|
const authPayload = {
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
displayName,
|
displayName,
|
||||||
role
|
role
|
||||||
});
|
};
|
||||||
|
|
||||||
if (peertubeHelpers && peertubeHelpers.database && peertubeHelpers.database.query) {
|
if (defaultVideoQuota > 0) {
|
||||||
setTimeout(async () => {
|
authPayload.videoQuota = defaultVideoQuota * 1024 * 1024;
|
||||||
try {
|
} else if (defaultVideoQuota === -1) {
|
||||||
await peertubeHelpers.database.query('UPDATE "user" SET "emailVerified" = true WHERE email = $1', {
|
authPayload.videoQuota = -1;
|
||||||
bind: [email]
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
logger.warn('Failed to auto-verify email in DB for ' + email, e);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defaultDailyVideoQuota > 0) {
|
||||||
|
authPayload.videoQuotaDaily = defaultDailyVideoQuota * 1024 * 1024;
|
||||||
|
} else if (defaultDailyVideoQuota === -1) {
|
||||||
|
authPayload.videoQuotaDaily = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
externalAuth.userAuthenticated(authPayload);
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
await dbQuery(
|
||||||
|
`UPDATE "user" SET "emailVerified" = true, "pluginAuth" = 'peertube-plugin-auth-yaknet' WHERE LOWER(email) = LOWER($1)`,
|
||||||
|
[email]
|
||||||
|
);
|
||||||
|
if (syncDisplayName && displayName) {
|
||||||
|
await dbQuery(
|
||||||
|
`UPDATE "account" SET "name" = $1 WHERE "userId" IN (SELECT id FROM "user" WHERE LOWER(email) = LOWER($2))`,
|
||||||
|
[displayName, email]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}, 1000);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Error processing YakNet auth callback:', err);
|
logger.error('Error processing YakNet auth callback:', err);
|
||||||
return res.redirect('/login?externalAuthError=true');
|
return res.redirect('/login?externalAuthError=true');
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
logger.info('YakNet SSO Plugin initialized with Callback URL: ' + callbackUrl);
|
router.get('/auth-callback', handleOAuthCallback);
|
||||||
|
|
||||||
|
// Also support legacy /plugins/peertube-plugin-auth-yaknet/router/auth-callback on any PeerTube server without bridge.js
|
||||||
|
try {
|
||||||
|
if (peertubeHelpers && peertubeHelpers.server && typeof peertubeHelpers.server.getHTTPServer === 'function') {
|
||||||
|
const httpServer = peertubeHelpers.server.getHTTPServer();
|
||||||
|
const listeners = httpServer ? httpServer.listeners('request') : [];
|
||||||
|
const expressApp = listeners && listeners[0];
|
||||||
|
if (expressApp && typeof expressApp.get === 'function') {
|
||||||
|
expressApp.get('/plugins/peertube-plugin-auth-yaknet/router/auth-callback', (req, res) => {
|
||||||
|
return handleOAuthCallback(req, res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
logger.info('YakNet SSO Plugin initialized with Callback URL: ' + getActiveCallbackUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function unregister() {
|
async function unregister() {
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peertube-plugin-auth-yaknet",
|
"name": "peertube-plugin-auth-yaknet",
|
||||||
"version": "1.0.6",
|
"version": "1.1.1",
|
||||||
"description": "YakNet SSO & OAuth2 Single Sign-On Authentication Plugin for PeerTube",
|
"description": "YakNet SSO & OAuth2 Single Sign-On Authentication Plugin for PeerTube",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"library": "./main.js",
|
"library": "./main.js",
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
"author": "Enes Yakıştır <[email protected]>",
|
"author": "Enes Yakıştır <[email protected]>",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/yakistir98/peertube-plugin-auth-yaknet.git"
|
"url": "git+https://github.com/yakistir98/peertube-plugin-auth-yaknet.git"
|
||||||
},
|
},
|
||||||
"homepage": "https://yaktube.yakhub.com.tr",
|
"homepage": "https://yaktube.yakhub.com.tr",
|
||||||
"bugs": "https://github.com/yakistir98/peertube-plugin-auth-yaknet/issues",
|
"bugs": "https://github.com/yakistir98/peertube-plugin-auth-yaknet/issues",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.yaknet-sso-btn {
|
.yaknet-sso-btn {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -6,17 +6,127 @@
|
|||||||
background: linear-gradient(135deg, #ff8f37 0%, #ff5e3a 100%);
|
background: linear-gradient(135deg, #ff8f37 0%, #ff5e3a 100%);
|
||||||
color: #fff !important;
|
color: #fff !important;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
padding: 10px 18px;
|
font-size: 15px;
|
||||||
|
padding: 12px 20px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
margin: 12px 0;
|
margin: 14px 0 8px 0;
|
||||||
box-shadow: 0 4px 15px rgba(255, 143, 55, 0.35);
|
box-shadow: 0 4px 16px rgba(255, 143, 55, 0.35);
|
||||||
transition:
|
transition:
|
||||||
transform 0.2s ease,
|
transform 0.2s ease,
|
||||||
|
box-shadow 0.2s ease,
|
||||||
opacity 0.2s ease;
|
opacity 0.2s ease;
|
||||||
|
cursor: pointer;
|
||||||
|
border: none;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.yaknet-sso-btn:hover {
|
.yaknet-sso-btn:hover {
|
||||||
transform: translateY(-2px);
|
transform: translateY(-2px);
|
||||||
opacity: 0.95;
|
box-shadow: 0 6px 20px rgba(255, 143, 55, 0.5);
|
||||||
|
opacity: 0.98;
|
||||||
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-sso-login-wrapper {
|
||||||
|
margin: 10px 0 20px 0;
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-divider {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
text-align: center;
|
||||||
|
margin: 16px 0 10px 0;
|
||||||
|
color: var(--greyColor, #94a3b8);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-divider::before,
|
||||||
|
.yaknet-divider::after {
|
||||||
|
content: '';
|
||||||
|
flex: 1;
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-divider:not(:empty)::before {
|
||||||
|
margin-right: 0.75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-divider:not(:empty)::after {
|
||||||
|
margin-left: 0.75em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-auth-error-box {
|
||||||
|
background: rgba(239, 68, 68, 0.1);
|
||||||
|
border: 1px solid rgba(239, 68, 68, 0.35);
|
||||||
|
border-left: 4px solid #ef4444;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 14px 18px;
|
||||||
|
margin: 14px 0 20px 0;
|
||||||
|
color: #fca5a5;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.5;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-error-title {
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 15px;
|
||||||
|
color: #f87171;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-error-desc {
|
||||||
|
margin: 0 0 10px 0;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-error-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-error-actions a {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-retry-btn {
|
||||||
|
background: #ef4444;
|
||||||
|
color: #fff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-help-btn {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
color: #e2e8f0 !important;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-retry-btn:hover,
|
||||||
|
.yaknet-help-btn:hover {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-account-link {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: #ff8f37 !important;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.yaknet-account-link:hover {
|
||||||
|
color: #ffaa5e !important;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user