MarcelRobitaille / bbyen

Bring Back YouTube Email Notifications! YouTube upload email notification replacement
MIT License
10 stars 0 forks source link

Unable to authorize #9

Closed Jozko568 closed 2 years ago

Jozko568 commented 2 years ago

Hi, I'm trying to set this up but whenever I try to run node src/index.js and authorize via the given URL, I'm being redirected to non working page where the code should be displayed. I noticed that the URL contains http://localhost from the google-credentials.json file but even if I try to change it to a different address or specify any port, the page never loads. I do not have any service running on port 80 so that should not be an issue. Google credentials are setup as desktop app.

I tried to authorize on Windows (also in Windows Sandbox) and Ubuntu but I got the same result. Is there some step which is not mentioned in the readme?

Node version: v16.15.1

bbyen - error code

MarcelRobitaille commented 2 years ago

That is strange. The URL copy-pasted from the terminal is immediately redirecting to localhost? Would you try a different browser or a private tab? There were not any additional steps last time I set this up, but I know google likes to changes things for the fun of it.

Jozko568 commented 2 years ago

No, it's not. This is the page after I authorize via Google. After I click Continue (by giving bbyen access to my account) I'm being redirected on this page above. I tried to open it in fresh Windows Sandbox environment, Firefox in Ubuntu but I ended up with the same result.

Recently I setup rclone which uses similiar authorization but I was redirected correctly as rclone stated Success. This seems like there is a missing server from bbyen which is required in order to get the code.

NightMean commented 2 years ago

Unfortunately I can confirm this. I was unable to set it up. Seems like Google changed the authorization process and it no longer gives out the key to be copied. Is there any way that the code could be shown regardless?

MarcelRobitaille commented 2 years ago

Ok, I just tried it with a fresh installation and fresh Google cloud project. When I pasted the link and authorized and everything, I was indeed redirected to http://localhost. I think the code query parameter is what you need to paste in the terminal. Would you please try copy everything after (not including) localhost/?code= up until the first &, which for me is &scope=.... and paste that in the terminal?

NightMean commented 2 years ago

Thanks! That works as a workaround.

Any plans to update the readme or the actual authorization process?

Also worth pointing out, it seems like gmail is no longer supported as per google changes mentioned here

[verbose] [videos]: New video from SometimesYouCom (id: AI0pgtw5-a4): Almost My Floor - PlayStation 5 / PlayStation 4 Release Trailer
[error] [videos]: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials z23-20020a170906435700b007094f98788csm6121655ejm.113 - gsmtp

Edit: I was able to set it up using App passwords

Everything seems to work, videos are being grabbed as expected. Thanks a lot.

Jozko568 commented 2 years ago

Can confirm. Authorization works when using the code from the URL as you described.

MarcelRobitaille commented 2 years ago

Any plans to update the readme or the actual authorization process?

Yes, I might try to do it the "proper" way and have the local server answer that request and save the code. I just have to figure out why it's http://localhost and not http://localhost:3030/some/path. I might change the readme until then.

Glad it's working for you both

MarcelRobitaille commented 2 years ago

I did some more research. It seems like the old google-credentials.json had the redirect_uris to be urn:ietf:wg:oauth:2.0:oob or localhost. The former only showed the code, and the latter sends the request to localhost. I tried forcing the former, and I get a 400 invalid request response. I think Google discontinued this way. I am not sure why they did this. I see no security advantage. Maybe they just want to discourage the clunky "copy paste this code into the terminal". image

MarcelRobitaille commented 2 years ago

The new proper and automatic method is in 55a04e1b. It automatically opens the browser tab, and opens a server to listen for the response code. Would either of you be willing to test the new method? If you use the same folder, you will have to delete .google-auth-token.json. You also need to specify a port in config.json. I used 3030.

NightMean commented 2 years ago

Hm, after tinkering with it in WSL, the URL gets opened automatically however the localhost is unreachable. As it no longer waits for code, I can't add it using the workaround. Not sure how this would work if the machine is headless?

Tried to run it with Node on my Windows 10 with Node v16 but I ended up with an error message below: I was able to fix it thanks to this thread.

Error message ``` bbyen2>node src/index.js node:internal/modules/cjs/loader:936 throw err; ^ Error: Cannot find module 'D:\Downloads\bbyen - Youtube Notify\bbyen2\node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.node' Require stack: - D:\Downloads\bbyen - Youtube Notify\bbyen2\node_modules\sqlite3\lib\sqlite3-binding.js - D:\Downloads\bbyen - Youtube Notify\bbyen2\node_modules\sqlite3\lib\sqlite3.js - D:\Downloads\bbyen - Youtube Notify\bbyen2\src\database.js - D:\Downloads\bbyen - Youtube Notify\bbyen2\src\index.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (D:\Downloads\bbyen - Youtube Notify\bbyen2\node_modules\sqlite3\lib\sqlite3-binding.js:4:15) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) { code: 'MODULE_NOT_FOUND', requireStack: [ 'D:\\Downloads\\bbyen - Youtube Notify\\bbyen2\\node_modules\\sqlite3\\lib\\sqlite3-binding.js', 'D:\\Downloads\\bbyen - Youtube Notify\\bbyen2\\node_modules\\sqlite3\\lib\\sqlite3.js', 'D:\\Downloads\\bbyen - Youtube Notify\\bbyen2\\src\\database.js', 'D:\\Downloads\\bbyen - Youtube Notify\\bbyen2\\src\\index.js' ] } ```

After this I found another issue which is mentioned here I found that the port 3030 is excluded. Changing the port to something like 9200 worked and I was able to authorize automatically as per your latest commit. https://github.com/MarcelRobitaille/bbyen/commit/55a04e1b8e2fc952f2ab9b558b2ac8ce0544cb38

Error message ``` node:events:505 throw er; // Unhandled 'error' event ^ Error: listen EACCES: permission denied 0.0.0.0:3030 at Server.setupListenHandle [as _listen2] (node:net:1355:21) at listenInCluster (node:net:1420:12) at Server.listen (node:net:1508:7) at tokens (D:\Downloads\bbyen - Youtube Notify\bbyen2\src\google\auth\index.js:75:10) at new Promise () at genAuthToken (D:\Downloads\bbyen - Youtube Notify\bbyen2\src\google\auth\index.js:55:23) at getToken (D:\Downloads\bbyen - Youtube Notify\bbyen2\src\google\auth\index.js:102:16) at async authorize (D:\Downloads\bbyen - Youtube Notify\bbyen2\src\google\auth\index.js:122:30) at async main (D:\Downloads\bbyen - Youtube Notify\bbyen2\src\index.js:19:16) Emitted 'error' event on Server instance at: at emitErrorNT (node:net:1399:8) at processTicksAndRejections (node:internal/process/task_queues:83:21) { code: 'EACCES', errno: -4092, syscall: 'listen', address: '0.0.0.0', port: 3030 } ```

The strange thing is that after authorization I received this error message however bbyen continued to check the subscriptions. Not sure if it may cause some issues later on.

[info] [google-auth]: Got code: undefined
[info] [google-auth]: Creating tokens from code
TypeError: Cannot read properties of undefined (reading 'code')
    at OAuth2Client.getTokenAsync (D:\Downloads\bbyen - Youtube Notify\bbyen2\node_modules\google-auth-library\build\src\auth\oauth2client.js:115:27)
    at OAuth2Client.getToken (D:\Downloads\bbyen - Youtube Notify\bbyen2\node_modules\google-auth-library\build\src\auth\oauth2client.js:109:25)
    at Server.handler (D:\Downloads\bbyen - Youtube Notify\bbyen2\src\google\auth\index.js:64:43)
    at Server.emit (node:events:527:28)
    at parserOnIncoming (node:_http_server:956:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)`
[verbose] [videos]: Checking channel TestChannel (UCMjg7arXVvaS5baey5mY2oA)
MarcelRobitaille commented 2 years ago

@NightMean sorry for the delay. Thanks for trying it!

As it no longer waits for code, I can't add it using the workaround. Not sure how this would work if the machine is headless?

That is a good point. I updated it so that both methods are supported. If the automatic method does not work, you can still paste into the terminal.

The strange thing is that after authorization I received this error message however bbyen continued to check the subscriptions. Not sure if it may cause some issues later on.

I got this once too, but I was not able to reproduce it after that. I suspect what happened is that two requests were made to localhost, and one failed (did not have any code or anything). Maybe the browser was trying to fetch /favicon.ico or something. In my latest commits, I add checks and ignore any requests other than GET to /authorization_code. That should stop such things from happening in the future.

I updated the documentation too to include this new authentication method.

I would like to hear what you think of these updates.

NightMean commented 2 years ago

Thanks for the update! I did not have issues running it on my Windows machine, the auth code was automatically accepted (I used port 9020 again). However on my Linux headless VM I was unable to authorize. I tried to paste the whole URL (as per your commit https://github.com/MarcelRobitaille/bbyen/commit/8d1b290b834f729e6b456788d923b14630a58cf7) and then only the code as previously but I received the same error message in both cases.

Enter the code from that page: 4/0AdQt8qgVUUzQR81knYpCeD2zT1I_haFus6QeNJgtF78nVgAeqKMUxDV6pBeog1Nf4W7C7A
[error] [main]: Cannot use 'in' operator to search for '&' in 4/0AdQt8qgVUUzQR81knYpCeD2zT1I_haFus6QeNJgtF78nVgAeqKMUxDV6pBeog1Nf4W7C7A
^C

On another note, I received error invalid_grant on my second Google project, will reopen issue https://github.com/MarcelRobitaille/bbyen/issues/7 Currently, I'm not able to test emails as I have to wait until Google actually removes my previous projects.

MarcelRobitaille commented 2 years ago

I've been doing too much Python. That error should be fixed. Not sure how I didn't catch it.

I'll check out that other issue for invalid_grant.

MarcelRobitaille commented 2 years ago

May I ask why you're running this twice? Is it for two different YouTube accounts?

NightMean commented 2 years ago

I've been doing too much Python. That error should be fixed. Not sure how I didn't catch it.

Thanks for the quick fix! Pasting the URL still throws an error message, but different this time. Pasting just the code works like a charm now!

[error] [main]: url.parse is not a function

May I ask why you're running this twice? Is it for two different YouTube accounts?

No it's not for 2 Youtube accounts. I guess I'm just the type of a person who likes to have it working on all environments haha. (Somebody has to catch all the bugs, right?) I run it primarily on my Linux VM but I tried to run it on my Windows just for test.

MarcelRobitaille commented 2 years ago

[error] [main]: url.parse is not a function

Sorry about that. Another stupid mistake. Should be fixed now.

NightMean commented 2 years ago

Works like a charm now! Links and code is now accepted as expected! Perhaps a small improvement would be to change the text that is displayed after the auth URL. Enter the code from that page: to something like Paste whole URL after authorization or something like that which is understandable.

Other than that I only found 1 major issue. I did not find any way to donate! May I request a fix for this?

MarcelRobitaille commented 2 years ago

Wow. That's never come up before. Thank you very much. It's very kind. I am willing to set up donations. What would you prefer? Paypal, GitHub sponsors, bitcoin? I would also be happy if you donated to another open source project as well.

I will think about changing that string.

MarcelRobitaille commented 2 years ago

I changed it to Paste the entire URL of the page you are redirected to (even if you receive 404):. What do you think?

NightMean commented 2 years ago

Wow. That's never come up before. Thank you very much. It's very kind. I am willing to set up donations. What would you prefer? Paypal, GitHub sponsors, bitcoin? I would also be happy if you donated to another open source project as well.

I will think about changing that string.

I prefer PayPal if that's okay. I already donated to couple 😁

I changed it to Paste the entire URL of the page you are redirected to (even if you receive 404):. What do you think?

Yup, sounds better to me! Thanks!

MarcelRobitaille commented 2 years ago

I added my paypal link to the readme. Thank you very much @NightMean. You don't have to donate anything.

Do you think we can close this?

NightMean commented 2 years ago

Thanks to you I can keep my Youtube obsession for longer haha! Sure, we can close it.

Thanks for the quick fixes! 👍