Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly Add License #5

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
693d52d
Use user@domain for "email"
agates Jan 24, 2021
76290f9
Ensure username is lowercase
agates Jan 24, 2021
bf4a1de
Remove email from test
agates Jan 24, 2021
08e1b60
Update readme to add Mastodon
agates Jan 24, 2021
354f8a2
Default to sending auth token in header
agates Jan 24, 2021
b67b4b4
Fix test after removing email field
agates Jan 24, 2021
455a572
Update package info with name changes
agates Jan 24, 2021
ff9a05f
Fix author
agates Jan 24, 2021
626fff6
Update version
agates Jan 24, 2021
27a18a3
Add "mastodon" keyword
agates Jan 25, 2021
1eeefa6
Fix redirectUrl
agates Jan 26, 2021
e40e6e7
1.0.6
moderniz Feb 14, 2021
6cd8932
Fix documentation for Identity URL path
agates Mar 7, 2021
3aa67ee
Identity token over header required for Mastodon
agates Mar 7, 2021
18231cd
Use user@domain for "email"
agates Jan 24, 2021
e202bb9
Ensure username is lowercase
agates Jan 24, 2021
8af06d3
Remove email from test
agates Jan 24, 2021
b00d49c
Update readme to add Mastodon
agates Jan 24, 2021
8c29d4d
Default to sending auth token in header
agates Jan 24, 2021
f2145f9
Fix test after removing email field
agates Jan 24, 2021
e7bc0a1
Update package info with name changes
agates Jan 24, 2021
b42d062
Fix author
agates Jan 24, 2021
5058252
Update version
agates Jan 24, 2021
6cf6087
Add "mastodon" keyword
agates Jan 25, 2021
729499f
Fix redirectUrl
agates Jan 26, 2021
41516a0
Fix documentation for Identity URL path
agates Mar 7, 2021
9a2b93e
Identity token over header required for Mastodon
agates Mar 7, 2021
f6066a4
Merge remote-tracking branch 'origin/master'
agates Mar 7, 2021
e41649c
Update new config info from upstream
agates Mar 7, 2021
08b5caa
Version 2.0.4
agates Mar 7, 2021
2f40478
Create LICENSE.txt
ncorder Nov 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
661 changes: 661 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# OAuth 2.0 server plugin for PeerTube
# Mastodon OAuth 2.0 server plugin for PeerTube

This PeerTube server plugin adds support to a PeerTube instance for external authentication via an OAuth 2.0 provider.
This PeerTube server plugin adds support to a PeerTube instance for external authentication via a Mastodon OAuth 2.0 provider.

## Dependencies

* **NodeJS >= 10.x**
* **PeerTube >= 2.2.0**

## OAuth 2.0 Provider Requirements

To properly use this plugin, the OAuth 2.0 provider must support confidential clients. See [RFC6749: 2.1. Client Types](https://tools.ietf.org/html/rfc6749#section-2.1).

> Note: [Nextcloud's](https://docs.nextcloud.com/server/20/admin_manual//configuration_server/oauth2.html) OAuth2 implementation is not supported.

## Configuration

The redirection endpoint provided by this plugin is available at `/plugins/auth-oauth2/router/callback`. Use the following URI in your OAuth 2.0 provider's `callback URL` or `redirection URI` setting.
The redirection endpoint provided by this plugin is available at `/plugins/auth-oauth2-mastodon/router/callback`. Use the following URI in Mastodon's `Redirect URI` setting.

`https://<your instance hostname>/plugins/auth-oauth2/router/callback`
`https://<your instance hostname>/plugins/auth-oauth2-mastodon/router/callback`

> Note: Replace `<your instance hostname>` with the hostname of your PeerTube instance.

Expand All @@ -34,10 +28,9 @@ To activate the plugin, configure the following settings after installation:
| Scope | yes | One or more Scope names separated by a single space. |
| Authorize URL path | yes | The URL from the provider that signs the user in. *example: `/oauth2/authorize`* |
| Token URL path | yes | The URL from the provider that gets the user's access tokens. *example: `/oauth2/token`* |
| Identity URL path | yes | The URL from the provider that returns information about the authenticated user in a JSON format. *example: `/oauth2/userInfo`* |
| Identity URL path | yes | The URL from the provider that returns information about the authenticated user in a JSON format. *example: `/api/v1/accounts/verify_credentials`* |
| Identity username field | yes | The name of the field that contains the user's username. |
| Identity email field | yes | The name of the field that contains the user's email. |
| Send identity token sent via HTTP header? | | Enable this setting to pass the access token using the `Authorization` header when requesting information about the authenticated user. *Required for AWS Cognito.* |
| Send identity token sent via HTTP header? | | Enable this setting to pass the access token using the `Authorization` header when requesting information about the authenticated user. *Required for Mastodon.* |
| Identity access token URL parameter name | | The URL parameter name used to pass the access token when requesting information about the authenticated user. *Required if the access token is sent via the URL.* |

> Note: The plugin will not function if the required settings are missing or if the settings for the provider are incorrect.
Expand All @@ -59,4 +52,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
9 changes: 1 addition & 8 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ const expectedSettings = [
private: true,
default: 'username'
},
{
name: 'identityEmailField',
label: 'Identity email field (required)',
type: 'input',
private: true,
default: 'email'
},
{
name: 'sendIdentityTokenViaHeader',
label: 'Send identity token sent via HTTP header? (required for AWS Cognito)',
Expand Down Expand Up @@ -153,7 +146,7 @@ it('register function smoke test', async () => {
getRouter,
});
// Assert
expect(registerSetting).toHaveBeenCalledTimes(12);
expect(registerSetting).toHaveBeenCalledTimes(expectedSettings.length);
expectedSettings.forEach((setting, index) => {
expect(setting).toStrictEqual(
registerSetting.mock.calls[index][0]
Expand Down
19 changes: 4 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const store = {
authDisplayName: 'OAuth2',
identityPath: null,
identityUsernameField: null,
identityEmailField: null,
sendIdentityTokenViaHeader: null,
sendIdentityTokenViaHeader: true,
accessTokenParam: null,
};

Expand Down Expand Up @@ -94,8 +93,8 @@ async function handleCallback(peertubeHelpers, settingsManager, req, res) {
).then(
async (identityResponse) => {
const identityData = await identityResponse.json();
const username = identityData[store.identityUsernameField];
const email = identityData[store.identityEmailField];
const username = identityData[store.identityUsernameField].toLowerCase();
const email = `${username}@${store.domain}`;
const role = 2; // Admin = 0, Moderator = 1, User = 2
return store.userAuthenticated({
res,
Expand Down Expand Up @@ -147,7 +146,6 @@ async function loadSettingsAndCreateClient(
'clientId',
'clientSecret',
'domain',
'identityEmailField',
'identityPath',
'sendIdentityTokenViaHeader',
'identityUsernameField',
Expand All @@ -161,7 +159,6 @@ async function loadSettingsAndCreateClient(
clientId,
clientSecret,
domain,
identityEmailField,
identityPath,
sendIdentityTokenViaHeader,
identityUsernameField,
Expand Down Expand Up @@ -221,13 +218,12 @@ async function loadSettingsAndCreateClient(
store.scope = scope.trim();
store.domain = domain;
store.accessTokenParam = accessTokenParam;
store.identityEmailField = identityEmailField;
store.identityPath = identityPath;
store.sendIdentityTokenViaHeader = sendIdentityTokenViaHeader;
store.identityUsernameField = identityUsernameField;

const webserverUrl = config.getWebserverUrl();
store.redirectUrl = `${webserverUrl}/plugins/auth-oauth2/router/callback`;
store.redirectUrl = `${webserverUrl}/plugins/auth-oauth2-mastodon/router/callback`;

store.client = new ClientOAuth2({
clientId,
Expand Down Expand Up @@ -327,13 +323,6 @@ async function register({
private: true,
default: 'username'
});
registerSetting({
name: 'identityEmailField',
label: 'Identity email field (required)',
type: 'input',
private: true,
default: 'email'
});
registerSetting({
name: 'sendIdentityTokenViaHeader',
label: 'Send identity token sent via HTTP header? (required for AWS Cognito)',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "peertube-plugin-auth-oauth2",
"description": "A PeerTube server plugin that adds support for external authentication via an OAuth 2.0 provider. The callback URL path is /plugins/auth-oauth2/router/callback",
"version": "1.0.5",
"author": "Codify Global LLC",
"name": "peertube-plugin-auth-oauth2-mastodon",
"description": "A PeerTube server plugin that adds support for external authentication via a Mastodon OAuth 2.0 provider. The callback URL path is /plugins/auth-oauth2-mastodon/router/callback",
"version": "2.0.4",
"author": "Alecks Gates",
"license": "AGPL-3.0",
"bugs": "https://github.com/codifyglobal/peertube-plugin-auth-oauth2/issues",
"bugs": "https://github.com/agates/peertube-plugin-auth-oauth2-mastodon/issues",
"directories": {
"test": "__tests__"
},
Expand All @@ -15,13 +15,14 @@
"peertube",
"plugin",
"auth",
"oauth2"
"oauth2",
"mastodon"
],
"scripts": {
"test": "jest",
"lint": "eslint main.js helpers/*.js __tests__/*.js"
},
"homepage": "https://github.com/codifyglobal/peertube-plugin-auth-oauth2",
"homepage": "https://github.com/agates/peertube-plugin-auth-oauth2-mastodon",
"staticDirs": {},
"css": [],
"clientScripts": [],
Expand Down