You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-3Lines changed: 49 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,6 +182,53 @@ pod 'OktaIdxAuth'
182
182
183
183
## Usage Guide
184
184
185
+
Every authentication flow follows the same two-method pattern defined by the
186
+
`AuthenticationFlow` protocol:
187
+
188
+
1.**`start()`** — initiates the flow (builds an authorize URL, sends
189
+
credentials, etc.) and returns either a token or an intermediate value
190
+
needed by the next step.
191
+
2.**`resume()`**_(optional)_ — completes a multi-step flow by exchanging the
192
+
intermediate value for tokens (e.g., trading an authorization code for an
193
+
access token, polling for device authorization, etc.).
194
+
195
+
Single-step flows such as Resource Owner, JWT Bearer, and Token Exchange
196
+
resolve entirely in `start()`. Multi-step flows like Authorization Code and
197
+
Device Authorization require a subsequent call to `resume()`.
198
+
199
+
All flows accept an optional **authentication context** that carries
200
+
cross-cutting parameters such as `audience`, `resource`, `nonce`, and
201
+
`maxAge`. See [Authentication Context](#authentication-context) below for
202
+
details.
203
+
204
+
### Authentication Context
205
+
206
+
All authentication flows accept an optional `context` parameter that carries cross-cutting authentication properties. Some flows require a specific context type (e.g., `AuthorizationCodeFlow.Context` for the Authorization Code flow), while simpler flows use `StandardAuthenticationContext`:
207
+
208
+
```swift
209
+
let flow =ResourceOwnerFlow(issuerURL: URL(string: "https://example.okta.com")!,
210
+
clientId: "abc123client",
211
+
scope: "openid offline_access email profile")
212
+
let token =tryawait flow.start(
213
+
username: "jane@example.com",
214
+
password: "secretPassword",
215
+
context: .init(
216
+
audience: "api://my-resource-server",
217
+
resource: "https://api.example.com/v1", // or an array of URIs
218
+
maxAge: 3600,
219
+
nonce: "custom-nonce"
220
+
)))
221
+
```
222
+
223
+
| Property | Type | Description |
224
+
| --- | --- | --- |
225
+
|`nonce`|`String?`| Custom nonce for ID token replay protection. |
226
+
|`maxAge`|`TimeInterval?`| Maximum authentication age (seconds). |
227
+
|`audience`|`String?`| Target resource server ([RFC 8707](https://datatracker.ietf.org/doc/html/rfc8707)). Sent in the token request. |
228
+
|`resource`|`[String]?`| Target resource URI(s) ([RFC 8707](https://datatracker.ietf.org/doc/html/rfc8707)). Sent in the token request. Accepts a string literal or an array of strings. |
229
+
|`acrValues`|`[String]?`| Requested Authentication Context Class Reference values. |
230
+
|`additionalParameters`|`[String: String]?`| Extra parameters forwarded to the token request. |
231
+
185
232
### Web Authentication using OIDC
186
233
187
234
The simplest way to integrate authentication in your app is with OIDC through a web browser, using the Authorization Code Flow grant.
@@ -263,8 +310,7 @@ When using the `device_sso` scope, your application can receive a "device secret
For more information, see the [OktaIdxAuth API documentation][oktaidxauth-docs].
320
-
366
+
321
367
## Storing and using tokens
322
368
323
369
Once your user has authenticated and you have a `Token` object, your application can store and use those credentials. The most direct approach is to use the `Credential.store(_:tags:security:)` function.
/// Common protocol that all ``AuthenticationFlow`` ``AuthenticationFlow/Context`` type aliases must conform to.
107
97
///
108
98
/// While instances of a particular ``AuthenticationFlow`` is configured for a particular OAuth2 client, the context supplied to the flow's `start` function represents the specific settings to customize an individual sign-in using that flow.
/// The values from this context that should be persisted into the ``Token/Context-swift.struct`` when the resulting token is created.
114
116
///
115
117
/// This is used to keep some data critical to the future lifecycle of the token associated with the object in storage, which may not be included in the final token response payload.
0 commit comments