ComposableAuthorizationProvider is a composable component built with the Swift Composable Architecture for handling Sign in with Apple on iOS, macOS, tvOS.
ComposableAuthorizationProvider is available via Swift Package Manager
ComposableAuthorizationProvider
gives you access to a new provider called AuthorizationProvider
. It can be integrated within your composable app like this:
public struct SomeReducer {
@Dependency(\.authorizationProvider) var authorizationProvider
}
public enum Action: Equatable {
/// Triggers existing credential check
case someAction
/// Triggers sign in flow
case someSignInAction
/// Handles ``AuthorizationProvider`` responses
case authorizationProvider(AuthorizationControllerClient.AuthorizationEvent)
}
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))
}
}
},
...
)
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)
}
}
}
}
}
ComposableAuthorizationProvider is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 3 |
Last commit: 4 weeks ago |
Full Changelog: https://github.com/msigsbey/ComposableAuthorizationProvider/compare/1.0.0...1.0.1
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics