Skip to content

Commit 6a8e561

Browse files
authored
Set up documentation generation for Swift Package Index; enhance docs (#37)
This adds a bunch of documentation using the `docc` format, and adds a Swift Package Index manifest so that it can be automatically generated, linked, and hosted. Fixes #36
1 parent 0b3b920 commit 6a8e561

File tree

5 files changed

+129
-13
lines changed

5 files changed

+129
-13
lines changed

.spi.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Swift Package Index
2+
version: 1
3+
builder:
4+
configs:
5+
- documentation_targets:
6+
- SnapAuth
7+
platform: ios

Sources/SnapAuth/Errors.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
import AuthenticationServices
22

3+
/// SnapAuth error codes
4+
///
5+
/// Authentication and credential registration can fail or be rejected in
6+
/// numerous ways, and applications should be prepared to handle these
7+
/// scenarios.
38
public enum SnapAuthError: Error {
49
/// The network request was disrupted. This is generally safe to retry.
510
case networkInterruption
611

7-
/// A new request is starting, so the one in flight was canceled
12+
/// Only a single request can run at a time. A new request is starting, so
13+
/// the current one is being canceled.
814
case newRequestStarting
915

10-
/// This needs APIs that are not supported on the current platform
16+
/// This needs APIs that are not supported on the current platform. You can
17+
/// use `if #available()` conditionals, or similar, to avoid this.
1118
case unsupportedOnPlatform
1219

1320
// MARK: Internal errors, which could represent SnapAuth bugs
1421

1522
/// The SDK received a response from SnapAuth, but it arrived in an
16-
/// unexpected format. If you encounter this, please reach out to us.
23+
/// unexpected format.
24+
///
25+
/// If you encounter this, please reach out to us.
1726
case malformedResposne
1827

19-
/// The SDK was unable to encode data to send to SnapAuth. If you encounter
20-
/// this, please reach out to us.
28+
/// The SDK was unable to encode data to send to SnapAuth.
29+
///
30+
/// If you encounter this, please reach out to us.
2131
case sdkEncodingError
2232

23-
/// The request was valid and understood, but processing was refused. If you
24-
/// encounter this, please reach out to us.
33+
/// The request was valid and understood, but processing was refused.
34+
///
35+
/// If you encounter this, please reach out to us.
2536
case badRequest
2637

2738
// MARK: Weird responses
2839

29-
/// ASAuthorizationServices sent SnapAuth an unexpected type of response
30-
/// which we don't know how to handle. If you encounter this, please reach
31-
/// out to us.
40+
/// `ASAuthorizationServices` sent SnapAuth an unexpected type of response
41+
/// which we don't know how to handle.
42+
///
43+
/// If you encounter this, please reach out to us.
3244
case unexpectedAuthorizationType
3345

3446
/// Some of the data SnapAuth requested during credential registration was
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ``SnapAuth``
2+
3+
The official [SnapAuth](https://www.snapauth.app) SDK for Apple platforms.
4+
5+
## Overview
6+
7+
SnapAuth allows you to quickly, easily, and reliably add passkeys to your web and native apps.
8+
You can be up and running in minutes on all platforms without ever having to look at `AuthenticationServices`.
9+
10+
This SDK supports all native Apple platforms that permit passkey use - iOS, iPadOS, macOS, visionOS, and tvOS.
11+
Apple Watch and watchOS do not support passkeys.
12+
If and when it does, we'll add support as well.
13+
14+
## Getting Started
15+
16+
To use SnapAuth, you'll first need to register an account: [](https://www.snapauth.app/register).
17+
Registration is free, but SnapAuth is a paid service and you'll be limited to a small number of users during the free trial.
18+
19+
Once you register, you'll be taken to our [dashboard](https://dashboard.snapauth.app).
20+
In there, you can get access to your `publishable key`, which you'll need to use SnapAuth in your native app.
21+
22+
## Topics
23+
24+
### Setup
25+
26+
To start, import the SnapAuth SDK and provide it your _publishable key_ from the dashboard.
27+
28+
```swift
29+
import SnapAuth
30+
31+
let snapAuth = SnapAuth(publishableKey: "pubkey_your_key")
32+
```
33+
34+
- ``SnapAuth/SnapAuth``
35+
- ``SnapAuth/SnapAuth/init(publishableKey:urlBase:)``
36+
37+
### Credential Registration
38+
39+
Create a new passkey (or associate a hardware key) for the user.
40+
41+
- ``SnapAuth/startRegister(name:displayName:authenticators:)``
42+
43+
### Authentication
44+
45+
Authenticate a user using their previously-registered passkey or hardware key.
46+
47+
- ``SnapAuth/SnapAuth/startAuth(_:authenticators:)``
48+
- ``SnapAuth/AuthenticatingUser``
49+
50+
### Credential AutoFill
51+
52+
When a user focuses a `TextField` with `.textContentType(.username)`, the QuickType bar can suggest passkeys.
53+
This allows the user to authenticate without even having to fill in their username.
54+
55+
AutoFill is only available on iOS and visionOS.
56+
57+
- ``SnapAuth/SnapAuth/handleAutoFill()``
58+
59+
### Controlling Authenticator Types
60+
61+
For the best user experience and most flexibility, allow all of the platform's supported authenticators.
62+
Passkeys are supported on all platforms.
63+
External hardware authenticators are not supported on tvOS or visionOS.
64+
65+
- ``SnapAuth/SnapAuth/Authenticator``
66+
67+
### Handling Responses
68+
69+
All of the SDK's core methods will return a `SnapAuthResult`, which is an alias for `Result<SnapAuthTokenInfo, SnapAuthError>`.
70+
Inspect the result to decide how to proceed.
71+
72+
```swift
73+
let result = await snapAuth.startAuth(.id("usr_123456"))
74+
switch result {
75+
case .success(let auth):
76+
// Send auth.token to your backend to sign in the user
77+
case .failure(let error):
78+
// Examine the error and decide how best to proceed
79+
}
80+
```
81+
82+
- ``SnapAuth/SnapAuthResult``
83+
- ``SnapAuth/SnapAuthTokenInfo``
84+
- ``SnapAuth/SnapAuthError``

Sources/SnapAuth/SnapAuth.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ public class SnapAuth: NSObject { // NSObject for ASAuthorizationControllerDeleg
2222

2323
internal var continuation: CheckedContinuation<SnapAuthResult, Never>?
2424

25+
/// Initialize the SnapAuth SDK
2526
/// - Parameters:
2627
/// - publishableKey: Your SnapAuth publishable key. This can be obtained
2728
/// from the [SnapAuth dashboard](https://dashboard.snapauth.app)
28-
/// - urlBase: A custom URL base for the SnapAuth API. This is generally
29-
/// for internal use.
29+
/// - urlBase: A custom URL base for the SnapAuth API. This should usually
30+
/// be omitted and left as the default value.
3031
public init(
3132
publishableKey: String,
3233
urlBase: URL = URL(string: "https://api.snapauth.app")!
@@ -223,6 +224,7 @@ public class SnapAuth: NSObject { // NSObject for ASAuthorizationControllerDeleg
223224
}
224225
}
225226

227+
/// A representation of the user that is trying to authenticate.
226228
public enum AuthenticatingUser {
227229
/// Your application's internal identifier for the user (usually a primary key)
228230
case id(String)

Sources/SnapAuth/SnapAuthDelegate.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import Foundation
22

3+
/// The success case of adding or using a passkey.
4+
///
5+
/// `SnapAuthTokenInfo` is the result of a successful authentication or credential registration.
6+
///
7+
/// This holds a short-lived token which should be sent to your application's backend for verifcation and use.
8+
///
9+
/// The token on its own does not authenticate a user; instead, the token must be sent to your application's backend for processing and verification.
10+
/// Tokens are short-lived and one-time-use.
11+
///
12+
/// See our [server documentation](https://docs.snapauth.app/server.html) for additional info on how to use these tokens.
313
public struct SnapAuthTokenInfo {
414
/// The registration or authentication token.
515
///
@@ -10,9 +20,10 @@ public struct SnapAuthTokenInfo {
1020

1121
/// When the paired token will expire.
1222
///
13-
/// If you try to use it after this time (or more than once), the request
23+
/// If you try to use it after this time, or more than once, the request
1424
/// will be rejected.
1525
public let expiresAt: Date
1626
}
1727

28+
/// An alias for the native `Result` type with our success and failure states.
1829
public typealias SnapAuthResult = Result<SnapAuthTokenInfo, SnapAuthError>

0 commit comments

Comments
 (0)