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.3
Composable component built with TCA for handling Sign in with Apple
⭐️ 2
🕓 4 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/msigsbey/ComposableAuthorizationProvider.git", from: "v0.1.3")

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 Environment

public struct SomeEnvironment {
    public var authorizationProvider: AuthorizationProvider
    
    public init(
        authorizationProvider: AuthorizationProvider = .live
    ) {
        self.authorizationProvider = authorizationProvider
    }
}

Step 2 - Add to actions

public enum SomeAction: Equatable {
    case someAction
    case someSignInAction
    case authorizationProvider(AuthorizationControllerClient.DelegateEvent)
}

Step 3 - Add logic to reducer

public let reducer = Reducer<SomeState, SomeAction, SomeEnvironment>.combine(
    Reducer { state, action, environment in
        switch action {
        case .someAction:
            return environment.authorizationProvider.getCredentialState("someUserId").eraseToEffect().map { state in
                // TODO: Decide when you want to perform credential challenges
                
                // Make a credential challenge
                environment.authorizationProvider.authorizationController.performRequest(.default).map(SomeAction.authorizationProvider)
            }
        case .someSignInAction:
            // Make a credential challenge
            return environment.authorizationProvider.authorizationController.performRequest(.default).map(SomeAction.authorizationProvider)
        }
    },
    ...
)

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 {
                            self.viewStore.send(.someSignInAction)
                        }
                }
            }
        }
    }

License

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

GitHub

link
Stars: 2
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v0.1.3
4 weeks ago

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