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 @@ ...@@ -15,6 +15,7 @@
#include "remoting/client/jni/chromoting_jni_runtime.h" #include "remoting/client/jni/chromoting_jni_runtime.h"
#include "remoting/client/log_to_server.h" #include "remoting/client/log_to_server.h"
#include "remoting/client/software_video_renderer.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_port_allocator.h"
#include "remoting/jingle_glue/chromium_socket_factory.h" #include "remoting/jingle_glue/chromium_socket_factory.h"
#include "remoting/jingle_glue/network_settings.h" #include "remoting/jingle_glue/network_settings.h"
...@@ -105,6 +106,15 @@ void ChromotingJniInstance::Cleanup() { ...@@ -105,6 +106,15 @@ void ChromotingJniInstance::Cleanup() {
this)); 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, void ChromotingJniInstance::ProvideSecret(const std::string& pin,
bool create_pairing, bool create_pairing,
const std::string& device_name) { const std::string& device_name) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "remoting/client/client_user_interface.h" #include "remoting/client/client_user_interface.h"
#include "remoting/client/frame_consumer_proxy.h" #include "remoting/client/frame_consumer_proxy.h"
#include "remoting/client/jni/jni_frame_consumer.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/jingle_glue/xmpp_signal_strategy.h"
#include "remoting/protocol/clipboard_stub.h" #include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/connection_to_host.h" #include "remoting/protocol/connection_to_host.h"
...@@ -58,6 +59,13 @@ class ChromotingJniInstance ...@@ -58,6 +59,13 @@ class ChromotingJniInstance
// up. Must be called before destruction. // up. Must be called before destruction.
void Cleanup(); 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 // 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, // 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()). // but only after the UI has been asked to provide a PIN (via FetchSecret()).
......
...@@ -47,9 +47,9 @@ ...@@ -47,9 +47,9 @@
#include "remoting/client/plugin/pepper_audio_player.h" #include "remoting/client/plugin/pepper_audio_player.h"
#include "remoting/client/plugin/pepper_input_handler.h" #include "remoting/client/plugin/pepper_input_handler.h"
#include "remoting/client/plugin/pepper_port_allocator.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/plugin/pepper_view.h"
#include "remoting/client/software_video_renderer.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/connection_to_host.h"
#include "remoting/protocol/host_stub.h" #include "remoting/protocol/host_stub.h"
#include "remoting/protocol/libjingle_transport_factory.h" #include "remoting/protocol/libjingle_transport_factory.h"
...@@ -452,12 +452,12 @@ void ChromotingInstance::FetchThirdPartyToken( ...@@ -452,12 +452,12 @@ void ChromotingInstance::FetchThirdPartyToken(
const GURL& token_url, const GURL& token_url,
const std::string& host_public_key, const std::string& host_public_key,
const std::string& scope, 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 // Once the Session object calls this function, it won't continue the
// authentication until the callback is called (or connection is canceled). // authentication until the callback is called (or connection is canceled).
// So, it's impossible to reach this with a callback already registered. // So, it's impossible to reach this with a callback already registered.
DCHECK(!pepper_token_fetcher_.get()); DCHECK(!token_fetcher_proxy_.get());
pepper_token_fetcher_ = pepper_token_fetcher; token_fetcher_proxy_ = token_fetcher_proxy;
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
data->SetString("tokenUrl", token_url.spec()); data->SetString("tokenUrl", token_url.spec());
data->SetString("hostPublicKey", host_public_key); data->SetString("hostPublicKey", host_public_key);
...@@ -537,7 +537,10 @@ protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() { ...@@ -537,7 +537,10 @@ protocol::CursorShapeStub* ChromotingInstance::GetCursorShapeStub() {
scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
ChromotingInstance::GetTokenFetcher(const std::string& host_public_key) { ChromotingInstance::GetTokenFetcher(const std::string& host_public_key) {
return scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>( 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( void ChromotingInstance::InjectClipboardEvent(
...@@ -940,9 +943,9 @@ void ChromotingInstance::HandleOnThirdPartyTokenFetched( ...@@ -940,9 +943,9 @@ void ChromotingInstance::HandleOnThirdPartyTokenFetched(
LOG(ERROR) << "Invalid onThirdPartyTokenFetched data."; LOG(ERROR) << "Invalid onThirdPartyTokenFetched data.";
return; return;
} }
if (pepper_token_fetcher_.get()) { if (token_fetcher_proxy_.get()) {
pepper_token_fetcher_->OnTokenFetched(token, shared_secret); token_fetcher_proxy_->OnTokenFetched(token, shared_secret);
pepper_token_fetcher_.reset(); token_fetcher_proxy_.reset();
} else { } else {
LOG(WARNING) << "Ignored OnThirdPartyTokenFetched without a pending fetch."; LOG(WARNING) << "Ignored OnThirdPartyTokenFetched without a pending fetch.";
} }
......
...@@ -61,7 +61,7 @@ class DelegatingSignalStrategy; ...@@ -61,7 +61,7 @@ class DelegatingSignalStrategy;
class FrameConsumer; class FrameConsumer;
class FrameConsumerProxy; class FrameConsumerProxy;
class PepperAudioPlayer; class PepperAudioPlayer;
class PepperTokenFetcher; class TokenFetcherProxy;
class PepperView; class PepperView;
class RectangleUpdateDecoder; class RectangleUpdateDecoder;
class SignalStrategy; class SignalStrategy;
...@@ -178,7 +178,7 @@ class ChromotingInstance : ...@@ -178,7 +178,7 @@ class ChromotingInstance :
const GURL& token_url, const GURL& token_url,
const std::string& host_public_key, const std::string& host_public_key,
const std::string& scope, const std::string& scope,
const base::WeakPtr<PepperTokenFetcher> pepper_token_fetcher); const base::WeakPtr<TokenFetcherProxy> pepper_token_fetcher);
private: private:
FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup); FRIEND_TEST_ALL_PREFIXES(ChromotingInstanceTest, TestCaseSetup);
...@@ -294,7 +294,7 @@ class ChromotingInstance : ...@@ -294,7 +294,7 @@ class ChromotingInstance :
// webapp for decoding. // webapp for decoding.
bool use_media_source_rendering_; 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. // Weak reference to this instance, used for global logging and task posting.
base::WeakPtrFactory<ChromotingInstance> weak_factory_; 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "remoting/client/plugin/pepper_token_fetcher.h" #include "remoting/client/token_fetcher_proxy.h"
#include "remoting/client/plugin/chromoting_instance.h"
namespace remoting { namespace remoting {
PepperTokenFetcher::PepperTokenFetcher(base::WeakPtr<ChromotingInstance> plugin, TokenFetcherProxy::TokenFetcherProxy(
const std::string& host_public_key) const TokenFetcherCallback& token_fetcher_impl,
: plugin_(plugin), const std::string& host_public_key)
host_public_key_(host_public_key), : host_public_key_(host_public_key),
token_fetcher_impl_(token_fetcher_impl),
weak_factory_(this) { weak_factory_(this) {
} }
PepperTokenFetcher::~PepperTokenFetcher() { TokenFetcherProxy::~TokenFetcherProxy() {
} }
void PepperTokenFetcher::FetchThirdPartyToken( void TokenFetcherProxy::FetchThirdPartyToken(
const GURL& token_url, const GURL& token_url,
const std::string& scope, const std::string& scope,
const TokenFetchedCallback& token_fetched_callback) { const TokenFetchedCallback& token_fetched_callback) {
if (plugin_.get()) { token_fetched_callback_ = token_fetched_callback;
token_fetched_callback_ = token_fetched_callback; token_fetcher_impl_.Run(
plugin_->FetchThirdPartyToken(token_url, host_public_key_, scope, token_url, host_public_key_, scope, weak_factory_.GetWeakPtr());
weak_factory_.GetWeakPtr());
}
} }
void PepperTokenFetcher::OnTokenFetched( void TokenFetcherProxy::OnTokenFetched(
const std::string& token, const std::string& shared_secret) { const std::string& token, const std::string& shared_secret) {
if (!token_fetched_callback_.is_null()) { if (!token_fetched_callback_.is_null()) {
token_fetched_callback_.Run(token, shared_secret); 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_ #ifndef REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
#define REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_ #define REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -11,14 +11,18 @@ ...@@ -11,14 +11,18 @@
namespace remoting { namespace remoting {
class ChromotingInstance; class TokenFetcherProxy
class PepperTokenFetcher
: public protocol::ThirdPartyClientAuthenticator::TokenFetcher { : public protocol::ThirdPartyClientAuthenticator::TokenFetcher {
public: public:
PepperTokenFetcher(base::WeakPtr<ChromotingInstance> plugin, typedef base::Callback<void(
const std::string& host_public_key); const GURL& token_url,
virtual ~PepperTokenFetcher(); 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 ~TokenFetcherProxy();
// protocol::TokenClientAuthenticator::TokenFetcher interface. // protocol::TokenClientAuthenticator::TokenFetcher interface.
virtual void FetchThirdPartyToken( virtual void FetchThirdPartyToken(
...@@ -26,19 +30,19 @@ class PepperTokenFetcher ...@@ -26,19 +30,19 @@ class PepperTokenFetcher
const std::string& scope, const std::string& scope,
const TokenFetchedCallback& token_fetched_callback) OVERRIDE; 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, void OnTokenFetched(const std::string& token,
const std::string& shared_secret); const std::string& shared_secret);
private: private:
base::WeakPtr<ChromotingInstance> plugin_;
std::string host_public_key_; std::string host_public_key_;
TokenFetcherCallback token_fetcher_impl_;
TokenFetchedCallback token_fetched_callback_; 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 } // namespace remoting
#endif // REMOTING_CLIENT_PLUGIN_PEPPER_TOKEN_FETCHER_H_ #endif // REMOTING_CLIENT_TOKEN_FETCHER_PROXY_H_
...@@ -218,6 +218,8 @@ ...@@ -218,6 +218,8 @@
'client/server_log_entry_client.h', 'client/server_log_entry_client.h',
'client/software_video_renderer.cc', 'client/software_video_renderer.cc',
'client/software_video_renderer.h', 'client/software_video_renderer.h',
'client/token_fetcher_proxy.cc',
'client/token_fetcher_proxy.h',
'client/video_renderer.h', 'client/video_renderer.h',
], ],
...@@ -244,8 +246,6 @@ ...@@ -244,8 +246,6 @@
'client/plugin/pepper_plugin_thread_delegate.h', 'client/plugin/pepper_plugin_thread_delegate.h',
'client/plugin/pepper_port_allocator.cc', 'client/plugin/pepper_port_allocator.cc',
'client/plugin/pepper_port_allocator.h', '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.cc',
'client/plugin/pepper_util.h', 'client/plugin/pepper_util.h',
'client/plugin/pepper_view.cc', '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