Files
xtool-mirror/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift
Víctor Agudo Gonzalez 952a7ffd43 entitlements: support Sign in with Apple (#377)
## What does this PR do?

Hi! xtool didn't know about the `com.apple.developer.applesignin`
entitlement, so every time I installed my app, the capability sync
removed Sign in with Apple from the App ID. The new provisioning profile
didn't have it, and the device refused the app ("A valid provisioning
profile for this executable was not found").

This maps the entitlement to the `APPLE_ID_AUTH` capability, as a
primary App ID, so the capability stays and the profile includes it.

## How was it tested?

I built xtool from this branch on macOS and installed my app (a SwiftPM
app with `entitlementsPath` and the Sign in with Apple entitlement) on
an iPhone with a paid team. The App ID kept the capability, the install
worked, and native Sign in with Apple works in the app. Before the
change the same install failed every time.

## AI tool usage

How much of this PR was AI-assisted? (check one)

- [ ] **0** - No AI was used to write code
- [x] **1** - I was assisted by AI. I reviewed the finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
  * Added support for configuring the Apple Sign In entitlement.
* Apple Sign In is now available as a supported entitlement type,
including serialization and configuration support.
  * Configures Apple ID app consent as the primary app consent option.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-10-22 22:25:37 -04:00

163 lines
4.9 KiB
Swift

//
// DeveloperServicesFeatureTypes.swift
// Supercharge
//
// Created by Kabir Oberai on 29/07/19.
// Copyright © 2019 Kabir Oberai. All rights reserved.
//
import Foundation
import DeveloperAPI
public struct DeveloperServicesCapability: Sendable, Hashable {
public var capabilityType: Components.Schemas.CapabilityType
public var isFree: Bool
public var settings: [Components.Schemas.CapabilitySetting]?
public init(
_ capabilityType: Components.Schemas.CapabilityType.Value1Payload,
isFree: Bool,
settings: [Components.Schemas.CapabilitySetting]? = nil
) {
self.capabilityType = .init(capabilityType)
self.isFree = isFree
self.settings = settings
}
public init(
rawName: String,
isFree: Bool,
settings: [Components.Schemas.CapabilitySetting]? = nil
) {
self.capabilityType = .init(value2: rawName)
self.isFree = isFree
self.settings = settings
}
}
protocol EntitlementWithCapability: Entitlement {
var capability: DeveloperServicesCapability { get }
}
extension Entitlement {
var anyCapability: DeveloperServicesCapability? {
(self as? EntitlementWithCapability)?.capability
}
}
// MARK: - Special Features
extension DataProtectionEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
let option: Components.Schemas.CapabilityOption.KeyPayload.Value1Payload = switch self {
case .complete: .completeProtection
case .unlessOpen: .protectedUnlessOpen
case .untilFirstAuth: .protectedUntilFirstUserAuth
}
return DeveloperServicesCapability(
.dataProtection,
isFree: true,
settings: [
.init(
key: .init(.dataProtectionPermissionLevel),
options: [.init(key: .init(option))]
)
]
)
}
}
// MARK: - Boolean Features
// https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/portal/app_service.rb
extension AppGroupEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
// FIXME: Enable app groups on free accounts
// but we need to always assign only one group
DeveloperServicesCapability(.appGroups, isFree: false)
}
}
extension AppleSignInEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
// A primary App ID: the app is its own Sign in with Apple group.
DeveloperServicesCapability(
.appleIdAuth,
isFree: false,
settings: [
.init(
key: .init(.appleIdAuthAppConsent),
options: [.init(key: .init(.primaryAppConsent))]
)
]
)
}
}
extension AssociatedDomainsEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.associatedDomains, isFree: false)
}
}
extension HealthKitEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.healthkit, isFree: true)
}
}
extension HomeKitEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.homekit, isFree: true)
}
}
extension InterAppAudioEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.interAppAudio, isFree: true)
}
}
extension MultipathEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.multipath, isFree: false)
}
}
extension NetworkExtensionEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.networkExtensions, isFree: false)
}
}
extension VPNConfigurationEntitlement: EntitlementWithCapability {
public var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.personalVpn, isFree: false)
}
}
extension APSEnvironmentEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.pushNotifications, isFree: false)
}
}
extension SiriKitEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.sirikit, isFree: false)
}
}
extension WirelessAccessoryEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.wirelessAccessoryConfiguration, isFree: true)
}
}
extension WiFiAwareEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(rawName: "WIFI_AWARE", isFree: false)
}
}