00f2b6640448b165b917f8b527cb51fdb130d561
[platform/upstream/iotivity.git] / resource / include / OCAccountManager.h
1 /* ****************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #ifndef OC_ACCOUNT_MANAGER_H_
22 #define OC_ACCOUNT_MANAGER_H_
23
24 #include <OCApi.h>
25 #include <IClientWrapper.h>
26 #include <InProcClientWrapper.h>
27
28 namespace OC
29 {
30     class OCAccountManager
31     {
32         friend class OCPlatform_impl;
33
34     public:
35         typedef std::shared_ptr<OCAccountManager> Ptr;
36
37         OCAccountManager(OCAccountManager&&) = default;
38         OCAccountManager(const OCAccountManager&) = delete;
39         OCAccountManager& operator=(OCAccountManager&&) = delete;
40         OCAccountManager& operator=(const OCAccountManager&) = delete;
41
42         virtual ~OCAccountManager(void);
43
44         /**
45         * Function to get the host address of account server
46         *
47         * @return std::string host address
48         */
49         std::string host() const;
50
51         /**
52         * Function to get the connectivity type for account server
53         *
54         * @return enum connectivity type (flags and adapter)
55         */
56         OCConnectivityType connectivityType() const;
57
58         /**
59          * Function for account registration to account server
60          *
61          * @param authProvider Provider name used for authentication.
62          * @param authCode The authorization code obtained by using an authorization server
63          *                 as an intermediary between the client and resource owner.
64          * @param cloudConnectHandler Callback function that will get the result of the operation.
65          *
66          * @return Returns ::OC_STACK_OK if success
67          */
68         OCStackResult signUp(const std::string& authProvider,
69                              const std::string& authCode,
70                              PostCallback cloudConnectHandler);
71
72         /**
73          * Overload
74          *
75          * @param authProvider Provider name used for authentication.
76          * @param authCode The authorization code obtained by using an authorization server
77          *                 as an intermediary between the client and resource owner.
78          * @param options The option values depends on auth provider.
79          * @param cloudConnectHandler Callback function that will get the result of the operation.
80          *
81          * @return Returns ::OC_STACK_OK if success
82          */
83         OCStackResult signUp(const std::string& authProvider,
84                              const std::string& authCode,
85                              const QueryParamsMap& options,
86                              PostCallback cloudConnectHandler);
87
88         /**
89          * Function for sign-in to account server
90          *
91          * @param userId Identifier of the user obtained by account registration.
92          * @param accessToken Identifier of the resource obtained by account registration.
93          * @param cloudConnectHandler Callback function that will get the result of the operation.
94          *
95          * @return Returns ::OC_STACK_OK if success
96          */
97         OCStackResult signIn(const std::string& userId,
98                              const std::string& accessToken,
99                              PostCallback cloudConnectHandler);
100
101         /**
102          * Function for sign-out to account server
103          *
104          * @param userId Identifier of the user obtained by account registration.
105          * @param accessToken Identifier of the resource obtained by account registration.
106          * @param cloudConnectHandler Callback function that will get the result of the operation.
107          *
108          * @return Returns ::OC_STACK_OK if success
109          */
110         OCStackResult signOut(const std::string& userId,
111                               const std::string& accessToken,
112                               PostCallback cloudConnectHandler);
113
114         /**
115          * Function for refresh access token to account server
116          *
117          * @param userId Identifier of the user obtained by account registration.
118          * @param refreshToken Refresh token used for access token refresh.
119          * @param cloudConnectHandler Callback function that will get the result of the operation.
120          *
121          * @return Returns ::OC_STACK_OK if success
122          */
123         OCStackResult refreshAccessToken(const std::string& userId,
124                                          const std::string& refreshToken,
125                                          PostCallback cloudConnectHandler);
126
127     private:
128         std::weak_ptr<IClientWrapper> m_clientWrapper;
129         std::string m_deviceID;
130         std::string m_host;
131         OCConnectivityType m_connType;
132         QualityOfService m_defaultQos;
133
134     private:
135         OCAccountManager(std::weak_ptr<IClientWrapper> clientWrapper,
136                          const std::string& host,
137                          OCConnectivityType connectivityType);
138
139         OCStackResult signInOut(const std::string& userId,
140                                 const std::string& accessToken,
141                                 bool isSignIn,
142                                 PostCallback cloudConnectHandler);
143     };
144 } // namespace OC
145
146 #endif // OC_ACCOUNT_MANAGER_H_
147