1c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_ 6c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_ 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <string> 9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "google_apis/gaia/gaia_auth_consumer.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "google_apis/gaia/gaia_auth_fetcher.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Retrieves the OAuth2 information from an already signed in cookie jar. 15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// The information retrieved is: username, refresh token. 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class SigninOAuthHelper : public GaiaAuthConsumer { 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Implemented by users of SigninOAuthHelper to know then helper is finished. 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) class Consumer { 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual ~Consumer() {} 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Called when all the information is retrieved successfully. |email| 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // and |display_email| correspond to the gaia properties called "email" 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // and "displayEmail" associated with the signed in account. |refresh_token| 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // is the account's login-scoped oauth2 refresh token. 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void OnSigninOAuthInformationAvailable( 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string& email, 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string& display_email, 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string& refresh_token) {} 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Called when an error occurs while getting the information. 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void OnSigninOAuthInformationFailure( 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const GoogleServiceAuthError& error) {} 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) }; 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) explicit SigninOAuthHelper(net::URLRequestContextGetter* getter, 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string& session_index, 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const std::string& signin_scoped_device_id, 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Consumer* consumer); 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~SigninOAuthHelper(); 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private: 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Overridden from GaiaAuthConsumer. 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) OVERRIDE; 46c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual void OnClientOAuthFailure(const GoogleServiceAuthError& error) 47c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OVERRIDE; 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; 49c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual void OnClientLoginFailure(const GoogleServiceAuthError& error) 50c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OVERRIDE; 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE; 52c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error) 53c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OVERRIDE; 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GaiaAuthFetcher gaia_auth_fetcher_; 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string refresh_token_; 57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Consumer* consumer_; 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SigninOAuthHelper); 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 62c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_OAUTH_HELPER_H_ 63