1 // Copyright 2014 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.
5 #include "chromeos/login/auth/user_context.h"
6 #include "chromeos/login/user_names.h"
10 UserContext::UserContext()
11 : is_using_oauth_(true),
12 auth_flow_(AUTH_FLOW_OFFLINE
),
13 user_type_(user_manager::USER_TYPE_REGULAR
) {
16 UserContext::UserContext(const UserContext
& other
)
17 : user_id_(other
.user_id_
),
18 gaia_id_(other
.gaia_id_
),
20 auth_code_(other
.auth_code_
),
21 refresh_token_(other
.refresh_token_
),
22 access_token_(other
.access_token_
),
23 user_id_hash_(other
.user_id_hash_
),
24 is_using_oauth_(other
.is_using_oauth_
),
25 auth_flow_(other
.auth_flow_
),
26 user_type_(other
.user_type_
),
27 public_session_locale_(other
.public_session_locale_
),
28 public_session_input_method_(other
.public_session_input_method_
),
29 device_id_(other
.device_id_
),
30 gaps_cookie_(other
.gaps_cookie_
) {
33 UserContext::UserContext(const std::string
& user_id
)
34 : user_id_(login::CanonicalizeUserID(user_id
)),
35 is_using_oauth_(true),
36 auth_flow_(AUTH_FLOW_OFFLINE
),
37 user_type_(user_manager::USER_TYPE_REGULAR
) {
40 UserContext::UserContext(user_manager::UserType user_type
,
41 const std::string
& user_id
)
42 : is_using_oauth_(true),
43 auth_flow_(AUTH_FLOW_OFFLINE
),
44 user_type_(user_type
) {
45 if (user_type_
== user_manager::USER_TYPE_REGULAR
)
46 user_id_
= login::CanonicalizeUserID(user_id
);
51 UserContext::~UserContext() {
54 bool UserContext::operator==(const UserContext
& context
) const {
55 return context
.user_id_
== user_id_
&& context
.gaia_id_
== gaia_id_
&&
56 context
.key_
== key_
&& context
.auth_code_
== auth_code_
&&
57 context
.refresh_token_
== refresh_token_
&&
58 context
.access_token_
== access_token_
&&
59 context
.user_id_hash_
== user_id_hash_
&&
60 context
.is_using_oauth_
== is_using_oauth_
&&
61 context
.auth_flow_
== auth_flow_
&& context
.user_type_
== user_type_
&&
62 context
.public_session_locale_
== public_session_locale_
&&
63 context
.public_session_input_method_
== public_session_input_method_
;
66 bool UserContext::operator!=(const UserContext
& context
) const {
67 return !(*this == context
);
70 const std::string
& UserContext::GetUserID() const {
74 const std::string
& UserContext::GetGaiaID() const {
78 const Key
* UserContext::GetKey() const {
82 Key
* UserContext::GetKey() {
86 const std::string
& UserContext::GetAuthCode() const {
90 const std::string
& UserContext::GetRefreshToken() const {
91 return refresh_token_
;
94 const std::string
& UserContext::GetAccessToken() const {
98 const std::string
& UserContext::GetUserIDHash() const {
102 bool UserContext::IsUsingOAuth() const {
103 return is_using_oauth_
;
106 UserContext::AuthFlow
UserContext::GetAuthFlow() const {
110 user_manager::UserType
UserContext::GetUserType() const {
114 const std::string
& UserContext::GetPublicSessionLocale() const {
115 return public_session_locale_
;
118 const std::string
& UserContext::GetPublicSessionInputMethod() const {
119 return public_session_input_method_
;
122 const std::string
& UserContext::GetDeviceId() const {
126 const std::string
& UserContext::GetGAPSCookie() const {
130 bool UserContext::HasCredentials() const {
131 return (!user_id_
.empty() && !key_
.GetSecret().empty()) ||
135 void UserContext::SetUserID(const std::string
& user_id
) {
136 user_id_
= login::CanonicalizeUserID(user_id
);
139 void UserContext::SetGaiaID(const std::string
& gaia_id
) {
143 void UserContext::SetKey(const Key
& key
) {
147 void UserContext::SetAuthCode(const std::string
& auth_code
) {
148 auth_code_
= auth_code
;
151 void UserContext::SetRefreshToken(const std::string
& refresh_token
) {
152 refresh_token_
= refresh_token
;
155 void UserContext::SetAccessToken(const std::string
& access_token
) {
156 access_token_
= access_token
;
159 void UserContext::SetUserIDHash(const std::string
& user_id_hash
) {
160 user_id_hash_
= user_id_hash
;
163 void UserContext::SetIsUsingOAuth(bool is_using_oauth
) {
164 is_using_oauth_
= is_using_oauth
;
167 void UserContext::SetAuthFlow(AuthFlow auth_flow
) {
168 auth_flow_
= auth_flow
;
171 void UserContext::SetUserType(user_manager::UserType user_type
) {
172 user_type_
= user_type
;
175 void UserContext::SetPublicSessionLocale(const std::string
& locale
) {
176 public_session_locale_
= locale
;
179 void UserContext::SetPublicSessionInputMethod(const std::string
& input_method
) {
180 public_session_input_method_
= input_method
;
183 void UserContext::SetDeviceId(const std::string
& device_id
) {
184 device_id_
= device_id
;
187 void UserContext::SetGAPSCookie(const std::string
& gaps_cookie
) {
188 gaps_cookie_
= gaps_cookie
;
191 void UserContext::ClearSecrets() {
194 refresh_token_
.clear();
197 } // namespace chromeos