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

Getting "Cannot retrieve OAuth Client credentials: undefined" when configuring at some arbitrary ports #3234

Closed
entomologe opened this issue Oct 29, 2020 · 10 comments

Comments

@entomologe
Copy link

entomologe commented Oct 29, 2020

Hello; what a great project! When testing on some arbitrary port, I get the following warning:

Cannot retrieve OAuth Client credentials: undefined. Ensure you have correctly configured PeerTube (config/ directory), in particular the “webserver” section.

I configured everything else like in the documentation described (except the standard ports), so my configuration differs as follows:

/var/www/peertube/config/production.yaml:

listen:
hostname: 'localhost'
port: 9000
webserver:
https: true
port: 4443
...

/etc/nginx/sites-enabled/peertube:

server {
listen 8000;
listen [::]:8000;
location / { return 301 "https://$host:4443$request_uri"; }
...
server {
listen 4443 ssl http2;
listen [::]:4443 ssl http2;
...

My syslog prints the following meaningful regarding the problem:

Oct 28 14:07:11 localhost peertube[18140]: [peertube.$DOMAIN:4443] 2020-10-28 14:07:11.694 #33[33mwarn#033[39m: It seems PeerTube was started (and created some data) with another domain name. This means you
will not be able to federate! Please use NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run update-host to fix this.

When I proceed like told I get:

npm ERR! path /var/www/peertube/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/var/www/peertube/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent


Just a quick sidenote: when changing the 2 configs above to standard ports, everything works fine. Meanwhile I used this aproach as I have already apache listening on 80 and 443 and did not felt to migrate the nginx vhost config to apache or migrate my other vhosts to nginx. ; )

@Chocobozzz
Copy link
Owner

Hello,

You should run the command in peertube-latest directory

@Chocobozzz Chocobozzz added the Status: Waiting for answer Waiting issue author answer label Oct 29, 2020
@entomologe
Copy link
Author

entomologe commented Oct 30, 2020

You should run the command in peertube-latest directory

Thanks. This indeed fixed the errors npm gave me, meanwhile the issue remains. Any ideas why I still get that error? What does it mean? What should I try to change in the "webserver" section?

@Chocobozzz
Copy link
Owner

What is your instance URL?

@ilgiaco
Copy link

ilgiaco commented Dec 25, 2020

Hi @Chocobozzz I installed your software two days ago, and got the same problem.
I couldn't log in and got "Getting client tokens for host myinstance.com is forbidden (expected myinstance.com:1234)." error in logs
I configured webserver section setting port param to 1234 in config/production.yaml.
It seems that there is a bug in file peertube-latest/dist/server/controllers/api/oauth-clients.js when checking host correctness. If configured port is different from 80 or 443 then headerHostShouldBe variable is composed by serverHostname + ':' + serverPort, but just serverHostname when using common ports (80,443)
Then headerHostShouldBe is checked against req.get('host') which seems to always return just "host" part and not port.
Since I'm not expert in using nodejs and don't know which attributes I can get from req (I tried req.get('port') but got "undefined"), I fixed my situation commenting out the part where host and port are concatenated. So here is my peertube-latest/dist/server/controllers/api/oauth-clients.js from peertube version 2.4.0:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.oauthClientsRouter = void 0;
const tslib_1 = require("tslib");
const express = require("express");
const logger_1 = require("../../helpers/logger");
const config_1 = require("../../initializers/config");
const middlewares_1 = require("../../middlewares");
const oauth_client_1 = require("../../models/oauth/oauth-client");
const oauthClientsRouter = express.Router();
exports.oauthClientsRouter = oauthClientsRouter;
oauthClientsRouter.get('/local', middlewares_1.asyncMiddleware(getLocalClient));
function getLocalClient(req, res, next) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const serverHostname = config_1.CONFIG.WEBSERVER.HOSTNAME;
        const serverPort = config_1.CONFIG.WEBSERVER.PORT;
        let headerHostShouldBe = serverHostname;
        // #### I COMMENTED THIS BLOCK ####
        /*if (serverPort !== 80 && serverPort !== 443) {
            headerHostShouldBe += ':' + serverPort;
        }*/
        if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) {
            logger_1.logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe);
            return res.type('json').status(403).end();
        }
        const client = yield oauth_client_1.OAuthClientModel.loadFirstClient();
        if (!client)
            throw new Error('No client available.');
        const json = {
            client_id: client.clientId,
            client_secret: client.clientSecret
        };
        return res.json(json);
    });
}

My 2 cents. Hope it will be useful for someone in future

@Chocobozzz
Copy link
Owner

@ilgiaco What is your instance URL? https://myinstance.com:1234 or just https://myinstance.com?

@ilgiaco
Copy link

ilgiaco commented Jan 1, 2021

I'm currently using https://myinstance.com:1234
Since now I'm just experimenting peertube for private use only, so myinstance.com and 1234 are fake data. My real instance data shouldn't be needed in order to test this bug and my "workaround"

@entomologe
Copy link
Author

What is your instance URL?

Hello @Chocobozzz, I hope I may apologize for the late reply. My instance URL is (due to my arbitrary port) https://domain.tld:4443. Like @ilgiaco I do not feel to share it publicly as it is at the moment for private testing only.

Thanks @ilgiaco for the hint, I'll test your fix soon.

@Chocobozzz
Copy link
Owner

@entomologe
Copy link
Author

Of course I configured the respective port in "production.yaml" as already and initially described above. Moreover I don't exactly understand why this issue was closed as it could be reproduced by someone else in the meantime with similiar intention namely using nonstandard ports.

@rigelk rigelk removed the Status: Waiting for answer Waiting issue author answer label Jan 16, 2021
@vontani
Copy link

vontani commented May 22, 2022

@ilgiaco , thanks ! worked for me with same issue ! but i just entered the dif. port i do use for my instance :) http 8080 /s 4443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants