Skip to content

Commit

Permalink
Merge pull request #11 from tparkercbn/master
Browse files Browse the repository at this point in the history
Changed the config and token_store code to use a variable in the config file
  • Loading branch information
tarickb authored Nov 23, 2020
2 parents 5d74916 + ee79a87 commit a564e10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ int Config::Init(const Json::Value &root) {
&log_full_trace_on_failure_);
if (err != SASL_OK) return err;

err = Fetch(root, "token_endpoint", true, &token_endpoint_);
if (err != SASL_OK) return err;

return 0;

} catch (const std::exception &e) {
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Config {
std::string client_secret() const { return client_secret_; }
bool log_to_syslog_on_failure() const { return log_to_syslog_on_failure_; }
bool log_full_trace_on_failure() const { return log_full_trace_on_failure_; }
std::string token_endpoint() const { return token_endpoint_; }

private:
Config() = default;
Expand All @@ -43,6 +44,7 @@ class Config {
std::string client_secret_;
bool log_to_syslog_on_failure_ = true;
bool log_full_trace_on_failure_ = false;
std::string token_endpoint_ = "https://accounts.google.com/o/oauth2/token";
};

} // namespace sasl_xoauth2
Expand Down
5 changes: 2 additions & 3 deletions src/token_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace {
constexpr int kMaxRefreshAttempts = 2;
constexpr int kExpiryMarginSec = 10;

constexpr char kTokenEndpoint[] = "https://accounts.google.com/o/oauth2/token";

std::string GetTempSuffix() {
timeval t = {};
gettimeofday(&t, nullptr);
Expand Down Expand Up @@ -85,11 +83,12 @@ int TokenStore::Refresh() {
"&grant_type=refresh_token&refresh_token=" + refresh_;
std::string response;
long response_code = 0;
log_->Write("TokenStore::Refresh: token_endpoint: %s", Config::Get()->token_endpoint().c_str());
log_->Write("TokenStore::Refresh: request: %s", request.c_str());

std::string http_error;
int err =
HttpPost(kTokenEndpoint, request, &response_code, &response, &http_error);
HttpPost(Config::Get()->token_endpoint(), request, &response_code, &response, &http_error);
if (err != SASL_OK) {
log_->Write("TokenStore::Refresh: http error: %s", http_error.c_str());
return err;
Expand Down

0 comments on commit a564e10

Please sign in to comment.