OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_ | 5 #ifndef GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_ |
6 #define GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_ | 6 #define GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 class GURL; | 12 class GURL; |
13 | 13 |
14 namespace gaia { | 14 namespace gaia { |
15 | 15 |
| 16 struct ListedAccount { |
| 17 // The account's ID, as per Chrome, will be determined in the |
| 18 // CookieManagerService. |
| 19 std::string id; |
| 20 std::string email; |
| 21 std::string gaia_id; |
| 22 std::string raw_email; |
| 23 bool valid; |
| 24 |
| 25 ListedAccount(); |
| 26 ~ListedAccount(); |
| 27 bool operator==(const ListedAccount& other) const; |
| 28 }; |
| 29 |
16 // Perform basic canonicalization of |email_address|, taking into account that | 30 // Perform basic canonicalization of |email_address|, taking into account that |
17 // gmail does not consider '.' or caps inside a username to matter. | 31 // gmail does not consider '.' or caps inside a username to matter. |
18 std::string CanonicalizeEmail(const std::string& email_address); | 32 std::string CanonicalizeEmail(const std::string& email_address); |
19 | 33 |
20 // Returns the canonical form of the given domain. | 34 // Returns the canonical form of the given domain. |
21 std::string CanonicalizeDomain(const std::string& domain); | 35 std::string CanonicalizeDomain(const std::string& domain); |
22 | 36 |
23 // Sanitize emails. Currently, it only ensures all emails have a domain by | 37 // Sanitize emails. Currently, it only ensures all emails have a domain by |
24 // adding gmail.com if no domain is present. | 38 // adding gmail.com if no domain is present. |
25 std::string SanitizeEmail(const std::string& email_address); | 39 std::string SanitizeEmail(const std::string& email_address); |
26 | 40 |
27 // Returns true if the two specified email addresses are the same. Both | 41 // Returns true if the two specified email addresses are the same. Both |
28 // addresses are first sanitized and then canonicalized before comparing. | 42 // addresses are first sanitized and then canonicalized before comparing. |
29 bool AreEmailsSame(const std::string& email1, const std::string& email2); | 43 bool AreEmailsSame(const std::string& email1, const std::string& email2); |
30 | 44 |
31 // Extract the domain part from the canonical form of the given email. | 45 // Extract the domain part from the canonical form of the given email. |
32 std::string ExtractDomainName(const std::string& email); | 46 std::string ExtractDomainName(const std::string& email); |
33 | 47 |
34 bool IsGaiaSignonRealm(const GURL& url); | 48 bool IsGaiaSignonRealm(const GURL& url); |
35 | 49 |
36 // Parses JSON data returned by /ListAccounts call, returning a vector of | 50 // Parses JSON data returned by /ListAccounts call, returning a vector of |
37 // email/valid pairs. An email addresses is considered valid if a passive | 51 // email/valid pairs. An email addresses is considered valid if a passive |
38 // login would succeed (i.e. the user does not need to reauthenticate). | 52 // login would succeed (i.e. the user does not need to reauthenticate). |
39 // If there an error parsing the JSON, then false is returned. | 53 // If there an error parsing the JSON, then false is returned. |
40 bool ParseListAccountsData( | 54 bool ParseListAccountsData( |
41 const std::string& data, | 55 const std::string& data, std::vector<ListedAccount>* accounts); |
42 std::vector<std::pair<std::string, bool> >* accounts); | |
43 | 56 |
44 } // namespace gaia | 57 } // namespace gaia |
45 | 58 |
46 #endif // GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_ | 59 #endif // GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_ |
OLD | NEW |