File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ // Generated using Sourcery 2.0.2 — https://github.com/krzysztofzablocki/Sourcery
2+ // DO NOT EDIT
3+ import Combine
4+ import Foundation
5+
6+ public extension StytchClient . OAuth . Apple {
7+ /// This function is intended for rare cases where you must authenticate with Apple only and collect the JWT.
8+ /// This function will not create a Stytch user.
9+ func authenticateWithApple( completion: @escaping Completion < String > ) {
10+ Task {
11+ do {
12+ completion ( . success( try await authenticateWithApple ( ) ) )
13+ } catch {
14+ completion ( . failure( error) )
15+ }
16+ }
17+ }
18+
19+ /// This function is intended for rare cases where you must authenticate with Apple only and collect the JWT.
20+ /// This function will not create a Stytch user.
21+ func authenticateWithApple( ) -> AnyPublisher < String , Error > {
22+ return Deferred {
23+ Future ( { promise in
24+ Task {
25+ do {
26+ promise ( . success( try await authenticateWithApple ( ) ) )
27+ } catch {
28+ promise ( . failure( error) )
29+ }
30+ }
31+ } )
32+ }
33+ . eraseToAnyPublisher ( )
34+ }
35+ }
Original file line number Diff line number Diff line change @@ -59,6 +59,21 @@ public extension StytchClient.OAuth {
5959
6060 return authenticateResponse
6161 }
62+
63+ // sourcery: AsyncVariants, (NOTE: - must use /// doc comment styling)
64+ /// This function is intended for rare cases where you must authenticate with Apple only and collect the JWT.
65+ /// This function will not create a Stytch user.
66+ public func authenticateWithApple( ) async throws -> String {
67+ let rawNonce = try cryptoClient. dataWithRandomBytesOfCount ( 32 ) . toHexString ( )
68+
69+ let authenticateResult = try await appleOAuthClient. authenticate (
70+ configureController: { _ in } ,
71+ nonce: cryptoClient. sha256 ( Data ( rawNonce. utf8) ) . base64EncodedString ( )
72+ )
73+
74+ // the idToken is the JWT
75+ return authenticateResult. idToken
76+ }
6277 }
6378}
6479
You can’t perform that action at this time.
0 commit comments