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

Save client id and secret when using grive -a #242

Closed
wants to merge 5 commits into from

Conversation

jankatins
Copy link

If you wanted to give a different than the default client id and secret, you always had to give that on the commandline. Now it's saved in the .give file. If given on the commandline, it's now also only used when 'auth/-a' is given, in normal runs it's not anymore valid (and errors out).

This is a workaround for #236 so you simply add your own client id and secret to get the sync going again.

This partly reverts #160 because it removes the possibility to set the client id and secret on the command line during a normal (not -a) run. I found that intuitive as the corresponding refresh token was saved to disc and so changing the id/secret (on the command line) was actually not possible as long as you do not change the refresh token. (That's at least my understanding here, cc: @cgltower, @kuschuermann)

@jankatins
Copy link
Author

Oh, please look over my changes, this is basically my first c PR and the changes are mostly c&p + string changes...

@jankatins
Copy link
Author

cc: @redmercury @0x3333 as they were in the contributer/discussers in #160

@jankatins
Copy link
Author

Unfortunately, this seems to not work: after sign in and getting the gibberish code to input into the cli, I get this error:

exception: /home/js/external/grive2/libgrive/src/protocol/OAuth2.cc(116): Throw in function void gr::OAuth2::Refresh()
Dynamic exception type: boost::exception_detail::clone_impl<gr::OAuth2::AuthFailed>
[gr::expt::BacktraceTag*] = #0 0x55607e2f8f96 grive gr::Exception::Exception()
#1 0x55607e2f08d9 grive gr::OAuth2::AuthFailed::AuthFailed()
#2 0x55607e2f05d3 grive gr::OAuth2::Refresh()
#3 0x55607e2ef420 grive gr::OAuth2::OAuth2(gr::http::Agent*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
#4 0x55607e29eceb grive Main(int, char**)
#5 0x55607e29fb71 grive main
#6 0x7f9e2691fb17 /lib/x86_64-linux-gnu/libc.so.6 __libc_start_main
#7 0x55607e29d23a grive _start

@jankatins
Copy link
Author

Seems the error was related to how to create the oauth2 client and the new instruction in the readme fixed the auth error for me. I've a working grive client again, yay :-)

}
}

// This is not included in the below 'refresh-token' try
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've a commit locally where I put that into the same try block, but that would error on upgrade because teh .grive file would not include a already saved client id/secret. -> Not backward compatible. It would save 10 lines of duplicatec code, though...

@amplatfus
Copy link

amplatfus commented Dec 7, 2018

Unfortunately, this seems to not work: after sign in and getting the gibberish code to input into the cli, I get this error:

exception: /home/js/external/grive2/libgrive/src/protocol/OAuth2.cc(116): Throw in function void gr::OAuth2::Refresh()
Dynamic exception type: boost::exception_detail::clone_impl<gr::OAuth2::AuthFailed>
[gr::expt::BacktraceTag*] = #0 0x55607e2f8f96 grive gr::Exception::Exception()
#1 0x55607e2f08d9 grive gr::OAuth2::AuthFailed::AuthFailed()
#2 0x55607e2f05d3 grive gr::OAuth2::Refresh()
#3 0x55607e2ef420 grive gr::OAuth2::OAuth2(gr::http::Agent*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
#4 0x55607e29eceb grive Main(int, char**)
#5 0x55607e29fb71 grive main
#6 0x7f9e2691fb17 /lib/x86_64-linux-gnu/libc.so.6 __libc_start_main
#7 0x55607e29d23a grive _start

Hi,
Could you please detail what steps did you execute? I want to try this too.
Many thanks!

PS: I am using it on Entware

@jankatins
Copy link
Author

See the reeadme additions in this pr.

@amplatfus
Copy link

After grive -a --id client_id --secret client_secret (when sync is working well) at the next sync with grive command: grive I obtain the error below:
Could you please provide some help? Thank you so much! Also, in .grive file I see only one key.

Failed to refresh auth token: HTTP 401, body: {
"error": "unauthorized_client",
"error_description": "Unauthorized"
}
exception: /media/ware/Entware.2018.09/build_dir/target-arm_cortex-a9_glibc-2.23_eabi/grive2-0.5.1-20180819/libgrive/src/protocol/OAuth2.cc(116): Throw in function void gr::OAuth2::Refresh()
Dynamic exception type: boost::exception_detail::clone_implgr::OAuth2::AuthFailed
[gr::expt::BacktraceTag*] = #0 0x9362c grive gr::OAuth2::AuthFailed::AuthFailed()
#1 0x931c4 grive gr::OAuth2::Refresh()
#2 0x933cc grive gr::OAuth2::OAuth2(gr::http::Agent*, std::string const&, std::string const&, std::string const&)
#3 0x4b520 grive Main(int, char**)
#4 0x49924 grive main
#5 0x2b1a6c00 /opt/lib/libc.so.6 __libc_start_main

@jankatins
Copy link
Author

I had that error as well but I think i solved that by following the steps in the (updated by this pr) readme how to create the oauth2 client tokens.

@amplatfus
Copy link

I had that error as well but I think i solved that by following the steps in the (updated by this pr) readme how to create the oauth2 client tokens.
Thank you for reply. Could you please help me to locate the file?
I see only README.md here without how to create the oauth2 client tokens section.
10q, All the best!

@jankatins
Copy link
Author

See here, everything which is green: https://github.com/vitalif/grive2/pull/242/files

@amplatfus
Copy link

Thanks. I have already id and secret. For first sync it works. At the second I receive the error.
Please share if you have some advice. Thank you!

user@router:/tmp/mnt/folder/drive# grive -a --id id.apps.googleusercontent.com --secret secret
-----------------------
Please go to this URL and get an authentication code:
https://accounts.google.com/o/oauth2/auth?codeetc.apps.googleusercontent.com
-----------------------
Please input the authentication code here: 
324343key
Reading local directories
Reading remote server file list
Synchronizing files
sync "./Google Photos/2018/12/MOVIE.mp4" changed in remote. downloading
sync "./.grive-new_v1" created in remote. creating local
sync "./.grive_last_v1" created in remote. creating local
sync "./.grive (another copy)" created in remote. creating local
sync "./.grive (copy)" created in remote. creating local
sync "./.grive_test" created in remote. creating local
sync "./.grive_state (copy)" created in remote. creating local
Finished!
user@router:/tmp/mnt/folder/drive# grive
Failed to refresh auth token: HTTP 401, body: {
  "error": "unauthorized_client",
  "error_description": "Unauthorized"
}
exception: /media/ware/Entware.2018.09/build_dir/target-arm_cortex-a9_glibc-2.23_eabi/grive2-0.5.1-20180819/libgrive/src/protocol/OAuth2.cc(116): Throw in function void gr::OAuth2::Refresh()
Dynamic exception type: boost::exception_detail::clone_impl<gr::OAuth2::AuthFailed>
[gr::expt::BacktraceTag*] = #0 0x9362c grive gr::OAuth2::AuthFailed::AuthFailed()
#1 0x931c4 grive gr::OAuth2::Refresh()
#2 0x933cc grive gr::OAuth2::OAuth2(gr::http::Agent*, std::string const&, std::string const&, std::string const&)
#3 0x4b520 grive Main(int, char**)
#4 0x49924 grive main
#5 0x2b195c00 /opt/lib/libc.so.6 __libc_start_main
user@router:/tmp/mnt/folder/drive# 

@jankatins
Copy link
Author

Ah, now i understand. Can you look into .grive if the right id and secret are in there? Looks a bit like this is an pre-this-pr version

@amplatfus
Copy link

amplatfus commented Dec 16, 2018

No, is not there. Only refresh_token is in that file. I mention that I am on entware linux distribution installed in Asus router. What I do not understand is that when grive -a --id client_id --secret client_secret all is fine. Grive recognize id and secret. I can see that are implemented also when entering grive -h.

Still searching. If I find the fix I will share it!
Thank you for support!

@jankatins
Copy link
Author

jankatins commented Dec 16, 2018

@amplatfus What happened is that you are still on a version which does not have this PR. So the id and secret are not saved. So in the second call, you again have to use ... --id ... --secret ..., otherwise it's a mismatch between the refresh token (generated with your specified id/secret) and the used id/ secret (default ones which are compiled in).

Only with this PR, the id and secret are saved during the grive -a --id ... --secret .. call and are then used by the grive (without any arguments) call.

@amplatfus
Copy link

So you suggest to use grive - -id... - -secret at all calls? Because the id and secret are not saved at the first call when.grive is created?
Thank you so much!

@jankatins
Copy link
Author

@amplatfus IF you are on a currently released version (=this PR is not applied), then yes. Only when this PR is merged and released, you only need to specify it in the grive -a call.

@amplatfus
Copy link

@amplatfus IF you are on a currently released version (=this PR is not applied), then yes. Only when this PR is merged and released, you only need to specify it in the grive -a call.

Thank you so much for the solution.
I entered first:
grive -a --id 123-xyz.apps.googleusercontent.com --secret DE6XYZ
And after, every time I want to sync:
grive --id 123-xyz.apps.googleusercontent.com --secret DE6XYZ
And is working. Thanks again for fast reply and fix.
All the best!

@kasi-mir33
Copy link

kasi-mir33 commented Feb 11, 2019

I can't seem to get this to work. Similarly to amplatfus I get this Error:

  "error": "unauthorized_client",
  "error_description": "Unauthorized"
}
exception: /home/_____/grive2/libgrive/src/protocol/OAuth2.cc(116): Throw in function void gr::OAuth2::Refresh()
Dynamic exception type: boost::exception_detail::clone_impl<gr::OAuth2::AuthFailed>
[gr::expt::BacktraceTag*] = #0 0x55c9e80f6317 grive gr::Exception::Exception()
#1 0x55c9e80d9a5b grive gr::OAuth2::AuthFailed::AuthFailed()
#2 0x55c9e80d9708 grive gr::OAuth2::Refresh()
#3 0x55c9e80d8522 grive gr::OAuth2::OAuth2(gr::http::Agent*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
#4 0x55c9e80945ae grive Main(int, char**)
#5 0x55c9e809551a grive main
#6 0x7fa7d0f7b1c1 /lib/x86_64-linux-gnu/libc.so.6 __libc_start_main
#7 0x55c9e80928da grive _start

This happens after I call the grive -a --id client_id --secret client_secret
The Authentication seems to work fine and I followed your steps from the updated README exactly.
I even fetched and merged this PR with git pull origin pull/242/head

Also updated according to the steps described here : http://yourcmc.ru/wiki/Grive2#Updates

my .grive is still only showing the refresh token.

Thanks for your effort!

@jankatins
Copy link
Author

Does it work with the old grive version? If not, too, then it seems I didn't get all steps to build a new google client token. :-(

If you wanted to give a different than the default client id and
secret, you always had to give that on the commandline. Now it's saved
in the .give file. If given on the commandline, it's now also only
used when 'auth/-a' is given, in normal runs it's not anymore valid (and errors out).
* Updated debhelper compat level to latest stable one
@vitalif
Copy link
Owner

vitalif commented Dec 15, 2019

Hi. I've just merged #294 which effectively does the same. So sorry for not merging your PR even though it's already a year old. :)

@jankatins
Copy link
Author

This still has the readme explanations how to set the id during runtime. If they are the same it might make sense to pull these in

@AmonRaNet
Copy link

Can we create other pull request with yours README changes.
Also we can add the fact, that grive not refreshing the existing config file and if you need to refresh the values you need to delete the old file.

@AmonRaNet
Copy link

I have open pull request #297 with cherry-pick of your readme. Hope is fine for you @jankatins.
Too many people ask the same questions, and here is more or less complete instruction.

@jankatins
Copy link
Author

This already in via #294

@jankatins jankatins closed this Mar 15, 2021
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

Successfully merging this pull request may close these issues.

6 participants