peertube-plugin-auth-yaknet 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,6 +44,7 @@ In your PeerTube admin panel (**Administration > Plugins / Themes > Settings** f
44
44
  - **Client ID:** Your registered YakNet OAuth2 Application Client ID.
45
45
  - **Client Secret:** Your YakNet OAuth2 Client Secret.
46
46
  - **Auth Base URL:** Default is `https://auth.yakhub.com.tr`.
47
+ - **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).
47
48
 
48
49
  ---
49
50
 
package/client.js CHANGED
@@ -1,3 +1,58 @@
1
1
  function registerClient({ registerHook, peertubeHelpers }) {
2
- // YakNet client script
2
+ try {
3
+ fetch('/plugins/auth-yaknet/router/status')
4
+ .then(function (r) {
5
+ return r.json();
6
+ })
7
+ .then(function (status) {
8
+ if (!status || status.autoRedirectLogin === false) {
9
+ return; // Auto redirect is disabled by administrator
10
+ }
11
+
12
+ var isLoginUrl = window.location.pathname.includes('/login');
13
+ var isLocal = window.location.search.includes('local=true');
14
+ var isError = window.location.search.includes('externalAuthError');
15
+
16
+ // If user directly visits /login without local override or error, forward to YakNet SSO
17
+ if (isLoginUrl && !isLocal && !isError) {
18
+ window.location.replace('/plugins/auth-yaknet/router/auth');
19
+ return;
20
+ }
21
+
22
+ // Intercept clicks on login links/buttons
23
+ document.addEventListener(
24
+ 'click',
25
+ function (e) {
26
+ var el = e.target;
27
+ if (el && el.closest) {
28
+ var isLoginBtn = el.closest(
29
+ '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"]'
30
+ );
31
+ if (isLoginBtn && !window.location.search.includes('local=true')) {
32
+ e.preventDefault();
33
+ e.stopPropagation();
34
+ window.location.href = '/plugins/auth-yaknet/router/auth';
35
+ }
36
+ }
37
+ },
38
+ true
39
+ );
40
+ })
41
+ .catch(function () {});
42
+
43
+ // Alt+A shortcut for local admin login bypass
44
+ document.addEventListener('keydown', function (e) {
45
+ if (e.altKey && (e.key === 'a' || e.key === 'A')) {
46
+ if (!window.location.pathname.includes('/login')) {
47
+ window.location.href = '/login?local=true';
48
+ }
49
+ }
50
+ });
51
+ } catch (err) {
52
+ console.warn('[YakNet SSO] Client init error:', err);
53
+ }
54
+ }
55
+
56
+ if (typeof module !== 'undefined' && module.exports) {
57
+ module.exports = { registerClient: registerClient };
3
58
  }
package/main.js CHANGED
@@ -109,13 +109,87 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
109
109
  default: 'https://auth.yakhub.com.tr'
110
110
  });
111
111
 
112
+ registerSetting({
113
+ name: 'auto-redirect-login',
114
+ label: 'Giriş Sayfasında Doğrudan YakNet SSO\'ya Yönlendir',
115
+ type: 'input-checkbox',
116
+ 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.',
117
+ private: false,
118
+ default: true
119
+ });
120
+
121
+ let autoRedirectLogin = true;
122
+
123
+ function syncConfigFiles(enable) {
124
+ const fs = require('fs');
125
+ const path = require('path');
126
+
127
+ // 1. Update local-production.json if present
128
+ const jsonCandidates = [
129
+ path.resolve(process.cwd(), 'config', 'local-production.json'),
130
+ path.resolve(__dirname, '..', '..', 'config', 'local-production.json'),
131
+ path.resolve(__dirname, '..', '..', '..', 'config', 'local-production.json'),
132
+ 'c:/laragon/www/yaktube.yakhub.com.tr/config/local-production.json'
133
+ ];
134
+ for (const jPath of jsonCandidates) {
135
+ if (fs.existsSync(jPath)) {
136
+ try {
137
+ const cfg = JSON.parse(fs.readFileSync(jPath, 'utf8'));
138
+ if (!cfg.menu) cfg.menu = {};
139
+ if (!cfg.menu.login) cfg.menu.login = {};
140
+ if (cfg.menu.login.redirect_on_single_external_auth !== enable) {
141
+ cfg.menu.login.redirect_on_single_external_auth = enable;
142
+ fs.writeFileSync(jPath, JSON.stringify(cfg, null, 2), 'utf8');
143
+ logger.info(`[YakNet SSO] Synced local-production.json redirect_on_single_external_auth = ${enable}`);
144
+ }
145
+ } catch (e) {
146
+ logger.warn('[YakNet SSO] Error updating local-production.json:', e.message);
147
+ }
148
+ break;
149
+ }
150
+ }
151
+
152
+ // 2. Update production.yaml if present
153
+ const yamlCandidates = [
154
+ path.resolve(process.cwd(), 'config', 'production.yaml'),
155
+ path.resolve(__dirname, '..', '..', 'config', 'production.yaml'),
156
+ path.resolve(__dirname, '..', '..', '..', 'config', 'production.yaml'),
157
+ 'c:/laragon/www/yaktube.yakhub.com.tr/config/production.yaml'
158
+ ];
159
+ for (const yPath of yamlCandidates) {
160
+ if (fs.existsSync(yPath)) {
161
+ try {
162
+ let yContent = fs.readFileSync(yPath, 'utf8');
163
+ const pattern = /(redirect_on_single_external_auth:\s*)(true|false)/;
164
+ if (pattern.test(yContent)) {
165
+ const updated = yContent.replace(pattern, `$1${enable}`);
166
+ if (updated !== yContent) {
167
+ fs.writeFileSync(yPath, updated, 'utf8');
168
+ logger.info(`[YakNet SSO] Synced production.yaml redirect_on_single_external_auth = ${enable}`);
169
+ }
170
+ }
171
+ } catch (e) {
172
+ logger.warn('[YakNet SSO] Error updating production.yaml:', e.message);
173
+ }
174
+ break;
175
+ }
176
+ }
177
+ }
178
+
112
179
  async function loadSettings() {
113
180
  const cid = await settingsManager.getSetting('client-id');
114
181
  const csec = await settingsManager.getSetting('client-secret');
115
182
  const burl = await settingsManager.getSetting('auth-base-url');
183
+ const autoRedir = await settingsManager.getSetting('auto-redirect-login');
116
184
  if (cid) clientId = cid;
117
185
  if (csec) clientSecret = csec;
118
186
  if (burl) authBaseUrl = burl.replace(/\/+$/, '');
187
+ if (autoRedir !== undefined && autoRedir !== null) {
188
+ autoRedirectLogin = autoRedir === true || autoRedir === 'true';
189
+ } else {
190
+ autoRedirectLogin = true;
191
+ }
192
+ syncConfigFiles(autoRedirectLogin);
119
193
  }
120
194
  await loadSettings();
121
195
  settingsManager.onSettingsChange(loadSettings);
@@ -135,6 +209,12 @@ async function register({ registerExternalAuth, registerSetting, settingsManager
135
209
 
136
210
  const router = getRouter();
137
211
 
212
+ router.get('/status', (req, res) => {
213
+ return res.json({
214
+ autoRedirectLogin: autoRedirectLogin !== false
215
+ });
216
+ });
217
+
138
218
  router.get('/auth', (req, res) => {
139
219
  const state = crypto.randomBytes(16).toString('hex');
140
220
  const authUrl = `${authBaseUrl}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(callbackUrl)}&response_type=code&scope=&state=${state}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peertube-plugin-auth-yaknet",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "YakNet SSO & OAuth2 Single Sign-On Authentication Plugin for PeerTube",
5
5
  "main": "main.js",
6
6
  "library": "./main.js",