• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_COMMON_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_COMMON_H
18 
19 #include <string>
20 #include "iapp_account_authenticator_callback.h"
21 #include "want.h"
22 
23 namespace OHOS {
24 namespace AccountSA {
25 namespace {
26 const std::string UNKONW_STRING_VALUE = "unknown";
27 }
28 
29 struct AppAccountCallingInfo {
30     int32_t callingUid = -1;
31     std::string bundleName;
32     uint32_t appIndex;
33 };
34 
35 struct AuthenticatorInfo {
36     std::string owner;
37     std::string abilityName;
38     int32_t iconId;
39     int32_t labelId;
40 };
41 
42 struct SelectAccountsOptions : public Parcelable {
43     bool hasAccounts = false;
44     bool hasOwners = false;
45     bool hasLabels = false;
46     std::vector<std::pair<std::string, std::string>> allowedAccounts;
47     std::vector<std::string> allowedOwners;
48     std::vector<std::string> requiredLabels;
49     bool ReadFromParcel(Parcel &parcel);
50     virtual bool Marshalling(Parcel &parcel) const override;
51     static SelectAccountsOptions *Unmarshalling(Parcel &parcel);
52 };
53 
54 struct VerifyCredentialOptions : public Parcelable {
55     std::string credentialType;
56     std::string credential;
57     AAFwk::WantParams parameters;
58     bool ReadFromParcel(Parcel &parcel);
59     virtual bool Marshalling(Parcel &parcel) const override;
60     static VerifyCredentialOptions *Unmarshalling(Parcel &parcel);
61 };
62 
63 struct SetPropertiesOptions : public Parcelable {
64     AAFwk::WantParams properties;
65     AAFwk::WantParams parameters;
66     bool ReadFromParcel(Parcel &parcel);
67     virtual bool Marshalling(Parcel &parcel) const override;
68     static SetPropertiesOptions *Unmarshalling(Parcel &parcel);
69 };
70 
71 struct CreateAccountOptions : public Parcelable {
72     std::map<std::string, std::string> customData;
73     bool ReadFromParcel(Parcel &parcel);
74     virtual bool Marshalling(Parcel &parcel) const override;
75     static CreateAccountOptions *Unmarshalling(Parcel &parcel);
76 };
77 
78 struct CreateAccountImplicitlyOptions : public Parcelable {
79     bool hasAuthType = false;
80     bool hasRequiredLabels = false;
81     std::string authType;
82     std::vector<std::string> requiredLabels;
83     AAFwk::Want parameters;
84     bool ReadFromParcel(Parcel &parcel);
85     virtual bool Marshalling(Parcel &parcel) const override;
86     static CreateAccountImplicitlyOptions *Unmarshalling(Parcel &parcel);
87 };
88 
89 struct AuthenticatorSessionRequest {
90     std::string action;
91     std::string sessionId;
92     std::string name = UNKONW_STRING_VALUE;
93     std::string owner = UNKONW_STRING_VALUE;
94     std::string authType;
95     std::string token;
96     std::string bundleName = UNKONW_STRING_VALUE;
97     std::string callerBundleName;
98     std::string callerAbilityName = UNKONW_STRING_VALUE;
99     uint32_t appIndex;
100     bool isTokenVisible = false;
101     pid_t callerPid;
102     pid_t callerUid;
103     AAFwk::Want options;
104     std::vector<std::string> labels;
105     VerifyCredentialOptions verifyCredOptions;
106     SetPropertiesOptions setPropOptions;
107     CreateAccountImplicitlyOptions createOptions;
108     sptr<IAppAccountAuthenticatorCallback> callback = nullptr;
109 };
110 
111 enum AuthenticatorAction {
112     ADD_ACCOUNT_IMPLICITLY,
113     AUTHENTICATE,
114     VERIFY_CREDENTIAL,
115     CHECK_ACCOUNT_LABELS,
116     SET_AUTHENTICATOR_PROPERTIES,
117     IS_ACCOUNT_REMOVABLE,
118     CREATE_ACCOUNT_IMPLICITLY,
119     AUTH,
120 };
121 
122 enum JSResultCode {
123     ERR_JS_SUCCESS_V8 = 0,
124     ERR_JS_ACCOUNT_NOT_EXIST = 10001,
125     ERR_JS_APP_ACCOUNT_SERVICE_EXCEPTION = 10002,
126     ERR_JS_INVALID_PASSWORD = 10003,
127     ERR_JS_INVALID_REQUEST = 10004,
128     ERR_JS_INVALID_RESPONSE = 10005,
129     ERR_JS_NETWORK_EXCEPTION = 10006,
130     ERR_JS_OAUTH_AUTHENTICATOR_NOT_EXIST = 10007,
131     ERR_JS_OAUTH_CANCELED = 10008,
132     ERR_JS_OAUTH_LIST_TOO_LARGE = 10009,
133     ERR_JS_OAUTH_SERVICE_BUSY = 10010,
134     ERR_JS_OAUTH_SERVICE_EXCEPTION = 10011,
135     ERR_JS_OAUTH_SESSION_NOT_EXIST = 10012,
136     ERR_JS_OAUTH_TIMEOUT = 10013,
137     ERR_JS_OAUTH_TOKEN_NOT_EXIST = 10014,
138     ERR_JS_OAUTH_TOKEN_TOO_MANY = 10015,
139     ERR_JS_OAUTH_UNSUPPORT_ACTION = 10016,
140     ERR_JS_OAUTH_UNSUPPORT_AUTH_TYPE = 10017,
141     ERR_JS_PERMISSION_DENIED_V8 = 10018
142 };
143 
144 int32_t ConvertToJSErrCodeV8(int32_t errCode);
145 }  // namespace AccountSA
146 }  // namespace OHOS
147 
148 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_COMMON_H
149