Commit cc6e2c0428962e60d506e4ac4d32f203135cfd42
1 parent
78a2ff96
Simplified auth token handling.
Showing
9 changed files
with
8 additions
and
37 deletions
httpclient.cpp
... | ... | @@ -19,10 +19,6 @@ HTTPClient::~HTTPClient() { |
19 | 19 | } |
20 | 20 | } |
21 | 21 | |
22 | -void HTTPClient::set_auth_token(std::string token) { | |
23 | - this->auth_token = token; | |
24 | -} | |
25 | - | |
26 | 22 | void HTTPClient::request(std::string url, HTTPClient::CompleteFunc callback) { |
27 | 23 | request(url, HTTPFlag::NONE, callback); |
28 | 24 | } |
... | ... | @@ -73,7 +69,8 @@ void HTTPClient::execute_next() { |
73 | 69 | if (req->flags & HTTPFlag::AUTH) { |
74 | 70 | ss |
75 | 71 | << "X-Line-Application: " << LINE_APPLICATION << "\r\n" |
76 | - << "X-Line-Access: " << auth_token << "\r\n"; | |
72 | + << "X-Line-Access: " | |
73 | + << purple_account_get_string(acct, LINE_ACCOUNT_AUTH_TOKEN, "") << "\r\n"; | |
77 | 74 | } |
78 | 75 | |
79 | 76 | if (req->content_type.size()) | ... | ... |
httpclient.hpp
... | ... | @@ -38,8 +38,6 @@ class HTTPClient { |
38 | 38 | |
39 | 39 | PurpleAccount *acct; |
40 | 40 | |
41 | - std::string auth_token; | |
42 | - | |
43 | 41 | std::list<Request *> request_queue; |
44 | 42 | int in_flight; |
45 | 43 | |
... | ... | @@ -55,8 +53,6 @@ public: |
55 | 53 | HTTPClient(PurpleAccount *acct); |
56 | 54 | ~HTTPClient(); |
57 | 55 | |
58 | - void set_auth_token(std::string token); | |
59 | - | |
60 | 56 | void request(std::string url, CompleteFunc callback); |
61 | 57 | void request(std::string url, HTTPFlag flags, CompleteFunc callback); |
62 | 58 | void request(std::string url, HTTPFlag flags, | ... | ... |
linehttptransport.cpp
... | ... | @@ -21,7 +21,6 @@ LineHttpTransport::LineHttpTransport( |
21 | 21 | host(host), |
22 | 22 | port(port), |
23 | 23 | ls_mode(ls_mode), |
24 | - auth_token(""), | |
25 | 24 | state(ConnectionState::DISCONNECTED), |
26 | 25 | auto_reconnect(false), |
27 | 26 | reconnect_timeout_handle(0), |
... | ... | @@ -45,10 +44,6 @@ void LineHttpTransport::set_auto_reconnect(bool auto_reconnect) { |
45 | 44 | this->auto_reconnect = auto_reconnect; |
46 | 45 | } |
47 | 46 | |
48 | -void LineHttpTransport::set_auth_token(std::string token) { | |
49 | - this->auth_token = token; | |
50 | -} | |
51 | - | |
52 | 47 | int LineHttpTransport::status_code() { |
53 | 48 | return status_code_; |
54 | 49 | } |
... | ... | @@ -171,7 +166,8 @@ void LineHttpTransport::send_next() { |
171 | 166 | << "User-Agent: " LINE_USER_AGENT "\r\n" |
172 | 167 | << "X-Line-Application: " LINE_APPLICATION "\r\n"; |
173 | 168 | |
174 | - if (auth_token != "") | |
169 | + const char *auth_token = purple_account_get_string(acct, LINE_ACCOUNT_AUTH_TOKEN, ""); | |
170 | + if (auth_token) | |
175 | 171 | data << "X-Line-Access: " << auth_token << "\r\n"; |
176 | 172 | } |
177 | 173 | ... | ... |
linehttptransport.hpp
... | ... | @@ -39,7 +39,6 @@ class LineHttpTransport : public apache::thrift::transport::TTransport { |
39 | 39 | std::string host; |
40 | 40 | uint16_t port; |
41 | 41 | bool ls_mode; |
42 | - std::string auth_token; | |
43 | 42 | std::string x_ls; |
44 | 43 | |
45 | 44 | ConnectionState state; |
... | ... | @@ -77,7 +76,6 @@ public: |
77 | 76 | ~LineHttpTransport(); |
78 | 77 | |
79 | 78 | void set_auto_reconnect(bool auto_reconnect); |
80 | - void set_auth_token(std::string token); | |
81 | 79 | |
82 | 80 | virtual void open(); |
83 | 81 | virtual void close(); | ... | ... |
pinverifier.cpp
... | ... | @@ -49,7 +49,8 @@ void PINVerifier::verify( |
49 | 49 | WRAPPER(PINVerifier::timeout_cb), |
50 | 50 | (gpointer)this); |
51 | 51 | |
52 | - http.set_auth_token(verifier); | |
52 | + parent.set_auth_token(verifier); | |
53 | + | |
53 | 54 | http.request(LINE_VERIFICATION_URL, HTTPFlag::AUTH, |
54 | 55 | [this, verifier, success](int status, const guchar *data, gsize len) |
55 | 56 | { | ... | ... |
poller.hpp
purpleline_login.cpp
... | ... | @@ -4,15 +4,11 @@ void PurpleLine::login_start() { |
4 | 4 | purple_connection_set_state(conn, PURPLE_CONNECTING); |
5 | 5 | purple_connection_update_progress(conn, "Logging in", 0, 3); |
6 | 6 | |
7 | - std::string auth_token(purple_account_get_string(acct, LINE_ACCOUNT_AUTH_TOKEN, "")); | |
8 | - | |
9 | - if (auth_token.size()) { | |
7 | + if (purple_account_get_string(acct, LINE_ACCOUNT_AUTH_TOKEN, NULL)) { | |
10 | 8 | // There's a stored authentication token, see if it works |
11 | 9 | |
12 | - set_auth_token(auth_token); | |
13 | - | |
14 | 10 | c_out->send_getLastOpRevision(); |
15 | - c_out->send([this, auth_token]() { | |
11 | + c_out->send([this]() { | |
16 | 12 | int64_t local_rev; |
17 | 13 | |
18 | 14 | try { |
... | ... | @@ -37,8 +33,6 @@ void PurpleLine::login_start() { |
37 | 33 | |
38 | 34 | poller.set_local_rev(local_rev); |
39 | 35 | |
40 | - set_auth_token(auth_token); | |
41 | - | |
42 | 36 | // Already got the last op revision, no need to call get_last_op_revision() |
43 | 37 | |
44 | 38 | get_profile(); |
... | ... | @@ -121,11 +115,6 @@ void PurpleLine::set_auth_token(std::string auth_token) { |
121 | 115 | c_out->close(); |
122 | 116 | c_out->set_auto_reconnect(true); |
123 | 117 | c_out->set_path(LINE_COMMAND_PATH); |
124 | - | |
125 | - c_out->set_auth_token(auth_token); | |
126 | - poller.set_auth_token(auth_token); | |
127 | - os_http.set_auth_token(auth_token); | |
128 | - http.set_auth_token(auth_token); | |
129 | 118 | } |
130 | 119 | |
131 | 120 | void PurpleLine::get_last_op_revision() { | ... | ... |
thriftclient.cpp
... | ... | @@ -23,10 +23,6 @@ void ThriftClient::set_auto_reconnect(bool auto_reconnect) { |
23 | 23 | http->set_auto_reconnect(auto_reconnect); |
24 | 24 | } |
25 | 25 | |
26 | -void ThriftClient::set_auth_token(std::string token) { | |
27 | - http->set_auth_token(token); | |
28 | -} | |
29 | - | |
30 | 26 | void ThriftClient::send(std::function<void()> callback) { |
31 | 27 | http->request("POST", path, "application/x-thrift", callback); |
32 | 28 | } | ... | ... |