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

Changed the config and token_store code to use a variable in the config file #11

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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