Swiftpack.co - msigsbey/ComposableAuthorizationProvider as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by msigsbey.
msigsbey/ComposableAuthorizationProvider v0.1.4
Composable component built with TCA for handling Sign in with Apple
⭐️ 3
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/msigsbey/ComposableAuthorizationProvider.git", from: "v0.1.4")

ComposableAuthorizationProvider

GitHub tag (latest by date) Swift Package Manager Swift5 Platform GitHub repo size

ComposableAuthorizationProvider is a composable component built with the Swift Composable Architecture for handling Sign in with Apple on iOS, macOS, tvOS.

Integration

ComposableAuthorizationProvider is available via Swift Package Manager

Usage

ComposableAuthorizationProvider gives you access to a new provider called AuthorizationProvider. It can be integrated within your composable app like this:

Step 1 - Add to Reducer

public struct SomeReducer {
    @Dependency(\.authorizationProvider) var authorizationProvider
}

Step 2 - Add to actions

public enum Action: Equatable {
    /// Triggers existing credential check
    case someAction
    /// Triggers sign in flow
    case someSignInAction
    /// Handles ``AuthorizationProvider`` responses
    case authorizationProvider(AuthorizationControllerClient.AuthorizationEvent)
}

Step 3 - Add logic to reducer

public var body: some Reducer<State, Action> {
    Reduce { state, action in
        switch action {
        case .someAction:
            return .run { send in 
                // Get current state
                let state = await authorizationProvider.getCredentialState("someUserId")
                
                // TODO: Decide when you want to perform credential challenges
                
                // Make a credential challenge
                let authorization = try? await authorizationProvider.authorizationController.performRequest(.standard)
                return .send(.authorizationProvider(authorization))
            }
        case .someSignInAction:
            return .run { send in
                // Make a credential challenge
                let authorization = try? await authorizationProvider.authorizationController.performRequest(.standard).map(SomeAction.authorizationProvider)
                return .send(.authorizationProvider(authorization))
            }
        }
    },
    ...
)

Step 4 - Add the sign in button to a view

public var body: some View {
    ZStack{
        Color.accentColor.edgesIgnoringSafeArea(.all)
        VStack {
            Spacer()
            if viewStore.loginButtonVisible {
                SignInWithAppleButton(type: .default, style: .white)
                    .frame(width: UIScreen.main.bounds.width / 2, height: 30)
                    .onTapGesture {
                        // Send the sign in flow action when pressed
                        self.viewStore.send(.someSignInAction)
                    }
            }
        }
    }
}

License

ComposableAuthorizationProvider is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 3
Last commit: 22 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics