react-native-oauth-essentials 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +20 -0
  2. package/OauthEssentials.podspec +22 -0
  3. package/README.md +30 -0
  4. package/android/build.gradle +74 -0
  5. package/android/src/main/AndroidManifest.xml +22 -0
  6. package/android/src/main/java/com/oauthessentials/CredentialError.kt +7 -0
  7. package/android/src/main/java/com/oauthessentials/CredentialFactory.kt +114 -0
  8. package/android/src/main/java/com/oauthessentials/CustomTabsActivity.kt +133 -0
  9. package/android/src/main/java/com/oauthessentials/OauthEssentialsModule.kt +603 -0
  10. package/android/src/main/java/com/oauthessentials/OauthEssentialsPackage.kt +33 -0
  11. package/android/src/main/java/com/oauthessentials/RCTPromiseSettler.kt +60 -0
  12. package/ios/AppleIdRetriever.swift +61 -0
  13. package/ios/CredentialError.swift +6 -0
  14. package/ios/CredentialFactory.swift +133 -0
  15. package/ios/CredentialsType.swift +7 -0
  16. package/ios/GoogleIdRetriever.swift +83 -0
  17. package/ios/HybridRetriever.swift +64 -0
  18. package/ios/OauthEssentials.h +8 -0
  19. package/ios/OauthEssentials.mm +104 -0
  20. package/ios/OauthEssentialsModule.swift +210 -0
  21. package/ios/PasskeyRetriever.swift +226 -0
  22. package/ios/PasswordRetriever.swift +72 -0
  23. package/ios/RCTPromiseSettler.swift +28 -0
  24. package/lib/module/NativeOauthEssentials.js +5 -0
  25. package/lib/module/NativeOauthEssentials.js.map +1 -0
  26. package/lib/module/index.js +148 -0
  27. package/lib/module/index.js.map +1 -0
  28. package/lib/module/package.json +1 -0
  29. package/lib/module/types.js +23 -0
  30. package/lib/module/types.js.map +1 -0
  31. package/lib/typescript/package.json +1 -0
  32. package/lib/typescript/src/NativeOauthEssentials.d.ts +60 -0
  33. package/lib/typescript/src/NativeOauthEssentials.d.ts.map +1 -0
  34. package/lib/typescript/src/index.d.ts +78 -0
  35. package/lib/typescript/src/index.d.ts.map +1 -0
  36. package/lib/typescript/src/types.d.ts +71 -0
  37. package/lib/typescript/src/types.d.ts.map +1 -0
  38. package/package.json +156 -0
  39. package/src/NativeOauthEssentials.ts +75 -0
  40. package/src/index.tsx +199 -0
  41. package/src/types.ts +79 -0
@@ -0,0 +1,226 @@
1
+ import AuthenticationServices
2
+ import React
3
+
4
+ @available(iOS 16.0, *)
5
+ public class PasskeyRetriever: RCTPromiseSettler,
6
+ ASAuthorizationControllerDelegate,
7
+ ASAuthorizationControllerPresentationContextProviding {
8
+
9
+ enum Mode {
10
+ case registration
11
+ case assertion
12
+ }
13
+
14
+ private let mode: Mode
15
+
16
+ init(
17
+ requestJson: String,
18
+ mode: Mode,
19
+ resolve: @escaping RCTPromiseResolveBlock,
20
+ reject: @escaping RCTPromiseRejectBlock,
21
+ emitEvent: ((String, NSDictionary) -> Void)?
22
+ ) {
23
+ self.mode = mode
24
+ super.init(resolve: resolve, reject: reject, emitEvent: emitEvent)
25
+
26
+ do {
27
+ let request = try buildRequest(requestJson: requestJson, mode: mode)
28
+ let controller = ASAuthorizationController(authorizationRequests: [request])
29
+ controller.delegate = self
30
+ controller.presentationContextProvider = self
31
+ controller.performRequests(options: .preferImmediatelyAvailableCredentials)
32
+ } catch {
33
+ reject(
34
+ CredentialError.invalidResult.rawValue,
35
+ "Failed to parse requestJson: \(error.localizedDescription)",
36
+ error
37
+ )
38
+ cleanup()
39
+ }
40
+ }
41
+
42
+ private func buildRequest(requestJson: String, mode: Mode) throws -> ASAuthorizationRequest {
43
+ guard let data = requestJson.data(using: .utf8),
44
+ let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] else {
45
+ throw NSError(domain: "PasskeyRetriever", code: -1, userInfo: [
46
+ NSLocalizedDescriptionKey: "Invalid requestJson"
47
+ ])
48
+ }
49
+
50
+ switch mode {
51
+ case .registration:
52
+ return try buildRegistrationRequest(json: json)
53
+ case .assertion:
54
+ return try buildAssertionRequest(json: json)
55
+ }
56
+ }
57
+
58
+ private func buildRegistrationRequest(json: [String: Any]) throws -> ASAuthorizationRequest {
59
+ guard let challengeStr = json["challenge"] as? String,
60
+ let challenge = base64URLDecode(challengeStr) else {
61
+ throw NSError(domain: "PasskeyRetriever", code: -1, userInfo: [
62
+ NSLocalizedDescriptionKey: "Missing or invalid challenge"
63
+ ])
64
+ }
65
+
66
+ guard let rp = json["rp"] as? [String: Any],
67
+ let rpId = rp["id"] as? String else {
68
+ throw NSError(domain: "PasskeyRetriever", code: -1, userInfo: [
69
+ NSLocalizedDescriptionKey: "Missing or invalid rp.id"
70
+ ])
71
+ }
72
+
73
+ guard let user = json["user"] as? [String: Any],
74
+ let userIdStr = user["id"] as? String,
75
+ let userId = base64URLDecode(userIdStr),
76
+ let userName = user["name"] as? String else {
77
+ throw NSError(domain: "PasskeyRetriever", code: -1, userInfo: [
78
+ NSLocalizedDescriptionKey: "Missing or invalid user fields"
79
+ ])
80
+ }
81
+
82
+ let provider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: rpId)
83
+ let request = provider.createCredentialRegistrationRequest(
84
+ challenge: challenge,
85
+ name: userName,
86
+ userID: userId
87
+ )
88
+
89
+ if let userVerification = json["authenticatorSelection"] as? [String: Any],
90
+ let uv = userVerification["userVerification"] as? String {
91
+ request.userVerificationPreference = mapUserVerification(uv)
92
+ }
93
+
94
+ if let attestation = json["attestation"] as? String {
95
+ request.attestationPreference = mapAttestation(attestation)
96
+ }
97
+
98
+ if let excludeCredentials = json["excludeCredentials"] as? [[String: Any]] {
99
+ request.excludedCredentials = excludeCredentials.compactMap { cred in
100
+ guard let idStr = cred["id"] as? String,
101
+ let idData = base64URLDecode(idStr) else { return nil }
102
+ return ASAuthorizationPlatformPublicKeyCredentialDescriptor(credentialID: idData)
103
+ }
104
+ }
105
+
106
+ return request
107
+ }
108
+
109
+ private func buildAssertionRequest(json: [String: Any]) throws -> ASAuthorizationRequest {
110
+ guard let challengeStr = json["challenge"] as? String,
111
+ let challenge = base64URLDecode(challengeStr) else {
112
+ throw NSError(domain: "PasskeyRetriever", code: -1, userInfo: [
113
+ NSLocalizedDescriptionKey: "Missing or invalid challenge"
114
+ ])
115
+ }
116
+
117
+ let rpId = json["rpId"] as? String ?? ""
118
+
119
+ let provider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: rpId)
120
+ let request = provider.createCredentialAssertionRequest(challenge: challenge)
121
+
122
+ if let allowCredentials = json["allowCredentials"] as? [[String: Any]] {
123
+ request.allowedCredentials = allowCredentials.compactMap { cred in
124
+ guard let idStr = cred["id"] as? String,
125
+ let idData = base64URLDecode(idStr) else { return nil }
126
+ return ASAuthorizationPlatformPublicKeyCredentialDescriptor(credentialID: idData)
127
+ }
128
+ }
129
+
130
+ if let uv = json["userVerification"] as? String {
131
+ request.userVerificationPreference = mapUserVerification(uv)
132
+ }
133
+
134
+ return request
135
+ }
136
+
137
+ // MARK: - ASAuthorizationControllerDelegate
138
+
139
+ public func authorizationController(
140
+ controller: ASAuthorizationController,
141
+ didCompleteWithAuthorization authorization: ASAuthorization
142
+ ) {
143
+ switch mode {
144
+ case .registration:
145
+ if let credential = authorization.credential as? ASAuthorizationPlatformPublicKeyCredentialRegistration {
146
+ let result = CredentialFactory.fromPasskeyRegistration(credential: credential)
147
+ self.resolve?(result)
148
+ self.emitEvent?("onCredentialSuccess", result as NSDictionary)
149
+ }
150
+ case .assertion:
151
+ if let credential = authorization.credential as? ASAuthorizationPlatformPublicKeyCredentialAssertion {
152
+ let result = CredentialFactory.fromPasskeyAssertion(credential: credential)
153
+ self.resolve?(result)
154
+ self.emitEvent?("onCredentialSuccess", result as NSDictionary)
155
+ }
156
+ }
157
+ cleanup()
158
+ }
159
+
160
+ public func authorizationController(
161
+ controller: ASAuthorizationController,
162
+ didCompleteWithError error: Error
163
+ ) {
164
+ let nsError = error as NSError
165
+ if nsError.domain == ASAuthorizationError.errorDomain,
166
+ nsError.code == ASAuthorizationError.canceled.rawValue {
167
+ let result = CredentialFactory.fromCancelled()
168
+ self.resolve?(result)
169
+ self.emitEvent?("onCredentialSuccess", result as NSDictionary)
170
+ } else {
171
+ self.reject?(
172
+ CredentialError.invalidResult.rawValue,
173
+ error.localizedDescription,
174
+ error
175
+ )
176
+ self.emitEvent?("onCredentialFailure", [
177
+ "code": CredentialError.invalidResult.rawValue,
178
+ "message": error.localizedDescription
179
+ ])
180
+ }
181
+ cleanup()
182
+ }
183
+
184
+ // MARK: - ASAuthorizationControllerPresentationContextProviding
185
+
186
+ public func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
187
+ return UIWindow()
188
+ }
189
+
190
+ // MARK: - Helpers
191
+
192
+ private func base64URLDecode(_ string: String) -> Data? {
193
+ var base64 = string
194
+ .replacingOccurrences(of: "-", with: "+")
195
+ .replacingOccurrences(of: "_", with: "/")
196
+ let remainder = base64.count % 4
197
+ if remainder > 0 {
198
+ base64.append(String(repeating: "=", count: 4 - remainder))
199
+ }
200
+ return Data(base64Encoded: base64)
201
+ }
202
+
203
+ private func mapUserVerification(_ value: String) -> ASAuthorizationPublicKeyCredentialUserVerificationPreference {
204
+ switch value {
205
+ case "required":
206
+ return .required
207
+ case "discouraged":
208
+ return .discouraged
209
+ default:
210
+ return .preferred
211
+ }
212
+ }
213
+
214
+ private func mapAttestation(_ value: String) -> ASAuthorizationPublicKeyCredentialAttestationKind {
215
+ switch value {
216
+ case "direct":
217
+ return .direct
218
+ case "indirect":
219
+ return .indirect
220
+ case "enterprise":
221
+ return .enterprise
222
+ default:
223
+ return .none
224
+ }
225
+ }
226
+ }
@@ -0,0 +1,72 @@
1
+ import React
2
+ import AuthenticationServices
3
+
4
+ public class PasswordRetriever: RCTPromiseSettler,
5
+ ASAuthorizationControllerDelegate,
6
+ ASAuthorizationControllerPresentationContextProviding {
7
+
8
+ override init(
9
+ resolve: @escaping RCTPromiseResolveBlock,
10
+ reject: @escaping RCTPromiseRejectBlock,
11
+ emitEvent: ((String, NSDictionary) -> Void)?
12
+ ) {
13
+ super.init(resolve: resolve, reject: reject, emitEvent: emitEvent)
14
+
15
+ let request = ASAuthorizationPasswordProvider().createRequest()
16
+ let controller = ASAuthorizationController(authorizationRequests: [request])
17
+ controller.delegate = self
18
+ controller.presentationContextProvider = self
19
+ if #available(iOS 16.0, *) {
20
+ controller.performRequests(options: .preferImmediatelyAvailableCredentials)
21
+ } else {
22
+ controller.performRequests()
23
+ }
24
+ }
25
+
26
+ public func authorizationController(
27
+ controller: ASAuthorizationController,
28
+ didCompleteWithAuthorization authorization: ASAuthorization
29
+ ) {
30
+ if let credential = authorization.credential as? ASPasswordCredential {
31
+ let result = CredentialFactory.fromPassword(credential: credential)
32
+ self.resolve?(result)
33
+ self.emitEvent?("onCredentialSuccess", result as NSDictionary)
34
+
35
+ cleanup()
36
+ }
37
+ }
38
+
39
+ public func authorizationController(
40
+ controller: ASAuthorizationController,
41
+ didCompleteWithError error: Error
42
+ ) {
43
+ let nsError = error as NSError
44
+ if nsError.domain == ASAuthorizationError.errorDomain,
45
+ nsError.code == ASAuthorizationError.canceled.rawValue {
46
+
47
+ let result = CredentialFactory.fromCancelled()
48
+ self.resolve?(result)
49
+ self.emitEvent?("onCredentialSuccess", result as NSDictionary)
50
+ } else {
51
+ self.reject?(
52
+ CredentialError.invalidResult.rawValue,
53
+ error.localizedDescription,
54
+ error
55
+ )
56
+ self.emitEvent?("onCredentialFailure", [
57
+ "code": CredentialError.invalidResult.rawValue,
58
+ "message": error.localizedDescription
59
+ ])
60
+ }
61
+
62
+ self.cleanup()
63
+ }
64
+
65
+ public func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
66
+ return UIWindow()
67
+ }
68
+
69
+ func getIsSettled() -> Bool {
70
+ return resolve == nil || reject == nil
71
+ }
72
+ }
@@ -0,0 +1,28 @@
1
+ import React
2
+
3
+ public typealias EventEmitter = ((_ eventName: String, _ body: [String: Any]) -> Void)?
4
+ public class RCTPromiseSettler: NSObject {
5
+ internal var resolve: RCTPromiseResolveBlock?
6
+ internal var reject: RCTPromiseRejectBlock?
7
+ internal var emitEvent: ((String, NSDictionary) -> Void)?
8
+
9
+ init(
10
+ resolve: @escaping RCTPromiseResolveBlock,
11
+ reject: @escaping RCTPromiseRejectBlock,
12
+ emitEvent: ((String, NSDictionary) -> Void)?
13
+ ) {
14
+ self.resolve = resolve
15
+ self.reject = reject
16
+ self.emitEvent = emitEvent
17
+ }
18
+
19
+ public func settled() -> Bool {
20
+ return self.resolve == nil && self.reject == nil
21
+ }
22
+
23
+ internal func cleanup() -> Void {
24
+ self.resolve = nil
25
+ self.reject = nil
26
+ self.emitEvent = nil
27
+ }
28
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('OauthEssentials');
5
+ //# sourceMappingURL=NativeOauthEssentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOauthEssentials.ts"],"mappings":";;AAAA,SAGEA,mBAAmB,QACd,cAAc;AA4DrB,eAAeA,mBAAmB,CAACC,YAAY,CAAO,iBAAiB,CAAC","ignoreList":[]}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ import OauthEssentials from "./NativeOauthEssentials.js";
4
+ import { Platform } from 'react-native';
5
+ import { CredentialsType } from "./types.js";
6
+ export * from "./types.js";
7
+ const APPLE_ID_CACHED_RESULTS = new Map();
8
+
9
+ /**
10
+ * Performs the google sign in.
11
+ * @param webClientId
12
+ * @param options
13
+ *
14
+ * You should rely on GOOGLE_ID_SUPPORTED constant to check if you can use this method.
15
+ * [Available on Android and IOS].
16
+ */
17
+ export async function googleSignIn(webClientId, options) {
18
+ return await OauthEssentials.googleSignIn(webClientId, parseGoogleIdOptions(options));
19
+ }
20
+
21
+ /**
22
+ * Gets the stored password.
23
+ * If does not have an stored password, returns false.
24
+ *
25
+ * You should rely on PASSWORD_SUPPORTED constant to check if you can use this method.
26
+ * [Available on Android and IOS].
27
+ */
28
+ export async function getPassword() {
29
+ const result = await OauthEssentials.getPassword();
30
+ return result || false;
31
+ }
32
+
33
+ /**
34
+ * Performs the password sign in.
35
+ * Cannot be a already stored password.
36
+ * @param {string} username
37
+ * @param {string} password
38
+ *
39
+ * You should rely on PASSWORD_SUPPORTED constant to check if you can use this method.
40
+ * [Available on Android and IOS].
41
+ */
42
+ export async function passwordSignIn(username, password) {
43
+ return await OauthEssentials.passwordSignIn(username, password);
44
+ }
45
+
46
+ /**
47
+ * Initiates the Apple Sign-In process.
48
+ * On IOS devices it handles it smoothly using the latest UI workflow.
49
+ * On Android it dispatches the androidWebUrl to device default browser for handling it.
50
+ * you need to implement on your backend the redirect logic and validation accordingly to the link below
51
+ * @see [Apple Sign In REST API Documentation](https://developer.apple.com/documentation/signinwithapplerestapi)
52
+ *
53
+ * @param {string} androidWebUrl - The web URL on Android where the user will complete the OAuth flow. **[Android only]**
54
+ *
55
+ * @returns {AppleIdCredentialResult|WebAppleIdCredentialResult} Returns AppleIdCredentialResult on IOS devices and WebAppleIdCredentialResult on android.
56
+ */
57
+ export async function appleSignIn(androidWebUrl) {
58
+ const result = await OauthEssentials.appleSignIn(Platform.select({
59
+ ios: undefined,
60
+ android: androidWebUrl
61
+ }));
62
+ if (result.type === CredentialsType.APPLE_ID) {
63
+ if (APPLE_ID_CACHED_RESULTS.has(result.data.user)) {
64
+ // Reuse the fullName and email provided
65
+ const cached = APPLE_ID_CACHED_RESULTS.get(result.data.user);
66
+ const data = result.data;
67
+ if (!data.fullName) {
68
+ data.fullName = cached.fullName;
69
+ }
70
+ if (!data.email) {
71
+ data.email = cached.email;
72
+ }
73
+ } else {
74
+ APPLE_ID_CACHED_RESULTS.set(result.data.user, result.data);
75
+ }
76
+ return result;
77
+ } else {
78
+ return result;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Performs all sign in methods available on the platform at once.
84
+ * This is supposed to be used on app start to get any existing sign in.
85
+ */
86
+ export async function hybridSignIn(googleClientId, options) {
87
+ return await OauthEssentials.hybridSignIn(googleClientId, parseGoogleIdOptions(options));
88
+ }
89
+
90
+ /**
91
+ * Creates a passkey.
92
+ * @param options
93
+ */
94
+ export async function createPassKey(options) {
95
+ return await OauthEssentials.createPassKey(options);
96
+ }
97
+ function parseGoogleIdOptions(options) {
98
+ const bridgeOptions = {
99
+ authorizedAccounts: false,
100
+ autoSelectEnabled: false
101
+ };
102
+ const hasOptions = options && typeof options === 'object' && Object.keys(options).length > 0;
103
+ if (hasOptions) {
104
+ if (Platform.OS === 'android') {
105
+ if (options.hasOwnProperty('authorizedAccounts')) {
106
+ bridgeOptions.authorizedAccounts = options.authorizedAccounts === true;
107
+ }
108
+ if (options.hasOwnProperty('autoSelectEnabled')) {
109
+ bridgeOptions.autoSelectEnabled = options.autoSelectEnabled === true;
110
+ }
111
+ }
112
+ }
113
+ return bridgeOptions;
114
+ }
115
+ const CONSTANTS = OauthEssentials.getConstants();
116
+
117
+ /**
118
+ * Google Play are supported.
119
+ * It always false on IOS, cause IOS does not use Google Play Services.
120
+ */
121
+ export const GOOGLE_PLAY_SERVICES_SUPPORTED = CONSTANTS.GOOGLE_PLAY_SERVICES_SUPPORTED;
122
+
123
+ /**
124
+ * The password method is supported.
125
+ */
126
+ export const PASSWORD_SUPPORTED = CONSTANTS.PASSWORD_SUPPORTED;
127
+
128
+ /**
129
+ * Google Play id sign in is supported.
130
+ * You should mainly rely on this constant to check if you can use google sign in.
131
+ */
132
+ export const GOOGLE_ID_SUPPORTED = CONSTANTS.GOOGLE_ID_SUPPORTED;
133
+
134
+ /**
135
+ * Gets if Apple id sign in is supported.
136
+ */
137
+ export const APPLE_ID_SUPPORTED = CONSTANTS.APPLE_ID_SUPPORTED;
138
+
139
+ /**
140
+ * Gets if "hybrid" is supported in this platform.
141
+ */
142
+ export const HYBRID_SUPPORTED = CONSTANTS.HYBRID_SUPPORTED;
143
+
144
+ /**
145
+ * Gets if passkeys are supported.
146
+ */
147
+ export const PASSKEYS_SUPPORTED = CONSTANTS.PASSKEYS_SUPPORTED;
148
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OauthEssentials","Platform","CredentialsType","APPLE_ID_CACHED_RESULTS","Map","googleSignIn","webClientId","options","parseGoogleIdOptions","getPassword","result","passwordSignIn","username","password","appleSignIn","androidWebUrl","select","ios","undefined","android","type","APPLE_ID","has","data","user","cached","get","fullName","email","set","hybridSignIn","googleClientId","createPassKey","bridgeOptions","authorizedAccounts","autoSelectEnabled","hasOptions","Object","keys","length","OS","hasOwnProperty","CONSTANTS","getConstants","GOOGLE_PLAY_SERVICES_SUPPORTED","PASSWORD_SUPPORTED","GOOGLE_ID_SUPPORTED","APPLE_ID_SUPPORTED","HYBRID_SUPPORTED","PASSKEYS_SUPPORTED"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,eAAe,MAAM,4BAAyB;AACrD,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAGEC,eAAe,QAOV,YAAS;AAEhB,cAAc,YAAS;AACvB,MAAMC,uBAAuB,GAAG,IAAIC,GAAG,CAGrC,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAChCC,WAAmB,EACnBC,OAA6B,EACkC;EAC/D,OAAQ,MAAMP,eAAe,CAACK,YAAY,CACxCC,WAAW,EACXE,oBAAoB,CAACD,OAAO,CAC9B,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeE,WAAWA,CAAA,EAA8C;EAC7E,MAAMC,MAAM,GAAG,MAAMV,eAAe,CAACS,WAAW,CAAC,CAAC;EAClD,OAAQC,MAAM,IAAiC,KAAK;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,cAAcA,CAClCC,QAAgB,EAChBC,QAAgB,EACE;EAClB,OAAO,MAAMb,eAAe,CAACW,cAAc,C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
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ export let CredentialsType = /*#__PURE__*/function (CredentialsType) {
4
+ CredentialsType["GOOGLE_ID"] = "GOOGLE_ID";
5
+ // GoogleId credentials type
6
+ CredentialsType["PASSWORD"] = "PASSWORD";
7
+ // Password credentials type
8
+ CredentialsType["APPLE_ID"] = "APPLE_ID";
9
+ // IOS AppleId credentials type
10
+ CredentialsType["WEB_APPLE_ID"] = "WEB_APPLE_ID";
11
+ // Android AppleId credentials type
12
+ CredentialsType["CANCELLED"] = "CANCELLED";
13
+ // type when the user cancels it
14
+ CredentialsType["PASSKEY"] = "PASSKEY"; // Passkey credential type
15
+ return CredentialsType;
16
+ }({});
17
+ export let CredentialError = /*#__PURE__*/function (CredentialError) {
18
+ CredentialError["NO_PLAY_SERVICES_ERROR"] = "NO_PLAY_SERVICES_ERROR";
19
+ CredentialError["NO_ACTIVITY_ERROR"] = "NO_ACTIVITY_ERROR";
20
+ CredentialError["INVALID_RESULT_ERROR"] = "INVALID_RESULT_ERROR";
21
+ return CredentialError;
22
+ }({});
23
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CredentialsType","CredentialError"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;AAiEA,WAAYA,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EACA;EADfA,eAAe;EAEF;EAFbA,eAAe;EAGF;EAHbA,eAAe;EAIM;EAJrBA,eAAe;EAKA;EALfA,eAAe,yBAMJ;EAAA,OANXA,eAAe;AAAA;AAS3B,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,60 @@
1
+ import { type CodegenTypes, type TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ readonly onCredentialSuccess: CodegenTypes.EventEmitter<CredentialSuccessEvent>;
4
+ readonly onCredentialFailure: CodegenTypes.EventEmitter<CredentialErrorEvent>;
5
+ getConstants(): {
6
+ readonly GOOGLE_PLAY_SERVICES_SUPPORTED: boolean;
7
+ readonly PASSWORD_SUPPORTED: boolean;
8
+ readonly GOOGLE_ID_SUPPORTED: boolean;
9
+ readonly APPLE_ID_SUPPORTED: boolean;
10
+ readonly HYBRID_SUPPORTED: boolean;
11
+ readonly PASSKEYS_SUPPORTED: boolean;
12
+ };
13
+ /**
14
+ * Performs the google sign in.
15
+ * @param androidAndIOSClientId
16
+ * @param options
17
+ */
18
+ googleSignIn(androidAndIOSClientId: string, options: Object): Promise<Object>;
19
+ /**
20
+ * Sign ins with apple.
21
+ * @param androidWebUrl
22
+ */
23
+ appleSignIn(androidWebUrl?: string): Promise<Object>;
24
+ /**
25
+ * Saves the username/password credential
26
+ * @param username
27
+ * @param password
28
+ */
29
+ passwordSignIn(username: string, password: string): Promise<boolean>;
30
+ /**
31
+ * Gets the saved password.
32
+ */
33
+ getPassword(): Promise<Object>;
34
+ /**
35
+ * Performs the called so "hybrid sign in"
36
+ * @param googleClientId
37
+ * @param options
38
+ */
39
+ hybridSignIn(googleClientId: string, options: Object): Promise<Object>;
40
+ /**
41
+ * Creates the passkey.
42
+ */
43
+ createPassKey(options: Object): Promise<Object>;
44
+ /**
45
+ * Gets the passkey
46
+ * @param options
47
+ */
48
+ getPassKey(options: Object): Promise<Object>;
49
+ }
50
+ declare const _default: Spec;
51
+ export default _default;
52
+ type CredentialSuccessEvent = {
53
+ type: string;
54
+ data: Object;
55
+ };
56
+ type CredentialErrorEvent = {
57
+ code: string;
58
+ message: string;
59
+ };
60
+ //# sourceMappingURL=NativeOauthEssentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeOauthEssentials.d.ts","sourceRoot":"","sources":["../../../src/NativeOauthEssentials.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KA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,sBAAsB,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { type AppleIdCredentialResult, type CancelledCredentialResult, type GoogleIdCredentialResult, type GoogleSignInOptions, type PassKeyCredentialResult, type PasskeyOptions, type PasswordCredentialResult, type WebAppleIdCredentialResult } from './types';
2
+ export * from './types';
3
+ /**
4
+ * Performs the google sign in.
5
+ * @param webClientId
6
+ * @param options
7
+ *
8
+ * You should rely on GOOGLE_ID_SUPPORTED constant to check if you can use this method.
9
+ * [Available on Android and IOS].
10
+ */
11
+ export declare function googleSignIn(webClientId: string, options?: GoogleSignInOptions): Promise<GoogleIdCredentialResult | CancelledCredentialResult>;
12
+ /**
13
+ * Gets the stored password.
14
+ * If does not have an stored password, returns false.
15
+ *
16
+ * You should rely on PASSWORD_SUPPORTED constant to check if you can use this method.
17
+ * [Available on Android and IOS].
18
+ */
19
+ export declare function getPassword(): Promise<false | PasswordCredentialResult>;
20
+ /**
21
+ * Performs the password sign in.
22
+ * Cannot be a already stored password.
23
+ * @param {string} username
24
+ * @param {string} password
25
+ *
26
+ * You should rely on PASSWORD_SUPPORTED constant to check if you can use this method.
27
+ * [Available on Android and IOS].
28
+ */
29
+ export declare function passwordSignIn(username: string, password: string): Promise<boolean>;
30
+ /**
31
+ * Initiates the Apple Sign-In process.
32
+ * On IOS devices it handles it smoothly using the latest UI workflow.
33
+ * On Android it dispatches the androidWebUrl to device default browser for handling it.
34
+ * you need to implement on your backend the redirect logic and validation accordingly to the link below
35
+ * @see [Apple Sign In REST API Documentation](https://developer.apple.com/documentation/signinwithapplerestapi)
36
+ *
37
+ * @param {string} androidWebUrl - The web URL on Android where the user will complete the OAuth flow. **[Android only]**
38
+ *
39
+ * @returns {AppleIdCredentialResult|WebAppleIdCredentialResult} Returns AppleIdCredentialResult on IOS devices and WebAppleIdCredentialResult on android.
40
+ */
41
+ export declare function appleSignIn(androidWebUrl?: string): Promise<AppleIdCredentialResult | WebAppleIdCredentialResult>;
42
+ /**
43
+ * Performs all sign in methods available on the platform at once.
44
+ * This is supposed to be used on app start to get any existing sign in.
45
+ */
46
+ export declare function hybridSignIn(googleClientId: string, options?: GoogleSignInOptions): Promise<AppleIdCredentialResult | GoogleIdCredentialResult | PasswordCredentialResult | CancelledCredentialResult>;
47
+ /**
48
+ * Creates a passkey.
49
+ * @param options
50
+ */
51
+ export declare function createPassKey(options: PasskeyOptions): Promise<PassKeyCredentialResult>;
52
+ /**
53
+ * Google Play are supported.
54
+ * It always false on IOS, cause IOS does not use Google Play Services.
55
+ */
56
+ export declare const GOOGLE_PLAY_SERVICES_SUPPORTED: boolean;
57
+ /**
58
+ * The password method is supported.
59
+ */
60
+ export declare const PASSWORD_SUPPORTED: boolean;
61
+ /**
62
+ * Google Play id sign in is supported.
63
+ * You should mainly rely on this constant to check if you can use google sign in.
64
+ */
65
+ export declare const GOOGLE_ID_SUPPORTED: boolean;
66
+ /**
67
+ * Gets if Apple id sign in is supported.
68
+ */
69
+ export declare const APPLE_ID_SUPPORTED: boolean;
70
+ /**
71
+ * Gets if "hybrid" is supported in this platform.
72
+ */
73
+ export declare const HYBRID_SUPPORTED: boolean;
74
+ /**
75
+ * Gets if passkeys are supported.
76
+ */
77
+ export declare const PASSKEYS_SUPPORTED: boolean;
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAE9B,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAChC,MAA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