mirror of https://github.com/vitalif/grive2
refactored. changed license to GPLv2 only. clean up console UI.
parent
947664937a
commit
41033f9bd5
|
@ -7,10 +7,10 @@ include(FindOpenSSL)
|
|||
add_executable( grive
|
||||
src/main.cc
|
||||
src/OAuth2.cc
|
||||
src/HTTP.cc
|
||||
src/Json.cc
|
||||
src/Drive.cc
|
||||
src/Download.cc )
|
||||
src/protocol/HTTP.cc
|
||||
src/protocol/Json.cc
|
||||
src/protocol/Download.cc )
|
||||
|
||||
target_link_libraries( grive
|
||||
curl
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -19,8 +19,8 @@
|
|||
|
||||
#include "Drive.hh"
|
||||
|
||||
#include "HTTP.hh"
|
||||
#include "Json.hh"
|
||||
#include "protocol/HTTP.hh"
|
||||
#include "protocol/Json.hh"
|
||||
#include "OAuth2.hh"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -18,8 +18,9 @@
|
|||
*/
|
||||
|
||||
#include "OAuth2.hh"
|
||||
#include "HTTP.hh"
|
||||
#include "Json.hh"
|
||||
|
||||
#include "protocol/HTTP.hh"
|
||||
#include "protocol/Json.hh"
|
||||
|
||||
// for debugging
|
||||
#include <iostream>
|
||||
|
@ -27,25 +28,32 @@
|
|||
namespace gr {
|
||||
|
||||
const std::string token_url = "https://accounts.google.com/o/oauth2/token" ;
|
||||
const std::string client_id = "22314510474.apps.googleusercontent.com" ;
|
||||
const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ;
|
||||
|
||||
OAuth2::OAuth2( const std::string& refresh_code ) :
|
||||
m_refresh( refresh_code )
|
||||
OAuth2::OAuth2(
|
||||
const std::string& refresh_code,
|
||||
const std::string& client_id,
|
||||
const std::string& client_secret ) :
|
||||
m_refresh( refresh_code ),
|
||||
m_client_id( client_id ),
|
||||
m_client_secret( client_secret )
|
||||
{
|
||||
Refresh( ) ;
|
||||
}
|
||||
|
||||
OAuth2::OAuth2( )
|
||||
OAuth2::OAuth2(
|
||||
const std::string& client_id,
|
||||
const std::string& client_secret ) :
|
||||
m_client_id( client_id ),
|
||||
m_client_secret( client_secret )
|
||||
{
|
||||
}
|
||||
|
||||
void OAuth2::Auth( const std::string& auth_code )
|
||||
void OAuth2::Auth( const std::string& auth_code )
|
||||
{
|
||||
std::string post =
|
||||
"code=" + auth_code +
|
||||
"&client_id=" + client_id +
|
||||
"&client_secret=" + client_secret +
|
||||
"&client_id=" + m_client_id +
|
||||
"&client_secret=" + m_client_secret +
|
||||
"&redirect_uri=" + "urn:ietf:wg:oauth:2.0:oob" +
|
||||
"&grant_type=authorization_code" ;
|
||||
|
||||
|
@ -74,8 +82,8 @@ void OAuth2::Refresh( )
|
|||
{
|
||||
std::string post =
|
||||
"refresh_token=" + m_refresh +
|
||||
"&client_id=" + client_id +
|
||||
"&client_secret=" + client_secret +
|
||||
"&client_id=" + m_client_id +
|
||||
"&client_secret=" + m_client_secret +
|
||||
"&grant_type=refresh_token" ;
|
||||
|
||||
Json resp = Json::Parse( HttpPostData( token_url, post ) ) ;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -26,8 +26,13 @@ namespace gr {
|
|||
class OAuth2
|
||||
{
|
||||
public :
|
||||
OAuth2( ) ;
|
||||
explicit OAuth2( const std::string& refresh_code ) ;
|
||||
OAuth2(
|
||||
const std::string& client_id,
|
||||
const std::string& client_secret ) ;
|
||||
OAuth2(
|
||||
const std::string& refresh_code,
|
||||
const std::string& client_id,
|
||||
const std::string& client_secret ) ;
|
||||
|
||||
std::string Str() const ;
|
||||
|
||||
|
@ -47,6 +52,9 @@ public :
|
|||
private :
|
||||
std::string m_access ;
|
||||
std::string m_refresh ;
|
||||
|
||||
const std::string m_client_id ;
|
||||
const std::string m_client_secret ;
|
||||
} ;
|
||||
|
||||
} // end of namespace
|
||||
|
|
24
src/main.cc
24
src/main.cc
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "OAuth2.hh"
|
||||
#include "Drive.hh"
|
||||
#include "Json.hh"
|
||||
#include "protocol/Json.hh"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
|
@ -27,6 +27,9 @@
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
const std::string client_id = "22314510474.apps.googleusercontent.com" ;
|
||||
const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ;
|
||||
|
||||
namespace gr
|
||||
{
|
||||
const std::string& ConfigFilename()
|
||||
|
@ -75,19 +78,20 @@ int main( int argc, char **argv )
|
|||
case 'a' :
|
||||
{
|
||||
std::cout
|
||||
<< "Please go to this URL and enter the code:\n"
|
||||
<< OAuth2::MakeAuthURL( "22314510474.apps.googleusercontent.com" )
|
||||
<< "-----------------------\n"
|
||||
<< "Please go to this URL and get an authenication code:\n\n"
|
||||
<< OAuth2::MakeAuthURL( client_id )
|
||||
<< std::endl ;
|
||||
|
||||
std::cout
|
||||
<< "\n-----------------------\n"
|
||||
<< "Please input the authenication code here" << std::endl ;
|
||||
std::string code ;
|
||||
std::cin >> code ;
|
||||
|
||||
OAuth2 token ;
|
||||
OAuth2 token( client_id, client_secret ) ;
|
||||
token.Auth( code ) ;
|
||||
|
||||
// print the refresh token an exist
|
||||
std::cout << "got refresh token: " << token.RefreshToken() << std::endl ;
|
||||
|
||||
// save to config
|
||||
config.Add( "refresh_token", Json( token.RefreshToken() ) ) ;
|
||||
assert( config["refresh_token"].As<std::string>() == token.RefreshToken() ) ;
|
||||
|
@ -98,7 +102,7 @@ int main( int argc, char **argv )
|
|||
}
|
||||
}
|
||||
|
||||
OAuth2 token( config["refresh_token"].As<std::string>() ) ;
|
||||
OAuth2 token( config["refresh_token"].As<std::string>(), client_id, client_secret ) ;
|
||||
Drive drive( token ) ;
|
||||
|
||||
return 0 ;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
as published by the Free Software Foundation; version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Loading…
Reference in New Issue