Commit dce8e645 authored by ckehoe's avatar ckehoe Committed by Commit bot

Scoping auth tokens by app

BUG=431868

Review URL: https://codereview.chromium.org/800613002

Cr-Commit-Position: refs/heads/master@{#308043}
parent a22536b2
......@@ -58,14 +58,23 @@ copresence::WhispernetClient* CopresenceService::whispernet_client() {
return whispernet_client_.get();
}
const std::string CopresenceService::auth_token(const std::string& app_id)
const {
// This won't be const if we use map[]
const auto& key = auth_tokens_by_app_.find(app_id);
return key == auth_tokens_by_app_.end() ? std::string() : key->second;
}
void CopresenceService::set_api_key(const std::string& app_id,
const std::string& api_key) {
DCHECK(!app_id.empty());
api_keys_by_app_[app_id] = api_key;
}
void CopresenceService::set_auth_token(const std::string& token) {
auth_token_ = token;
void CopresenceService::set_auth_token(const std::string& app_id,
const std::string& token) {
DCHECK(!app_id.empty());
auth_tokens_by_app_[app_id] = token;
}
void CopresenceService::set_manager_for_testing(
......@@ -184,7 +193,7 @@ ExtensionFunction::ResponseAction CopresenceExecuteFunction::Run() {
service->manager()->ExecuteReportRequest(
request,
extension_id(),
service->auth_token(),
service->auth_token(extension_id()),
base::Bind(&CopresenceExecuteFunction::SendResult, this));
return RespondLater();
}
......@@ -216,9 +225,8 @@ ExtensionFunction::ResponseAction CopresenceSetAuthTokenFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(params.get());
// The token may be set to empty, to clear it.
// TODO(ckehoe): Scope the auth token appropriately (crbug/423517).
CopresenceService::GetFactoryInstance()->Get(browser_context())
->set_auth_token(params->token);
->set_auth_token(extension_id(), params->token);
return RespondNow(NoArguments());
}
......
......@@ -49,14 +49,13 @@ class CopresenceService final : public BrowserContextKeyedAPI,
return apps_by_subscription_id_;
}
const std::string auth_token(const std::string& app_id) const;
void set_api_key(const std::string& app_id,
const std::string& api_key);
std::string auth_token() const {
return auth_token_;
}
void set_auth_token(const std::string& token);
void set_auth_token(const std::string& app_id,
const std::string& token);
// Manager override for testing.
void set_manager_for_testing(
......@@ -83,14 +82,12 @@ class CopresenceService final : public BrowserContextKeyedAPI,
static const char* service_name() { return "CopresenceService"; }
bool is_shutting_down_;
content::BrowserContext* const browser_context_;
std::map<std::string, std::string> apps_by_subscription_id_;
content::BrowserContext* const browser_context_;
std::map<std::string, std::string> api_keys_by_app_;
// TODO(ckehoe): This is a temporary hack.
// Auth tokens from different apps needs to be separated properly.
std::string auth_token_;
std::map<std::string, std::string> auth_tokens_by_app_;
scoped_ptr<copresence::CopresenceManager> manager_;
scoped_ptr<ChromeWhispernetClient> whispernet_client_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment