Contents

AuthorizationController

A SwiftUI environment value that views use to perform authorization requests.

Declaration

@MainActor struct AuthorizationController

Overview

To access an instance of this type, use the SwiftUI Environment property wrapper and specify authorizationController as the environment value, as the following example shows:

struct AuthorizationControllerExample: View {
    // Get an instance of AuthorizationController using SwiftUI's @Environment 
    // property wrapper.
    @Environment(\.authorizationController) private var authorizationController

    var body: some View {
        Button("Sign In") {
            Task {
                do {
                    // Create the authorization request.
                    async let request = makeAuthorizationRequest()
                    // Perform the request and await its result.
                    let result = try await authorizationController
                        .performRequest(request)
                    switch result {
                        // Process the request's result.
                    }
                } catch {
                    // Respond to any authorization errors.
                }
            }
        }
    }
}

Topics

Performing requests

Performing assisted requests

See Also

Authorization requests