codebytere / codebytere/node-mac-contacts

Permission dialog for contacts access not shown

Đang mở
#32 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Objective-C++
Star
86
Fork
18
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**Issue** :
When running the electron app, I am not able to get the contacts permission dialog to be presented (neither when i run the script from the terminal, nor the compiled electron app), despite supplying the correct entitlement(s) in the plist file.

When running the electron app from the command line , the below code is evaluated and when i check the status, i am returned `"Authorised"` and as such i can successfully retrieve my macs Addressbook contacts. In this instance I understand why the pop-up is not displayed, as because I have run the electron app from Terminal, I am implicitly given access to contacts without needing to give consent explicitly.

However when I compile the Electron app, and run, the permission status is immediately returned as being `"Denied"`, this happens for both the .app and .dmg versions.

**Things i have tried :**
1. Clearing the permission state every time i make a new build with > `sudo tccutil reset All com.wowfresh.freshmeup-desktop`
2. Performed step 1 and restarted my mac before attempting to launch the .dmg and .apps

**I am running**
electron version : v1.4.13
npm version : v6.14.15
node version : v14.18.1
OS version : Monterey 12.3.1
packager : electron-builder version : 23.0.3

**My code and config**
My entitlements plist file. Note : i have the same for inherited entitlements.
Also, if you're thinking , why has he included `com.apple.security.personal-information.addressbook` in the entitlements file, i have documented my rational in point 3 at the end :).

**entitlements.plist**
```


com.apple.security.app-sandbox

com.apple.security.personal-information.addressbook

com.apple.private.tcc.manager.check-by-audit-token

com.apple.security.automation.apple-events

NSContactsUsageDescription
Your reason for wanting to access the Contact store
com.apple.security.inherit

```

Relevant pieces of **package.json**
```
"appId": "com.wowfresh.freshmeup-desktop",
"mac": {
"gatekeeperAssess": false,
"icon": "./public/icons/mac/icon.icns",
"category": "public.app-category.utilities",
"type": "distribution",
"hardenedRuntime": true,
"provisioningProfile": "../mac_signing_certificates/freshmeup-desktop.provisionprofile",
"identity": "Apple Distribution: freshmeup Limited (HSGFYWI9929)",
"asarUnpack": "**/*.node",
"extendInfo": {
"NSContactsUsageDescription": "Your reason for wanting to access the Contact store"
}

},
"mas":{
"entitlements": "./build/electron/entitlements.mac.plist",
"entitlementsInherit": "./build/electron/entitlements.mac.plist"
},
```

**Getting contacts code**

```
const macContacts = require('node-mac-contacts');

macContacts.requestAccess().then(function(result) {

const authStatus = macContacts.getAuthStatus();

console.log(`Authorization access to contacts is: ${authStatus}`);

if(authStatus == "Authorized"){
const allContacts = macContacts.getAllContacts();
console.log(allContacts);
}

});
```

**My observations :**
1. When i launch the app (and receive the `Denied` status immediately) i notice that system preferences is not launched (as the documents suggest it should be) and further more ...
2. Having navigated to system preferences i do not see my app in the section as shown below.
![Screenshot 2022-04-04 at 14 06 15](https://user-images.githubusercontent.com/5942626/161550113-2755dc74-bb75-48c5-9ae9-e6cfa3cec640.png)

3. Unrelated to points 1 and 2 , when i pull up the console logs for the compiled electron app, i see ERROR messages like the following in the list (in order of when i see them) coming from the tccd process , Note : TCC (Transparency, Consent, and Control) is a mechanism in macOS to limit and control application access to certain features

`service: kTCCServiceAddressBook requires entitlement com.apple.security.personal-information.addressbook but it is missing for requesting`
and
`service: kTCCServiceAppleEvents requires entitlement com.apple.security.automation.apple-events but it is missing for accessing
`
and
`attempted to call TCCAccessRequest for kTCCServiceAccessibility without the recommended com.apple.private.tcc.manager.check-by-audit-token entitlement`

These relate to what i am assuming are underlying permissions for accessing contacts, the odd thing is that despite adding them to the entitlements file, the errors persist.

At this point i would have thought , ok i have a signing problem, however when i test adding the **camera** and **microphone** permissions to the entitlements file, then requesting access to them in my code using the electron request method https://www.electronjs.org/docs/latest/api/system-preferences#systempreferencesaskformediaaccessmediatype-macos , i get the "Application Name wants access to your camera and microphone" dialog as expected.

Thank you so much for any help / guidance / alternative things i could try.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với entitlements.plist và cấu hình mac trong package.json, sau đó lần theo các lệnh gọi requestAccess() và getAuthStatus() trong mã contacts. Build cả hai biến thể đã được đóng gói và kiểm tra xem ứng dụng đã biên dịch có chứa các entitlements được khai báo hay không. Được xem là hoàn tất khi ứng dụng Electron đã đóng gói hiển thị luồng cấp quyền Contacts và báo cáo trạng thái truy cập cho phép truy xuất danh bạ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
electron, javascript, macos, node.js, objective-c
Lĩnh vực
build-system, desktop, security
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.