1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2025-06-30 18:52:47 -04:00

Update: Using another way to authenticate github module (#2029)

The github module only authenticate by query string, and this method is deprecated:
https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters


There is no reason to remove it before the method stop working, so I've made possible to the user choose which authentication method he will use:

* The parameter token remain unchanged.
* If the parameter user is passed then the module will use the not deprecated method, passing user and token on the body of the requisition. Otherwise the module will use the deprecated method.

Co-authored-by: Lucas <araujo.lucasvale@gmail.com>

Fixes #2002
This commit is contained in:
Lucas Araújo 2020-03-26 08:50:42 -03:00 committed by GitHub
parent 15e79b09d3
commit 15496bfb4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View file

@ -17,6 +17,7 @@ namespace modules {
github_module::github_module(const bar_settings& bar, string name_)
: timer_module<github_module>(bar, move(name_)), m_http(http_util::make_downloader()) {
m_accesstoken = m_conf.get(name(), "token");
m_user = m_conf.get(name(), "user", ""s);
m_api_url = m_conf.get(name(), "api-url", "https://api.github.com/"s);
if (m_api_url.back() != '/') {
m_api_url += '/';
@ -52,7 +53,12 @@ namespace modules {
}
string github_module::request() {
string content{m_http->get(m_api_url + "notifications?access_token=" + m_accesstoken)};
string content;
if (m_user.empty()) {
content = m_http->get(m_api_url + "notifications?access_token=" + m_accesstoken);
} else {
content = m_http->get(m_api_url + "notifications", m_user, m_accesstoken);
}
long response_code{m_http->response_code()};
switch (response_code) {