Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/client/core/authenticator.h" | |
| 6 | |
| 7 namespace blimp { | |
| 8 namespace client { | |
| 9 | |
| 10 // OAuth2 token scope. | |
| 11 const char kOAuth2TokenScope[] = | |
|
nyquist
2016/08/10 01:20:33
This should be in an anonymous namespace.
xingliu
2016/08/10 21:03:14
Done.
| |
| 12 "https://www.googleapis.com/auth/userinfo.email"; | |
| 13 | |
| 14 Authenticator::Authenticator( | |
| 15 std::unique_ptr<IdentityProvider> identity_provider) | |
| 16 : OAuth2TokenService::Consumer("blimp_client"), | |
| 17 identity_provider_(std::move(identity_provider)) { | |
| 18 DCHECK(identity_provider_); | |
| 19 | |
| 20 identity_provider_->AddObserver(this); | |
| 21 } | |
| 22 | |
| 23 Authenticator::~Authenticator() { | |
| 24 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this); | |
| 25 identity_provider_->RemoveObserver(this); | |
| 26 } | |
| 27 | |
| 28 void Authenticator::Connect() { | |
| 29 const std::string& account_id = identity_provider_->GetActiveAccountId(); | |
| 30 | |
| 31 // User must sign in first. | |
| 32 if (account_id.empty()) { | |
| 33 return; | |
|
nyquist
2016/08/10 01:20:33
For now, maybe at least log?
But I'm thinking that
xingliu
2016/08/10 21:03:14
Added VLOG, moved this to delegate's OnError
| |
| 34 } | |
| 35 | |
| 36 account_id_ = account_id; | |
| 37 FetchAuthToken(); | |
| 38 } | |
| 39 | |
| 40 void Authenticator::OnGetTokenSuccess( | |
| 41 const OAuth2TokenService::Request* request, | |
| 42 const std::string& access_token, | |
| 43 const base::Time& expiration_time) { | |
| 44 | |
| 45 token_request_.reset(); | |
| 46 | |
| 47 // TODO(xingliu): Use the token in assignment source. | |
| 48 } | |
| 49 | |
| 50 // Fail to get the token after retries attempts in native layer and Java layer. | |
| 51 void Authenticator::OnGetTokenFailure( | |
| 52 const OAuth2TokenService::Request* request, | |
| 53 const GoogleServiceAuthError& error) { | |
| 54 token_request_.reset(); | |
| 55 | |
| 56 // TODO(xingliu): Alert the user in UI. | |
|
nyquist
2016/08/10 01:20:33
Like above, I think this could call out to the del
xingliu
2016/08/10 21:03:14
Done.
| |
| 57 // There is an known issue that when Android layer fires | |
| 58 // OnRefreshTokenAvailable to listeners, ProfileOAuth2TokenService will | |
| 59 // revoke all refresh tokens, cancel request and bypass the | |
| 60 // retry mechanism in native code and call this function with | |
| 61 // GoogleServiceAuthError.REQUEST_CANCELED. | |
| 62 } | |
| 63 | |
| 64 void Authenticator::OnRefreshTokenAvailable(const std::string& account_id) { | |
|
nyquist
2016/08/10 01:20:33
Is there any requirement to when this is created?
xingliu
2016/08/10 21:03:14
This is added only when no refresh token. If we ha
| |
| 65 if (account_id != account_id_) | |
|
nyquist
2016/08/10 01:20:33
I think we should be consistent about using { or n
xingliu
2016/08/10 21:03:14
Done.
| |
| 66 return; | |
| 67 | |
| 68 identity_provider_->RemoveActiveAccountRefreshTokenObserver(this); | |
| 69 FetchAuthToken(); | |
| 70 } | |
| 71 | |
| 72 void Authenticator::OnActiveAccountLogin() { | |
| 73 } | |
| 74 | |
| 75 void Authenticator::OnActiveAccountLogout() { | |
| 76 } | |
| 77 | |
| 78 void Authenticator::FetchAuthToken() { | |
| 79 OAuth2TokenService* token_service = identity_provider_->GetTokenService(); | |
| 80 DCHECK(token_service); | |
| 81 | |
| 82 if (token_service->RefreshTokenIsAvailable(account_id_)) { | |
| 83 OAuth2TokenService::ScopeSet scopes; | |
| 84 scopes.insert(kOAuth2TokenScope); | |
| 85 token_request_ = token_service->StartRequest( | |
| 86 account_id_, scopes, this); | |
| 87 } else { | |
|
nyquist
2016/08/10 01:20:33
I think something happened to the indent here? You
xingliu
2016/08/10 21:03:14
Oh, that's cool.
| |
| 88 identity_provider_->AddActiveAccountRefreshTokenObserver(this); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 } // namespace client | |
| 93 } // namespace blimp | |
| OLD | NEW |