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 | |
|---|---|---|---|
|
|
8e8170a8dc | ||
|
|
4327c510e9 | ||
|
|
f40f5ca905 | ||
|
|
f11c9bdeee | ||
|
|
8c1eb882a3 | ||
|
|
0b4a25f684 | ||
|
|
d890d60dad | ||
|
|
9d12320035 | ||
|
|
a23a151618 | ||
|
|
c141d4232e | ||
|
|
688530d8e5 |
@@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
dist/
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 120,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "auto"
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://joinpeertube.org)
|
||||
[](https://auth.yakhub.com.tr)
|
||||
[](https://developer-console.yakhub.com.tr)
|
||||
|
||||
**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 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,4 +1,57 @@
|
||||
function register() {
|
||||
console.log('[YakNet Auth] Client script loaded');
|
||||
async function register({ registerHook, peertubeHelpers }) {
|
||||
try {
|
||||
fetch('/plugins/auth-yaknet/router/status')
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (status) {
|
||||
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');
|
||||
|
||||
// If user directly visits /login without local override or error, forward to YakNet SSO
|
||||
if (isLoginUrl && !isLocal && !isError) {
|
||||
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')) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
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);
|
||||
}
|
||||
}
|
||||
module.exports = { register };
|
||||
|
||||
export { register, register as registerClient };
|
||||
export default register;
|
||||
@@ -4,11 +4,22 @@ const http = require('http');
|
||||
|
||||
let clientId = '';
|
||||
let clientSecret = '';
|
||||
let authBaseUrl = 'https://auth.yakhub.com.tr';
|
||||
let authBaseUrl = 'https://developer-console.yakhub.com.tr';
|
||||
|
||||
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) => {
|
||||
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 lib = url.protocol === 'https:' ? https : http;
|
||||
|
||||
@@ -26,6 +37,12 @@ function postRequest(urlStr, data) {
|
||||
}
|
||||
},
|
||||
res => {
|
||||
// Follow 301, 302, 307, 308 redirects automatically
|
||||
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 = '';
|
||||
res.on('data', chunk => (body += chunk));
|
||||
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) => {
|
||||
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 req = lib.request(
|
||||
@@ -62,6 +83,12 @@ function getRequest(urlStr, token) {
|
||||
}
|
||||
},
|
||||
res => {
|
||||
// Follow 301, 302, 307, 308 redirects automatically
|
||||
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 = '';
|
||||
res.on('data', chunk => (body += chunk));
|
||||
res.on('end', () => {
|
||||
@@ -104,18 +131,95 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
||||
name: 'auth-base-url',
|
||||
label: 'YakNet Auth URL',
|
||||
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,
|
||||
default: 'https://auth.yakhub.com.tr'
|
||||
default: 'https://developer-console.yakhub.com.tr'
|
||||
});
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
let autoRedirectLogin = true;
|
||||
|
||||
function syncConfigFiles(enable) {
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 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() {
|
||||
const cid = await settingsManager.getSetting('client-id');
|
||||
const csec = await settingsManager.getSetting('client-secret');
|
||||
const burl = await settingsManager.getSetting('auth-base-url');
|
||||
const autoRedir = await settingsManager.getSetting('auto-redirect-login');
|
||||
if (cid) clientId = cid;
|
||||
if (csec) clientSecret = csec;
|
||||
if (burl) authBaseUrl = burl.replace(/\/+$/, '');
|
||||
if (burl) {
|
||||
authBaseUrl = normalizeAuthUrl(burl.replace(/\/+$/, ''));
|
||||
}
|
||||
if (autoRedir !== undefined && autoRedir !== null) {
|
||||
autoRedirectLogin = autoRedir === true || autoRedir === 'true';
|
||||
} else {
|
||||
autoRedirectLogin = true;
|
||||
}
|
||||
syncConfigFiles(autoRedirectLogin);
|
||||
}
|
||||
await loadSettings();
|
||||
settingsManager.onSettingsChange(loadSettings);
|
||||
@@ -128,16 +232,22 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
||||
authDisplayName: () => 'YakNet ile Giriş Yap',
|
||||
onAuthRequest: (req, res) => {
|
||||
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 authUrl = `${normalizeAuthUrl(authBaseUrl)}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(callbackUrl)}&response_type=code&scope=&state=${state}`;
|
||||
return res.redirect(authUrl);
|
||||
}
|
||||
});
|
||||
|
||||
const router = getRouter();
|
||||
|
||||
router.get('/status', (req, res) => {
|
||||
return res.json({
|
||||
autoRedirectLogin: autoRedirectLogin !== false
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/auth', (req, res) => {
|
||||
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 authUrl = `${normalizeAuthUrl(authBaseUrl)}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(callbackUrl)}&response_type=code&scope=&state=${state}`;
|
||||
return res.redirect(authUrl);
|
||||
});
|
||||
|
||||
@@ -155,7 +265,8 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
||||
}
|
||||
|
||||
try {
|
||||
const tokenRes = await postRequest(`${authBaseUrl}/oauth/token`, {
|
||||
const targetAuthUrl = normalizeAuthUrl(authBaseUrl);
|
||||
const tokenRes = await postRequest(`${targetAuthUrl}/oauth/token`, {
|
||||
grant_type: 'authorization_code',
|
||||
client_id: clientId,
|
||||
client_secret: clientSecret,
|
||||
@@ -164,14 +275,14 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
||||
});
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
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) {
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -207,6 +318,18 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
|
||||
displayName,
|
||||
role
|
||||
});
|
||||
|
||||
if (peertubeHelpers && peertubeHelpers.database && peertubeHelpers.database.query) {
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await peertubeHelpers.database.query('UPDATE "user" SET "emailVerified" = true WHERE email = $1', {
|
||||
bind: [email]
|
||||
});
|
||||
} catch (e) {
|
||||
logger.warn('Failed to auto-verify email in DB for ' + email, e);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('Error processing YakNet auth callback:', err);
|
||||
return res.redirect('/login?externalAuthError=true');
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "peertube-plugin-auth-yaknet",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.10",
|
||||
"description": "YakNet SSO & OAuth2 Single Sign-On Authentication Plugin for PeerTube",
|
||||
"main": "main.js",
|
||||
"library": "./main.js",
|
||||
|
||||
Reference in New Issue
Block a user