Implement Sign in with Apple with just a few lines of code
While the convenience of not having to deal with user logins is attractive, and most likely how some of you have built your apps, if you want to integrate AI services - be it big model providers like OpenAI or Compiler’s function calling - there really isn’t a good mechanism to protect your API keys or be able to clearly charge and monitor your users.
The unfortunate reality is that AI costs money in terms of hosting, inference, and electricity to make inference requests to these LLMs, and without visibility into your users, this becomes impossible to manage and prohibitively expensive for you as the developer.
Also, if you put bare API keys into your client-side app, these keys can get sniffed by malicious actors and can be used for their own devices, leaving you with a massive bill for use that you never authorized. So with these realities, using Auth is the only option; however, we have worked hard to make the implementation not only easy but something that will benefit you and your users.
For now we are focused on Sign in with Apple. (coming soon: email/password, firebase, google). We chose Sign in with Apple because it’s easy to implement, and it provides the least amount of friction to your end users.
Before you begin, you’ll need:
Click on ”+ Capability”, this will open a popup with a search input
Start typing “Sign” and you’ll see an option in the left hand side that reads “Sign in with apple”. Select this and Xcode will automatically generate the entitlements for you and add them to your developer account for this given app.
Go to developer.apple.com and sign in to your Apple Developer account if you aren’t already signed in.
You will see a series of buttons in a row. You will first click on “Membership Details” to get your TeamID:
Note, you can only download the P8 key once, so please store it somewhere safe. If you lose it, you’ll have to do this process all over again for the given app.
You must copy and paste the entirety of the .p8 file which includes ----BEGIN PRIVATE KEY---- and ----END PRIVATE KEY----. Text Edit is good for opening these files.
Click on “Save Configuration” when done.
Once you’ve completed the setup process, adding Sign in with Apple to your app is as simple as a few lines of code. Here’s a basic implementation using a view model pattern:
That’s it! With just these few components, you’ve implemented a complete Sign in with Apple flow that securely authenticates your users with Compiler’s backend.
Once you have authentication set up, you can:
Implement Sign in with Apple with just a few lines of code
While the convenience of not having to deal with user logins is attractive, and most likely how some of you have built your apps, if you want to integrate AI services - be it big model providers like OpenAI or Compiler’s function calling - there really isn’t a good mechanism to protect your API keys or be able to clearly charge and monitor your users.
The unfortunate reality is that AI costs money in terms of hosting, inference, and electricity to make inference requests to these LLMs, and without visibility into your users, this becomes impossible to manage and prohibitively expensive for you as the developer.
Also, if you put bare API keys into your client-side app, these keys can get sniffed by malicious actors and can be used for their own devices, leaving you with a massive bill for use that you never authorized. So with these realities, using Auth is the only option; however, we have worked hard to make the implementation not only easy but something that will benefit you and your users.
For now we are focused on Sign in with Apple. (coming soon: email/password, firebase, google). We chose Sign in with Apple because it’s easy to implement, and it provides the least amount of friction to your end users.
Before you begin, you’ll need:
Click on ”+ Capability”, this will open a popup with a search input
Start typing “Sign” and you’ll see an option in the left hand side that reads “Sign in with apple”. Select this and Xcode will automatically generate the entitlements for you and add them to your developer account for this given app.
Go to developer.apple.com and sign in to your Apple Developer account if you aren’t already signed in.
You will see a series of buttons in a row. You will first click on “Membership Details” to get your TeamID:
Note, you can only download the P8 key once, so please store it somewhere safe. If you lose it, you’ll have to do this process all over again for the given app.
You must copy and paste the entirety of the .p8 file which includes ----BEGIN PRIVATE KEY---- and ----END PRIVATE KEY----. Text Edit is good for opening these files.
Click on “Save Configuration” when done.
Once you’ve completed the setup process, adding Sign in with Apple to your app is as simple as a few lines of code. Here’s a basic implementation using a view model pattern:
That’s it! With just these few components, you’ve implemented a complete Sign in with Apple flow that securely authenticates your users with Compiler’s backend.
Once you have authentication set up, you can: