• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @file Describe the file
3 * Copyright (c) 2023 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { getQueries } from '@ohos/common/src/main/ets/utils/UrlUtils';
18import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
19import { Log } from '@ohos/common/src/main/ets/utils/Log';
20
21const TAG = "CalendarUriHelper"
22
23/**
24 * Verify whether the current calling application has this permission by tokenID
25 *
26 * @param tokenId indicates the user's tokenID ,the tokenID can be a string or number
27 * @return the uri string without BundleName and TokenID in case of changing this data.
28 */
29export async function verifyAccessByTokenId(tokenId: string, permissionName: string): Promise<boolean> {
30  var atManager = abilityAccessCtrl.createAtManager();
31  let result;
32  try {
33    result = await atManager.verifyAccessToken(parseInt(tokenId), permissionName);
34  } catch (err) {
35    Log.error(TAG, `err=${err?.message}`);
36  }
37
38  if (result === null || result === undefined) {
39    return false;
40  }
41
42  if (result === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) {
43    // Allow the visitor to call the interface provided by the current application
44    Log.debug(TAG, "This application has been authorized to access");
45    return true;
46  } else {
47    // Prohibit the visitor to call the interface provided by the current application
48    Log.debug(TAG, "This application is NOT authorized to access");
49    return false;
50  }
51  return false;
52}