| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2009 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 // The authenticator is a cross-platform class that handles authentication for | |
| 6 // the sync client. | |
| 7 // | |
| 8 // Current State: | |
| 9 // The authenticator is currently only used to authenticate tokens using the | |
| 10 // newer protocol buffer request. | |
| 11 | |
| 12 #ifndef CHROME_BROWSER_SYNC_ENGINE_AUTHENTICATOR_H_ | |
| 13 #define CHROME_BROWSER_SYNC_ENGINE_AUTHENTICATOR_H_ | |
| 14 #pragma once | |
| 15 | |
| 16 #include <string> | |
| 17 | |
| 18 #include "base/basictypes.h" | |
| 19 #include "base/port.h" | |
| 20 | |
| 21 namespace sync_pb { | |
| 22 class UserIdentification; | |
| 23 } | |
| 24 | |
| 25 namespace browser_sync { | |
| 26 | |
| 27 class ServerConnectionManager; | |
| 28 class UserSettings; | |
| 29 | |
| 30 class Authenticator { | |
| 31 public: | |
| 32 // Single return enum. | |
| 33 enum AuthenticationResult { | |
| 34 SUCCESS = 0, | |
| 35 // We couldn't log on because we don't have saved credentials. | |
| 36 NO_SAVED_CREDENTIALS, | |
| 37 // We can't reach auth server (i.e. we're offline or server's down). | |
| 38 NOT_CONNECTED, | |
| 39 // Server's up, but we're down. | |
| 40 SERVICE_DOWN, | |
| 41 // We contacted the server, but the response didn't make sense. | |
| 42 CORRUPT_SERVER_RESPONSE, | |
| 43 // Bad username/password. | |
| 44 BAD_CREDENTIALS, | |
| 45 // Credentials are fine, but the user hasn't signed up. | |
| 46 USER_NOT_ACTIVATED, | |
| 47 | |
| 48 // Return values for internal use. | |
| 49 | |
| 50 // We will never return this to the user unless they call AuthenticateToken | |
| 51 // directly. Other auth functions retry and then return | |
| 52 // CORRUPT_SERVER_RESPONSE. | |
| 53 // TODO(sync): Implement retries. | |
| 54 BAD_AUTH_TOKEN, | |
| 55 // We should never return this, it's a placeholder during development. | |
| 56 // TODO(sync): Remove this | |
| 57 UNSPECIFIC_ERROR_RETURN, | |
| 58 }; | |
| 59 | |
| 60 // Constructor. This class will keep the connection authenticated. | |
| 61 // TODO(sync): Make it work as described. | |
| 62 // TODO(sync): Require a UI callback mechanism. | |
| 63 Authenticator(ServerConnectionManager* manager, UserSettings* settings); | |
| 64 | |
| 65 // Constructor for a simple authenticator used for programmatic login from | |
| 66 // test programs. | |
| 67 explicit Authenticator(ServerConnectionManager* manager); | |
| 68 | |
| 69 // This version of Authenticate tries to use saved credentials, if we have | |
| 70 // any. | |
| 71 AuthenticationResult Authenticate(); | |
| 72 | |
| 73 // We save the username and password in memory (if given) so we | |
| 74 // can refresh the long-lived auth token if it expires. | |
| 75 // Also we save a 10-bit hash of the password to allow offline login. | |
| 76 AuthenticationResult Authenticate(std::string username, std::string password); | |
| 77 | |
| 78 // A version of the auth token to authenticate cookie portion of | |
| 79 // authentication. It uses the new proto buffer based call instead of the HTTP | |
| 80 // GET based one we currently use. | |
| 81 // Can return one of SUCCESS, SERVICE_DOWN, CORRUPT_SERVER_RESPONSE, | |
| 82 // USER_NOT_ACTIVATED or BAD_AUTH_TOKEN. See above for the meaning of these | |
| 83 // values. | |
| 84 // TODO(sync): Make this function private when we're done. | |
| 85 AuthenticationResult AuthenticateToken(std::string auth_token); | |
| 86 | |
| 87 const char* display_email() const { return display_email_.c_str(); } | |
| 88 const char* display_name() const { return display_name_.c_str(); } | |
| 89 private: | |
| 90 // Stores the information in the UserIdentification returned from the server. | |
| 91 AuthenticationResult HandleSuccessfulTokenRequest( | |
| 92 const sync_pb::UserIdentification* user); | |
| 93 // The server connection manager that we're looking after. | |
| 94 ServerConnectionManager* server_connection_manager_; | |
| 95 // Returns SUCCESS or the value that should be returned to the user. | |
| 96 std::string display_email_; | |
| 97 std::string display_name_; | |
| 98 std::string obfuscated_id_; | |
| 99 UserSettings* const settings_; | |
| 100 DISALLOW_COPY_AND_ASSIGN(Authenticator); | |
| 101 }; | |
| 102 | |
| 103 } // namespace browser_sync | |
| 104 | |
| 105 #endif // CHROME_BROWSER_SYNC_ENGINE_AUTHENTICATOR_H_ | |
| OLD | NEW |