Skip to content

Commit

Permalink
feat: add module AppStoreConnect for related types
Browse files Browse the repository at this point in the history
  • Loading branch information
c4710n committed Oct 13, 2024
1 parent 20a6f5f commit a3a2870
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 34 deletions.
51 changes: 17 additions & 34 deletions lib/apple/app_store_server_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,32 @@ defmodule Apple.AppStoreServerAPI do
"""

alias JOSE.{JWK, JWS, JWT}

@typedoc """
The issuer ID, like `"57246542-96fe-1a63-e053-0824d011072a"`
"""
@type issuer_id :: String.t()

@typedoc """
The private key ID, like `"2X9R4HXF34"`.
"""
@type key_id :: String.t()

@typedoc """
The private key associated with the `key_id`.
It's in PEM format, like:
```text
-----BEGIN PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
-----END PRIVATE KEY-----
```
"""
@type private_key :: String.t()

@typedoc """
The app's bundle ID, like `"com.example.demo"`.
"""
@type bundle_id :: String.t()
alias Apple.Types.AppStoreConnect

@doc """
Builds a token to authorize HTTP requests.
To get the value of arguments, such as `issuer_id`, `key_id` and so on,
please read [Generating JSON Web Tokens for API requests](https://developer.apple.com/documentation/appstoreserverapi/generating_json_web_tokens_for_api_requests).
> #### Note {: .info}
> Using a private key of the "In-App Purchase" type is sufficient.
After building it, use it in the `Authorization` header like this:
```text
Authorization: Bearer <JWT>
```
```
## More
* [Generating JSON Web Tokens for API requests](https://developer.apple.com/documentation/appstoreserverapi/generating_json_web_tokens_for_api_requests)
"""
@spec build_auth_token!(issuer_id(), key_id(), private_key(), bundle_id()) :: String.t()
@spec build_auth_token!(
AppStoreConnect.issuer_id(),
AppStoreConnect.key_id(),
AppStoreConnect.private_key(),
AppStoreConnect.bundle_id()
) ::
String.t()
def build_auth_token!(issuer_id, key_id, private_key, bundle_id)
when is_binary(issuer_id) and
is_binary(key_id) and
Expand Down
108 changes: 108 additions & 0 deletions lib/apple/types/app_store_connect.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
defmodule Apple.Types.AppStoreConnect do
@moduledoc """
Provides App Store Connect related types.
"""

@typedoc """
The issuer ID, like `"57246542-96fe-1a63-e053-0824d011072a"`
To obtain the issuer ID, sign into App Store Connect and complete the
following steps:
1. Select "Users and Access", and then select the "Integrations" tab.
2. Select the type of "Keys" that you need:
- App Store Connect API
- In-App Purchase
3. Look up the "Issue ID" on the page.
"""
@type issuer_id :: String.t()

@typedoc """
The app's bundle ID, like `"com.example.demo"`.
To obtain the app's bundle ID, sign into App Store Connect and complete the
following steps:
1. Select "Apps".
2. Select "App Information" under the "General" section.
3. Look up the "Bundle ID" on the page.
"""
@type bundle_id :: String.t()

@typedoc """
The private key ID, like `"2X9R4HXF34"`.
To generate a private key, sign into App Store Connect and complete the
following steps:
1. Select "Users and Access", and then select the "Integrations" tab.
2. Select the type of "Keys" that you need:
- App Store Connect API
- In-App Purchase
3. Click the Generate button or the Add (+) button.
4. Enter a name for the key.
5. Click the Generate button.
Then, following information appears on the page:
* the private key's name
* the private key ID
* the link for downloading the private key
> #### Note {: .info}
> The name for the key is for your reference only and isn't part of the key itself.
> #### Warning {: .warning}
> The private key is only available for download a single time.
"""
@type key_id :: String.t()

@typedoc """
The private key associated with the `key_id`.
It's in PEM format, like:
```text
-----BEGIN PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
-----END PRIVATE KEY-----
```
"""
@type private_key :: String.t()

@typedoc """
The secret for verifying receipt, which is a 32-character hexadecimal string,
like `"10e87024b8b34e699156d1d89bdd6bf0"`.
There are two type of shared secrets:
* primary shared secret, which can be used for all of your apps.
* app-specific shared secret, which can only be used for individual apps.
To obtain a primary shared secret, sign into App Store Connect and complete
the following steps:
1. Select "Users and Access", and then select the "Integrations" tab.
2. Select the "Shared Secret" type of "Keys".
3. Generate or regenerate a shared secret.
To obtain a app-specific shared secret, sign into App Store Connect and
complete the following steps:
1. Select "Apps".
2. Select the app that you want to generate shared secret for.
3. Select "App Information" under the "General" section.
4. Look up "App-Specific Shared Secret" on the page.
> #### Note {: .info}
>
> Considering that App Store Receipts have been deprecated, this so-called
> shared secret should no longer be used.
"""
@type shared_secret :: String.t()
end

0 comments on commit a3a2870

Please sign in to comment.