Commit b560539c authored by kelvinp@chromium.org's avatar kelvinp@chromium.org

Third Party Authentication for Android Part I - TokenFetcherProxy.

This is part I of the effort to support third party authentication for android.

The TokenFetcherProxy is generalized version of the existing PepperTokenFetcher.  It is used by the ThirdPartyClientAuthenticator to fetch auth tokens from both the webapp and the android client.  

BUG=329109

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275386 0039d316-1c4b-4281-b951-d872f2087c98
parent 401afd2f
......@@ -15,6 +15,7 @@
#include "remoting/client/jni/chromoting_jni_runtime.h"
#include "remoting/client/log_to_server.h"
#include "remoting/client/software_video_renderer.h"
#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/jingle_glue/chromium_port_allocator.h"
#include "remoting/jingle_glue/chromium_socket_factory.h"
#include "remoting/jingle_glue/network_settings.h"
......@@ -105,6 +106,15 @@ void ChromotingJniInstance::Cleanup() {
this));
}
void ChromotingJniInstance::FetchThirdPartyToken(
const GURL& token_url,
const std::string& client_id,
const std::string& scope,
base::WeakPtr<TokenFetcherProxy> jni_token_fetcher) {
// TODO(kelvinp) Calls into the jni_runtime_ to obtain a token from the
// android app (Android Third Party Auth - Part II).
}
void ChromotingJniInstance::ProvideSecret(const std::string& pin,
bool create_pairing,
const std::string& device_name) {
......
......@@ -17,6 +17,7 @@
#include "remoting/client/client_user_interface.h"
#include "remoting/client/frame_consumer_proxy.h"
#include "remoting/client/jni/jni_frame_consumer.h"
#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/jingle_glue/xmpp_signal_strategy.h"
#include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/connection_to_host.h"
......@@ -58,6 +59,13 @@ class ChromotingJniInstance
// up. Must be called before destruction.
void Cleanup();
// Requests the android app to fetch a third-party token.
void FetchThirdPartyToken(
const GURL& token_url,
const std::string& client_id,
const std::string& scope,
const base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy);
// Provides the user's PIN and resumes the host authentication attempt. Call
// on the UI thread once the user has finished entering this PIN into the UI,
// but only after the UI has been asked to provide a PIN (via FetchSecret()).
......
......@@ -47,9 +47,9 @@
#include "remoting/client/plugin/pepper_audio_player.h"
#include "remoting/client/plugin/pepper_input_handler.h"
#include "remoting/client/plugin/pepper_port_allocator.h"
#include "remoting/client/plugin/pepper_token_fetcher.h"
#include "remoting/client/plugin/pepper_view.h"
#include "remoting/client/software_video_renderer.h"
#include "remoting/client/token_fetcher_proxy.h"
#include "remoting/protocol/connection_to_host.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/libjingle_transport_factory.h"
......@@ -452,12 +452,12 @@ void ChromotingInstance::FetchThirdPartyToken(
const GURL& token_url,
const std::string& host_public_key,
const std::string& scope,
base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher) {
base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy) {
// Once the Session object calls this function, it won't continue the
// authentication until the callback is called (or connection is canceled).
// So, it's impossible to reach this with a callback already registered.
DCHECK(!pepper_token_fetcher_.get());
pepper_token_fetcher_ = pepper_token_fetcher;
DCHECK(!token_fetcher_proxy_.get());
token_fetcher_proxy_ = token_fetcher_proxy;
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("tokenUrl", token_url.spec());
data->SetString("hostPublicKey", host_public_key);
......@@ -537,7 +537,10 @@ protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() {
scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
ChromotingInstance::GetTokenFetcher(const std::string& host_public_key) {
return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>(
new PepperTokenFetcher(weak_factory_.GetWeakPtr(), host_public_key));
new TokenFetcherProxy(
base::Bind(&ChromotingInstance::FetchThirdPartyToken,
weak_factory_.GetWeakPtr()),
host_public_key));
}
void ChromotingInstance::InjectClipboardEvent(
......@@ -940,9 +943,9 @@ void ChromotingInstance::HandleOnThirdPartyTokenFetched(
LOG(ERROR) << "Invalid onThirdPartyTokenFetched data.";
return;
}
if (pepper_token_fetcher_.get()) {
pepper_token_fetcher_->OnTokenFetched(token, shared_secret);
pepper_token_fetcher_.reset();
if (token_fetcher_proxy_.get()) {
token_fetcher_proxy_->OnTokenFetched(token, shared_secret);
token_fetcher_proxy_.reset();
} else {
LOG(WARNING) << "Ignored OnThirdPartyTokenFetched without a pending fetch.";
}
......
......@@ -61,7 +61,7 @@ class DelegatingSignalStrategy;
class FrameConsumer;
class FrameConsumerProxy;
class PepperAudioPlayer;
class PepperTokenFetcher;
class TokenFetcherProxy;
class PepperView;
class RectangleUpdateDecoder;
class SignalStrategy;
......@@ -178,7 +178,7 @@ class ChromotingInstance :
const GURL& token_url,
const std::string& host_public_key,
const std::string& scope,
const base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher);
const base::WeakPtr<TokenFetcherProxy> pepper_token_fetcher);
private:
FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup);
......@@ -294,7 +294,7 @@ class ChromotingInstance :
// webapp for decoding.
bool use_media_source_rendering_;
base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher_;
base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy_;
// Weak reference to this instance, used for global logging and task posting.
base::WeakPtrFactory<ChromotingInstance> weak_factory_;
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/client/plugin/pepper_token_fetcher.h"
#include "remoting/client/plugin/chromoting_instance.h"
#include "remoting/client/token_fetcher_proxy.h"
namespace remoting {
PepperTokenFetcher::PepperTokenFetcher(base::WeakPtr<ChromotingInstance> plugin,
TokenFetcherProxy::TokenFetcherProxy(
const TokenFetcherCallback& token_fetcher_impl,
const std::string& host_public_key)
: plugin_(plugin),
host_public_key_(host_public_key),
: host_public_key_(host_public_key),
token_fetcher_impl_(token_fetcher_impl),
weak_factory_(this) {
}
PepperTokenFetcher::~PepperTokenFetcher() {
TokenFetcherProxy::~TokenFetcherProxy() {
}
void PepperTokenFetcher::FetchThirdPartyToken(
void TokenFetcherProxy::FetchThirdPartyToken(
const GURL& token_url,
const std::string& scope,
const TokenFetchedCallback& token_fetched_callback) {
if (plugin_.get()) {
token_fetched_callback_ = token_fetched_callback;
plugin_->FetchThirdPartyToken(token_url, host_public_key_, scope,
weak_factory_.GetWeakPtr());
}
token_fetcher_impl_.Run(
token_url, host_public_key_, scope, weak_factory_.GetWeakPtr());
}
void PepperTokenFetcher::OnTokenFetched(
void TokenFetcherProxy::OnTokenFetched(
const std::string& token, const std::string& shared_secret) {
if (!token_fetched_callback_.is_null()) {
token_fetched_callback_.Run(token, shared_secret);
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_
#define REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_
#ifndef REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
#define REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
......@@ -11,14 +11,18 @@
namespace remoting {
class ChromotingInstance;
class PepperTokenFetcher
class TokenFetcherProxy
: public protocol::ThirdPartyClientAuthenticator::TokenFetcher {
public:
PepperTokenFetcher(base::WeakPtr<ChromotingInstance> plugin,
typedef base::Callback<void(
const GURL& token_url,
const std::string& host_public_key,
const std::string& scope,
base::WeakPtr<TokenFetcherProxy>)> TokenFetcherCallback;
TokenFetcherProxy(const TokenFetcherCallback& token_fetcher_impl,
const std::string& host_public_key);
virtual ~PepperTokenFetcher();
virtual ~TokenFetcherProxy();
// protocol::TokenClientAuthenticator::TokenFetcher interface.
virtual void FetchThirdPartyToken(
......@@ -26,19 +30,19 @@ class PepperTokenFetcher
const std::string& scope,
const TokenFetchedCallback& token_fetched_callback) OVERRIDE;
// Called by ChromotingInstance when the webapp finishes fetching the token.
// Called by the token fetching implementation when the token is fetched.
void OnTokenFetched(const std::string& token,
const std::string& shared_secret);
private:
base::WeakPtr<ChromotingInstance> plugin_;
std::string host_public_key_;
TokenFetcherCallback token_fetcher_impl_;
TokenFetchedCallback token_fetched_callback_;
base::WeakPtrFactory<PepperTokenFetcher> weak_factory_;
base::WeakPtrFactory<TokenFetcherProxy> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PepperTokenFetcher);
DISALLOW_COPY_AND_ASSIGN(TokenFetcherProxy);
};
} // namespace remoting
#endif // REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_
#endif // REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
......@@ -218,6 +218,8 @@
'client/server_log_entry_client.h',
'client/software_video_renderer.cc',
'client/software_video_renderer.h',
'client/token_fetcher_proxy.cc',
'client/token_fetcher_proxy.h',
'client/video_renderer.h',
],
......@@ -244,8 +246,6 @@
'client/plugin/pepper_plugin_thread_delegate.h',
'client/plugin/pepper_port_allocator.cc',
'client/plugin/pepper_port_allocator.h',
'client/plugin/pepper_token_fetcher.cc',
'client/plugin/pepper_token_fetcher.h',
'client/plugin/pepper_util.cc',
'client/plugin/pepper_util.h',
'client/plugin/pepper_view.cc',
......
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