How can I ask for an Administrator Login in an OSX Swift Application? - swift

I'm currently trying to make an application only open if an administrator login is entered into a dialog box. I've tried using an AppleScript under the following method:
set adminLogin to do shell script "" with administrator privileges
display dialog adminLogin
This displays the dialog I'd like, and I was able to throw this into an NSTask to perform it. I can even grab the output and use that to close the application under and if statement.
I'd like to be using the actual application rather than osascript to mention that it requires an administrator login to continue, and this scpt file vanishes as soon as I compile, build, and archive this for actual usage, meaning I'd have to re-add this file post-creation to all of the clients I am making this for. It doesn't seem too effective for the fact that it relies on a different task for a quick login that could possibly be exploited rather than using the same process that the application is holding.
Is there a way I can programmatically ask for an administrator login to continue opening the application? Could I use CoreLocation and-or could I use AuthorizationServices() to perform this task?

Take a look at the LocalAuthentication framework. There is a policy for deviceOwnerAuthentication which handles both Touch ID and device passcode authentication.
LocalAuthentication Framework Reference: https://developer.apple.com/reference/localauthentication
and
deviceOwnerAuthentication:
https://developer.apple.com/reference/localauthentication/lapolicy/1514164-deviceownerauthentication

Related

Powershell - Open URL and login

Is it possible to run a Powershell script that opens a website in a default browser, sets username and password input values, and then triggers a button click event?
Thank you for any feedback!
In PowerShell, you can use Start-Process on a string containing a URL to open the default Web browser. And you can use SendKeys to send keystrokes to an application.
If you want to automate a Web browser, you can try Selenium.
If you want to manage logons among users, you can try RoboForm.
If you want to wrap a line-of-business application for single sign-on, you can try Azure AD Application Proxy.
My advice is to avoid public macros because they are unreliable and generate help desk requests.

MacOs. How can I ask access for System Events on every app?

I need my Mac Swift app uses the System Events (via Applescript) to close any app that user adds to a list.
I see in my System Preferences a lot of apps having System Events access in Automation panel (e.g. 'Google's backup and sync' or 'Divvy'). How can I ask permissions for that?
In Info.plist add the key NSAppleEventsUsageDescription in Source Code view
<key>NSAppleEventsUsageDescription</key>
<string>$(PRODUCT_NAME) needs to control System Events</string>
or Privacy - AppleEvents Sending Usage Description in the popup menu in Property List view.
The <string> value is an arbitrary description.
Moreover in Xcode 11 where Hardened Runtime is enabled you have to check the Apple Events checkbox
I found a reliable way to ask Automation permission in my app.
Run a command to send System Event in shell use osascript, like this:
osascript -e 'tell application "System Events" to keystroke "a"'
If this is the first time you have sent System Event on user's computer, an authorization dialog will pop up by system.
If you want to check the Automation permission status, you can run the same script via NSAppleScript.
NSAppleScript *aScript = [[NSAppleScript alloc] initWithSource:source];
NSDictionary<NSString *, id> *errorInfo;
[aScript executeAndReturnError:&errorInfo];
This code will silently fail in both cases when the first time sending System Event and when the authorization had denied. And the error code here will be -1743.
It should be noted that if the Accessibility permission is unauthorized, the error code here will be 1002. So first make sure that accessibility permissions are authorized.

Sorry, this action is not available in simulation

My test invocation name is "Mrs Tang", so i input "Talk to Mrs Tang", but it responds "Sorry, this action is not available in simulation"...
Does anybody know How can I resolve this error?
According to the doc:
Turn on the Web & App Activity, Device Information, and Voice & Audio
Activity permissions on the Activity controls page for your Google
account. You need to do this to use the Actions Simulator, which lets
you test your actions on the web without a hardware device.
And I had do what Jeremy Gordon suggested. To add a second google account in the GCP IAM console with a viewer action permission and then login with this second google account in an incognito window for the web simulator to work.
I had a related problem (I could test with my main developer account, but not my test credentials). I eventually got it working with the non-primary account.
The missing link for me was that when I was viewing the simulator, I was actually signed in to two accounts, my primary google account (developer account, shows up in the main frame of the page, upper right corner), and the account I authorized when 'starting' the simulator (email address shows up in the simulator frame), which was my test credentials. The second test account repeatedly gave me the "Sorry, this action is not supported in simulation" message, until I:
1) Added the test account as a Conversation API Viewer & Client in GCP IAM console
2) Visited the 'create link' (the one that comes up when you click share) in an incognito window, and signed into the secondary account there such that I was signed into only one account in that incognito window.
After that, invocations connected to the app.
Make sure you are logged into the same account you used to deploy the test action and that the deployment has been done within the past half hour or so. If you have not set all the information on the Actions on Google Console, you may need to use the invocation phrase "Talk to my test app".
I think sometimes I run into the same error. I get past it by toggling the Active switch off and on.
Same problem I encountered. You must be logged in via the secondary google account. Do logout from the account and login via the account that is paired with api.ai.
why I can't use google action in web simulator
I got this to work by saying "talk to my test app" or typing it in to the simulator prompt, that triggered my app to start in the simulator.
I had the same problem. I needed to set the location first (it defaults to Google-Headquaters), if you are in some other region (like in germany as i am).
Then go on with "Mit meiner Test-App sprechen" (Talk to my test app), or whatever it is in your language!
I did not get this message on my invocation, but on my my second input:"Sorry, this action is not available for your app.".
It turns out the simulator had left the conversation right after the invocation (and it did mention that in the small print).
This happened because I returned a FinalResponse for the invocation. And a final response is pretty final, it will terminate your conversation.
So, after a FinalResponse you can only get back in your action/conversation by a new invocation or a deep link. If you want to suggest questions/inputs, then you should return ExpectedInputs.
You might need to turn on Web & App Activity to let group members use some Google Assistant features.(if you are using organizational account)
https://support.google.com/assistant/answer/7219584?hl=en
If you are using any organization's Google Accounts then there might be an access issue. So use your own personal Gmail account.
Take a look here, organization's might not be given you access. So use your personal Gmail and follow the Docs, you will able to create your agent/ actions and able to test it with simulator as well as in android device.
At time of testing the Google Action you need to set the location to the country which you selected while developing or submitting your Google Action.
By default US is selected in testing but if your action is for one particular country only then you need to select that. You can see in image the field where you can select location

When to create PFInstallation

I am new to using PFinstallations on Parse, and i am a bit confused as to how they work. I have an app that creates a new installation when a user creates an account, and i set the "User" field of the installation to the users userId so i can send them notifications easily later. I dont understand how the installation works when the user logs out or closes the app. In order to be able to always send the user a notification, must i create new installations periodically when these events (ie. logging out or closing the app) occur?
You shouldn't ever need to create an instance of PFInstallation. The parse framework will handle that for you if you access it using PFInstallation.currentInstallation(). But to save it to the backend, you'll need to call one of the save methods yourself.
By default, logging out will have no impact on the installation since it is a method on the user. You can have you own logic that modifies the installation on logout to, for example, clear the user field or channels.
The parse framework writes the installation to disk on the users device. When the app stops running and then restarts, parse can just read that data from disk and have the proper PFInstallation object again.

wp7 how to add a pre install message

I want to add a pre install messagebox in my wp7 application, like in most of the application on market place.
e.g., my message :
'This application required your location services access, if you don't want to allow app to use it, click cancel otherwise allow'
if user choose allow then application installs otherwise it doesn't install
These messages are created by the Marketplace / install routine based on the capabilities requested by your app. You can't change them.
For example, if your app manifest says the app will use location services, the install routine prompts the user with a default message asking if they want to allow access.