OidcDeviceClient
public class OidcDeviceClient : @unchecked Sendable
A client that implements the RFC 8628 Device Authorization Grant (requesting-device side).
Use OidcDeviceClient when the device cannot open a browser directly
(e.g., a smart TV or CLI tool). Call deviceAuthorization() to start the
flow and receive a stream of DeviceFlowStatus updates. The stream yields
.started with the userCode and verificationUri to display, then
.polling on each poll, and finally .success, .accessDenied, or
.expired when the flow resolves.
Important
OidcClientConfig is marked @unchecked Sendable and contains mutable
var fields. Do not mutate the config after passing it to this initializer — the
polling loop captures the config and reads it from a background thread.
-
Initializes a new
OidcDeviceClient.Declaration
Swift
public init(config: OidcClientConfig)Parameters
configThe OIDC client configuration to use.
-
Creates an
OidcDeviceClientusing the provided configuration block.Declaration
Swift
public static func createOidcDeviceClient(block: (OidcClientConfig) -> Void) -> OidcDeviceClientParameters
blockA closure to configure the
OidcClientConfig.Return Value
A fully configured
OidcDeviceClient. -
Creates an
OidcDeviceClientfrom a unified JSON configuration dictionary.Parses and validates the platform-neutral schema and delegates to
createOidcDeviceClient(block:)with the extracted values. Unknown fields are silently ignored for forward compatibility.Endpoint overrides (e.g.
deviceAuthorizationEndpoint) are expressed as anopenIdsub-object insideoidcand applied after OIDC discovery completes, mirroring theopenIdOverrideclosure onOidcClientConfig.Declaration
Swift
public static func createOidcDeviceClient(json: [String : Any]) -> Result<OidcDeviceClient, Error>Parameters
jsonA
[String: Any]dictionary conforming to the unified SDK configuration schema.Return Value
.success(OidcDeviceClient)on valid input,.failure(JsonConfigError)if a required field is absent or a field has the wrong type.
-
deviceAuthorization()AsynchronousStarts the RFC 8628 device authorization flow.
- Calls
config.oidcInitialize()to set up the HTTP client and discover endpoints. - POSTs to the
device_authorization_endpointto obtain aDeviceAuthorizationResponse.
Throws
OidcError.unknownif the discovered configuration does not include a device authorization endpoint;OidcError.apiErrorif the initial POST fails.Declaration
Swift
public func deviceAuthorization() async throws -> AsyncThrowingStream<DeviceFlowStatus, Error>Return Value
An
AsyncThrowingStream<DeviceFlowStatus, Error>. - Calls
-
authorize(verificationUriComplete:Asynchronous) Opens the
verificationUriCompleteURL in anSFSafariViewControllerso the user can approve the device flow on this device. Suspends until the browser is dismissed (either via the redirect callback or because the user closed it); the polling loop indeviceAuthorization()continues independently while this method is awaiting.Throws
OidcError.unknownifverificationUriCompleteis not a valid URL orconfig.redirectUrihas no scheme;BrowserError.externalUserAgentCancelledif the user closed the browser before completing the flow, or any other error surfaced byBrowserLauncher.Declaration
Swift
public func authorize(verificationUriComplete: String) async throwsParameters
verificationUriCompleteThe verification URI (including
user_code) returned in theDeviceAuthorizationResponse.
-
revoke()AsynchronousRevokes the stored token by delegating to
OidcClient.Declaration
Swift
public func revoke() async
View on GitHub