1 /* ****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #ifndef OC_ACCOUNT_MANAGER_H_
22 #define OC_ACCOUNT_MANAGER_H_
27 #include <IClientWrapper.h>
28 #include <InProcClientWrapper.h>
32 class OCAccountManager
34 friend class OCPlatform_impl;
37 typedef std::shared_ptr<OCAccountManager> Ptr;
39 OCAccountManager(OCAccountManager&&) = default;
40 OCAccountManager(const OCAccountManager&) = delete;
41 OCAccountManager& operator=(OCAccountManager&&) = delete;
42 OCAccountManager& operator=(const OCAccountManager&) = delete;
44 virtual ~OCAccountManager(void);
47 * Function to get the host address of account server
49 * @return std::string host address
51 std::string host() const;
54 * Function to get the connectivity type for account server
56 * @return enum connectivity type (flags and adapter)
58 OCConnectivityType connectivityType() const;
61 * Function for account registration to account server
63 * @param authProvider Provider name used for authentication.
64 * @param authCode The authorization code obtained by using an authorization server
65 * as an intermediary between the client and resource owner.
66 * @param cloudConnectHandler Callback function that will get the result of the operation.
68 * @return Returns ::OC_STACK_OK if success
70 OCStackResult signUp(const std::string& authProvider,
71 const std::string& authCode,
72 PostCallback cloudConnectHandler);
77 * @param authProvider Provider name used for authentication.
78 * @param authCode The authorization code obtained by using an authorization server
79 * as an intermediary between the client and resource owner.
80 * @param options The option values depends on auth provider.
81 * @param cloudConnectHandler Callback function that will get the result of the operation.
83 * @return Returns ::OC_STACK_OK if success
85 OCStackResult signUp(const std::string& authProvider,
86 const std::string& authCode,
87 const QueryParamsMap& options,
88 PostCallback cloudConnectHandler);
91 * Function for sign-in to account server
93 * @param userUuid Identifier of the user obtained by account registration.
94 * @param accessToken Identifier of the resource obtained by account registration.
95 * @param cloudConnectHandler Callback function that will get the result of the operation.
97 * @return Returns ::OC_STACK_OK if success
99 OCStackResult signIn(const std::string& userUuid,
100 const std::string& accessToken,
101 PostCallback cloudConnectHandler);
104 * Function for sign-out to account server
106 * @param cloudConnectHandler Callback function that will get the result of the operation.
108 * @return Returns ::OC_STACK_OK if success
110 OCStackResult signOut(PostCallback cloudConnectHandler);
113 * Function for refresh access token to account server
115 * @param userUuid Identifier of the user obtained by account registration.
116 * @param refreshToken Refresh token used for access token refresh.
117 * @param cloudConnectHandler Callback function that will get the result of the operation.
119 * @return Returns ::OC_STACK_OK if success
121 OCStackResult refreshAccessToken(const std::string& userUuid,
122 const std::string& refreshToken,
123 PostCallback cloudConnectHandler);
126 * Function to get information of the user to account server
128 * @param userUuid Identifier of the user to get information.
129 * @param cloudConnectHandler Callback function that will get the result of the operation.
131 * @return Returns ::OC_STACK_OK if success
133 OCStackResult searchUser(const std::string& userUuid,
134 GetCallback cloudConnectHandler);
139 * @param queryParams Map which can have the query key and value for specific users.
140 * account server can response information of more than one user.
141 * @param cloudConnectHandler Callback function that will get the result of the operation.
143 * @return Returns ::OC_STACK_OK if success
145 OCStackResult searchUser(const QueryParamsMap& queryParams,
146 GetCallback cloudConnectHandler);
149 * Function to delete the device registered on the account signed-in
151 * @param deviceId Device ID to delete.
152 * @param cloudConnectHandler Callback function that will get the result of the operation.
154 * @return Returns ::OC_STACK_OK if success
156 OCStackResult deleteDevice(const std::string& deviceId,
157 DeleteCallback cloudConnectHandler);
160 * Function to create a group on account server
162 * @param groupType Group type that can be used for referencing default group ACL creation.
163 * @param cloudConnectHandler Callback function that will get the result of the operation.
165 * @return Returns ::OC_STACK_OK if success
167 OCStackResult createGroup(AclGroupType groupType,
168 PostCallback cloudConnectHandler);
171 * Function to get a list of groups joined from account server
173 * @param cloudConnectHandler Callback function that will get the result of the operation.
175 * @return Returns ::OC_STACK_OK if success
177 OCStackResult getGroupList(GetCallback cloudConnectHandler);
180 * Function to delete the group from account server
182 * @param groupId Group ID to delete.
183 * @param cloudConnectHandler Callback function that will get the result of the operation.
185 * @return Returns ::OC_STACK_OK if success
187 OCStackResult deleteGroup(const std::string& groupId,
188 DeleteCallback cloudConnectHandler);
191 * Function to join the group on account server
193 * @param groupId Group ID to join
194 * @param cloudConnectHandler Callback function that will get the result of the operation.
196 * @return Returns ::OC_STACK_OK if success
198 OCStackResult joinGroup(const std::string& groupId,
199 PostCallback cloudConnectHandler);
202 * Function to add devices to the group on account server
204 * @param groupId Group ID to add devices.
205 * @param deviceId List of devices to add.
206 * @param cloudConnectHandler Callback function that will get the result of the operation.
208 * @return Returns ::OC_STACK_OK if success
210 OCStackResult addDeviceToGroup(const std::string& groupId,
211 const std::vector<std::string>& deviceId,
212 PostCallback cloudConnectHandler);
215 * Function to get information of the group from account server
217 * @param groupId Group ID to get information.
218 * @param cloudConnectHandler Callback function that will get the result of the operation.
220 * @return Returns ::OC_STACK_OK if success
222 OCStackResult getGroupInfo(const std::string& groupId,
223 GetCallback cloudConnectHandler);
226 * Function to leave the group joined on account server
228 * @param groupId Group ID to leave.
229 * @param cloudConnectHandler Callback function that will get the result of the operation.
231 * @return Returns ::OC_STACK_OK if success
233 OCStackResult leaveGroup(const std::string& groupId,
234 DeleteCallback cloudConnectHandler);
237 * Function to delete devices from the group on account server
239 * @param groupId Group ID to delete devices.
240 * @param deviceId List of devices to delete.
241 * @param cloudConnectHandler Callback function that will get the result of the operation.
243 * @return Returns ::OC_STACK_OK if success
245 OCStackResult deleteDeviceFromGroup(const std::string& groupId,
246 const std::vector<std::string>& deviceId,
247 DeleteCallback cloudConnectHandler);
250 * Function to register observe to the group on account server
251 * User can receive a notify when the group get changed (eg. new user/device added)
253 * @param groupId Group ID to observe.
254 * @param cloudConnectHandler Callback function that will get the result of the operation.
256 * @return Returns ::OC_STACK_OK if success
258 OCStackResult observeGroup(const std::string& groupId,
259 ObserveCallback cloudConnectHandler);
262 * Function to cancel observe to the group on account server
264 * @param groupId Group ID to observe.
266 * @return Returns ::OC_STACK_OK if success
268 OCStackResult cancelObserveGroup(const std::string& groupId);
271 * Function to register observe to invitation resource on account server
272 * User can receive a invitation which is including group ID to join
273 * Once receive a invitation, user should call 'deleteInvitation' to delete a invitation
276 * @param cloudConnectHandler Callback function that will get the result of the operation.
278 * @return Returns ::OC_STACK_OK if success
280 OCStackResult observeInvitation(ObserveCallback cloudConnectHandler);
283 * Function to cancel observe to invitation resource on account server
285 * @return Returns ::OC_STACK_OK if success
287 OCStackResult cancelObserveInvitation();
290 * Function to send a invitation to invite a user into a group
292 * @param groupId Group ID for inviting.
293 * @param userUuid Identifier of the user to invite.
294 * @param cloudConnectHandler Callback function that will get the result of the operation.
296 * @return Returns ::OC_STACK_OK if success
298 OCStackResult sendInvitation(const std::string& groupId,
299 const std::string& userUuid,
300 PostCallback cloudConnectHandler);
303 * Function to cancel a invitation on account server that user has sent
305 * @param groupId Group ID to cancel a invitation.
306 * @param userUuid Identifier of the user to cancel a invitation.
307 * @param cloudConnectHandler Callback function that will get the result of the operation.
309 * @return Returns ::OC_STACK_OK if success
311 OCStackResult cancelInvitation(const std::string& groupId,
312 const std::string& userUuid,
313 DeleteCallback cloudConnectHandler);
316 * Function to delete a invitation on account server that user has received
318 * @param groupId Group ID to delete a invitation.
319 * @param cloudConnectHandler Callback function that will get the result of the operation.
321 * @return Returns ::OC_STACK_OK if success
323 OCStackResult deleteInvitation(const std::string& groupId,
324 DeleteCallback cloudConnectHandler);
327 std::weak_ptr<IClientWrapper> m_clientWrapper;
328 std::string m_deviceID;
330 OCDoHandle m_invitationObserveHandle;
331 mutable std::map<std::string, OCDoHandle> m_groupObserveHandles;
332 OCConnectivityType m_connType;
333 QualityOfService m_defaultQos;
336 OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
337 const std::string& host,
338 OCConnectivityType connectivityType);
340 OCStackResult signInOut(const std::string& userUuid,
341 const std::string& accessToken,
343 PostCallback cloudConnectHandler);
345 OCStackResult searchUser(const std::string& userUuid,
346 const QueryParamsMap& queryParams,
347 GetCallback cloudConnectHandler);
351 #endif // OC_ACCOUNT_MANAGER_H_