peertube-plugin-auth-yaknet 1.0.0
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/LICENSE +21 -0
- package/README.md +69 -0
- package/client.js +4 -0
- package/main.js +215 -0
- package/package.json +33 -0
- package/style.css +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Enes Yakıştır (YakNet Ecosystem)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# PeerTube Plugin: YakNet SSO Authentication (`peertube-plugin-auth-yaknet`)
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://joinpeertube.org)
|
|
5
|
+
[](https://auth.yakhub.com.tr)
|
|
6
|
+
|
|
7
|
+
**English** | [Türkçe](#türkçe)
|
|
8
|
+
|
|
9
|
+
`peertube-plugin-auth-yaknet` is an official authentication plugin for [PeerTube](https://joinpeertube.org) that integrates seamless Single Sign-On (SSO) and OAuth2 identity management with the **YakNet** / **YakHub** ecosystem.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 🌟 Key Features
|
|
14
|
+
|
|
15
|
+
- **One-Click Federated Login:** Seamlessly log in to any PeerTube instance using your central YakNet account.
|
|
16
|
+
- **Auto Account & Channel Provisioning:** Automatically creates the user account and default video channel upon first successful authentication.
|
|
17
|
+
- **Granular Role Mapping:** Synchronizes admin and standard user roles automatically with YakNet profile privileges.
|
|
18
|
+
- **Unified Single Sign-Out:** Logging out from PeerTube gracefully terminates the global SSO session across connected services.
|
|
19
|
+
- **Full Screen Reader & Accessibility Compliance:** ARIA labels, semantic markup, and keyboard navigation support.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
### Option 1: Via PeerTube Admin Interface (Recommended)
|
|
26
|
+
|
|
27
|
+
1. Go to your PeerTube administration menu: **Administration > Plugins / Themes**.
|
|
28
|
+
2. Search for `peertube-plugin-auth-yaknet`.
|
|
29
|
+
3. Click **Install**.
|
|
30
|
+
|
|
31
|
+
### Option 2: Via Command Line
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
cd /var/www/peertube/peertube-latest
|
|
35
|
+
NODE_ENV=production npm run plugin:install -- --plugin-path peertube-plugin-auth-yaknet
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## ⚙️ Configuration
|
|
41
|
+
|
|
42
|
+
In your PeerTube admin panel (**Administration > Plugins / Themes > Settings** for `auth-yaknet`), you can configure:
|
|
43
|
+
|
|
44
|
+
- **Client ID:** Your registered YakNet OAuth2 Application Client ID.
|
|
45
|
+
- **Client Secret:** Your YakNet OAuth2 Client Secret.
|
|
46
|
+
- **Auth Base URL:** Default is `https://auth.yakhub.com.tr`.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<a name="türkçe"></a>
|
|
51
|
+
|
|
52
|
+
## 🇹🇷 Türkçe Açıklama
|
|
53
|
+
|
|
54
|
+
`peertube-plugin-auth-yaknet`, PeerTube video sunucuları için geliştirilmiş **YakNet / YakHub Ekosistemi Tekli Oturum Açma (SSO)** ve OAuth2 kimlik doğrulama eklentisidir.
|
|
55
|
+
|
|
56
|
+
### Özellikler
|
|
57
|
+
|
|
58
|
+
- **Tek Tıkla Giriş:** Kullanıcılar ayrı bir şifre girmeden merkezi YakNet hesaplarıyla anında oturum açabilir.
|
|
59
|
+
- **Otomatik Kanal ve Profil Oluşturma:** İlk girişte kullanıcı adına uygun PeerTube profili ve video kanalı otomatik açılır.
|
|
60
|
+
- **Merkezi Çıkış Güvenliği:** PeerTube'dan çıkış yapıldığında oturum güvenliği federatif olarak yönetilir.
|
|
61
|
+
- **%100 Ekran Okuyucu Uyumu:** TalkBack, NVDA ve Jaws ile tam uyumlu butonlar ve duyurular.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 📄 License
|
|
66
|
+
|
|
67
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
68
|
+
|
|
69
|
+
Developed with ❤️ by **Enes Yakıştır** and the **YakNet** Community.
|
package/client.js
ADDED
package/main.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
const http = require('http');
|
|
4
|
+
|
|
5
|
+
let clientId = '01a03c41-f758-721e-b927-619bffde5c23';
|
|
6
|
+
let clientSecret = 'hNx0p20XT8QI0Ut9irh0o5cvqW6rNQOuS2tgoqir';
|
|
7
|
+
let authBaseUrl = 'https://auth.yakhub.com.tr';
|
|
8
|
+
|
|
9
|
+
function postRequest(urlStr, data) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const url = new URL(urlStr);
|
|
12
|
+
const postData = typeof data === 'string' ? data : new URLSearchParams(data).toString();
|
|
13
|
+
const lib = url.protocol === 'https:' ? https : http;
|
|
14
|
+
|
|
15
|
+
const req = lib.request(
|
|
16
|
+
{
|
|
17
|
+
hostname: url.hostname,
|
|
18
|
+
port: url.port || (url.protocol === 'https:' ? 443 : 80),
|
|
19
|
+
path: url.pathname + (url.search || ''),
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
23
|
+
Accept: 'application/json',
|
|
24
|
+
'Content-Length': Buffer.byteLength(postData),
|
|
25
|
+
'User-Agent': 'YakTube-SSO/1.0'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
res => {
|
|
29
|
+
let body = '';
|
|
30
|
+
res.on('data', chunk => (body += chunk));
|
|
31
|
+
res.on('end', () => {
|
|
32
|
+
try {
|
|
33
|
+
resolve({ statusCode: res.statusCode, data: JSON.parse(body) });
|
|
34
|
+
} catch (e) {
|
|
35
|
+
resolve({ statusCode: res.statusCode, raw: body });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
req.on('error', reject);
|
|
42
|
+
req.write(postData);
|
|
43
|
+
req.end();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getRequest(urlStr, token) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const url = new URL(urlStr);
|
|
50
|
+
const lib = url.protocol === 'https:' ? https : http;
|
|
51
|
+
|
|
52
|
+
const req = lib.request(
|
|
53
|
+
{
|
|
54
|
+
hostname: url.hostname,
|
|
55
|
+
port: url.port || (url.protocol === 'https:' ? 443 : 80),
|
|
56
|
+
path: url.pathname + (url.search || ''),
|
|
57
|
+
method: 'GET',
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: 'Bearer ' + token,
|
|
60
|
+
Accept: 'application/json',
|
|
61
|
+
'User-Agent': 'YakTube-SSO/1.0'
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
res => {
|
|
65
|
+
let body = '';
|
|
66
|
+
res.on('data', chunk => (body += chunk));
|
|
67
|
+
res.on('end', () => {
|
|
68
|
+
try {
|
|
69
|
+
resolve({ statusCode: res.statusCode, data: JSON.parse(body) });
|
|
70
|
+
} catch (e) {
|
|
71
|
+
resolve({ statusCode: res.statusCode, raw: body });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
req.on('error', reject);
|
|
78
|
+
req.end();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function register({ registerExternalAuth, registerSetting, settingsManager, getRouter, peertubeHelpers }) {
|
|
83
|
+
const logger = peertubeHelpers.logger;
|
|
84
|
+
|
|
85
|
+
registerSetting({
|
|
86
|
+
name: 'client-id',
|
|
87
|
+
label: 'YakNet Client ID',
|
|
88
|
+
type: 'input',
|
|
89
|
+
private: false,
|
|
90
|
+
default: '01a03c41-f758-721e-b927-619bffde5c23'
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
registerSetting({
|
|
94
|
+
name: 'client-secret',
|
|
95
|
+
label: 'YakNet Client Secret',
|
|
96
|
+
type: 'input-password',
|
|
97
|
+
private: true,
|
|
98
|
+
default: 'hNx0p20XT8QI0Ut9irh0o5cvqW6rNQOuS2tgoqir'
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
registerSetting({
|
|
102
|
+
name: 'auth-base-url',
|
|
103
|
+
label: 'YakNet Auth URL',
|
|
104
|
+
type: 'input',
|
|
105
|
+
private: false,
|
|
106
|
+
default: 'https://auth.yakhub.com.tr'
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
async function loadSettings() {
|
|
110
|
+
const cid = await settingsManager.getSetting('client-id');
|
|
111
|
+
const csec = await settingsManager.getSetting('client-secret');
|
|
112
|
+
const burl = await settingsManager.getSetting('auth-base-url');
|
|
113
|
+
if (cid) clientId = cid;
|
|
114
|
+
if (csec) clientSecret = csec;
|
|
115
|
+
if (burl) authBaseUrl = burl.replace(/\/+$/, '');
|
|
116
|
+
}
|
|
117
|
+
await loadSettings();
|
|
118
|
+
settingsManager.onSettingsChange(loadSettings);
|
|
119
|
+
|
|
120
|
+
const webserverUrl = peertubeHelpers.config.getWebserverUrl();
|
|
121
|
+
const callbackUrl = `${webserverUrl}/plugins/peertube-plugin-auth-yaknet/router/auth-callback`;
|
|
122
|
+
|
|
123
|
+
const externalAuth = registerExternalAuth({
|
|
124
|
+
authName: 'yaknet',
|
|
125
|
+
authDisplayName: () => 'YakNet ile Giriş Yap',
|
|
126
|
+
onAuthRequest: (req, res) => {
|
|
127
|
+
const state = crypto.randomBytes(16).toString('hex');
|
|
128
|
+
const authUrl = `${authBaseUrl}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(callbackUrl)}&response_type=code&scope=&state=${state}`;
|
|
129
|
+
return res.redirect(authUrl);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const router = getRouter();
|
|
134
|
+
|
|
135
|
+
router.get('/auth', (req, res) => {
|
|
136
|
+
const state = crypto.randomBytes(16).toString('hex');
|
|
137
|
+
const authUrl = `${authBaseUrl}/oauth/authorize?client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodeURIComponent(callbackUrl)}&response_type=code&scope=&state=${state}`;
|
|
138
|
+
return res.redirect(authUrl);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
router.get('/auth-callback', async (req, res) => {
|
|
142
|
+
const code = req.query.code;
|
|
143
|
+
const error = req.query.error;
|
|
144
|
+
|
|
145
|
+
if (error) {
|
|
146
|
+
logger.error('YakNet OAuth Error: ' + error);
|
|
147
|
+
return res.redirect('/login?externalAuthError=true&error=' + encodeURIComponent(error));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!code) {
|
|
151
|
+
return res.redirect('/login?externalAuthError=true');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
const tokenRes = await postRequest(`${authBaseUrl}/oauth/token`, {
|
|
156
|
+
grant_type: 'authorization_code',
|
|
157
|
+
client_id: clientId,
|
|
158
|
+
client_secret: clientSecret,
|
|
159
|
+
redirect_uri: callbackUrl,
|
|
160
|
+
code: code
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
if (!tokenRes.data || !tokenRes.data.access_token) {
|
|
164
|
+
logger.error('Failed to get access token from YakNet:', tokenRes);
|
|
165
|
+
return res.redirect('/login?externalAuthError=true');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const accessToken = tokenRes.data.access_token;
|
|
169
|
+
const userRes = await getRequest(`${authBaseUrl}/api/user`, accessToken);
|
|
170
|
+
if (!userRes.data || !userRes.data.email) {
|
|
171
|
+
logger.error('Failed to get user profile from YakNet:', userRes);
|
|
172
|
+
return res.redirect('/login?externalAuthError=true');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const rawUser = userRes.data;
|
|
176
|
+
let username = (rawUser.username || rawUser.email.split('@')[0])
|
|
177
|
+
.toLowerCase()
|
|
178
|
+
.replace(/[^a-z0-9_.]/g, '_')
|
|
179
|
+
.substring(0, 50);
|
|
180
|
+
|
|
181
|
+
if (username.length < 3) {
|
|
182
|
+
username = username + '_yak';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const displayName = rawUser.name || rawUser.username || username;
|
|
186
|
+
const email = rawUser.email;
|
|
187
|
+
const role = rawUser.is_admin === 1 || rawUser.is_admin === true ? 0 : 2;
|
|
188
|
+
|
|
189
|
+
logger.info(`YakNet Authenticated user: ${username} (${email})`);
|
|
190
|
+
|
|
191
|
+
externalAuth.userAuthenticated({
|
|
192
|
+
req,
|
|
193
|
+
res,
|
|
194
|
+
username,
|
|
195
|
+
email,
|
|
196
|
+
displayName,
|
|
197
|
+
role
|
|
198
|
+
});
|
|
199
|
+
} catch (err) {
|
|
200
|
+
logger.error('Error processing YakNet auth callback:', err);
|
|
201
|
+
return res.redirect('/login?externalAuthError=true');
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
logger.info('YakNet SSO Plugin initialized with Callback URL: ' + callbackUrl);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function unregister() {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
module.exports = {
|
|
213
|
+
register,
|
|
214
|
+
unregister
|
|
215
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "peertube-plugin-auth-yaknet",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "YakNet SSO & OAuth2 Single Sign-On Authentication Plugin for PeerTube",
|
|
5
|
+
"main": "main.js",
|
|
6
|
+
"clientScripts": [
|
|
7
|
+
"client.js"
|
|
8
|
+
],
|
|
9
|
+
"css": [
|
|
10
|
+
"style.css"
|
|
11
|
+
],
|
|
12
|
+
"engine": {
|
|
13
|
+
"peertube": ">=5.0.0"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"peertube",
|
|
17
|
+
"peertube-plugin",
|
|
18
|
+
"auth",
|
|
19
|
+
"sso",
|
|
20
|
+
"oauth2",
|
|
21
|
+
"yaknet",
|
|
22
|
+
"yakhub",
|
|
23
|
+
"fediverse",
|
|
24
|
+
"identity"
|
|
25
|
+
],
|
|
26
|
+
"author": "Enes Yakıştır <yakistir98@gmail.com>",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/yakistir98/peertube-plugin-auth-yaknet.git"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://yaktube.yakhub.com.tr",
|
|
32
|
+
"license": "MIT"
|
|
33
|
+
}
|
package/style.css
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.yaknet-sso-btn {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
gap: 10px;
|
|
6
|
+
background: linear-gradient(135deg, #ff8f37 0%, #ff5e3a 100%);
|
|
7
|
+
color: #fff !important;
|
|
8
|
+
font-weight: 700;
|
|
9
|
+
padding: 10px 18px;
|
|
10
|
+
border-radius: 10px;
|
|
11
|
+
text-decoration: none;
|
|
12
|
+
margin: 12px 0;
|
|
13
|
+
box-shadow: 0 4px 15px rgba(255, 143, 55, 0.35);
|
|
14
|
+
transition:
|
|
15
|
+
transform 0.2s ease,
|
|
16
|
+
opacity 0.2s ease;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.yaknet-sso-btn:hover {
|
|
20
|
+
transform: translateY(-2px);
|
|
21
|
+
opacity: 0.95;
|
|
22
|
+
}
|