react-native-credentials-manager 0.8.1 → 0.9.0
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.
|
@@ -6,6 +6,7 @@ import androidx.credentials.exceptions.GetCredentialException
|
|
|
6
6
|
import androidx.credentials.exceptions.NoCredentialException
|
|
7
7
|
import com.credentialsmanager.handlers.CredentialHandler
|
|
8
8
|
import com.credentialsmanager.handlers.ErrorHandler
|
|
9
|
+
import com.facebook.react.bridge.Arguments
|
|
9
10
|
import com.facebook.react.bridge.Promise
|
|
10
11
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
12
|
import com.facebook.react.bridge.ReadableArray
|
|
@@ -68,11 +69,11 @@ class CredentialsManagerModule(
|
|
|
68
69
|
credentialHandler.createPassword(username, password)
|
|
69
70
|
|
|
70
71
|
// Create success response
|
|
71
|
-
val result =
|
|
72
|
-
"type"
|
|
73
|
-
"username"
|
|
74
|
-
"success"
|
|
75
|
-
|
|
72
|
+
val result = Arguments.createMap().apply {
|
|
73
|
+
putString("type", "password")
|
|
74
|
+
putString("username", username)
|
|
75
|
+
putBoolean("success", true)
|
|
76
|
+
}
|
|
76
77
|
promise.resolve(result)
|
|
77
78
|
} catch (e: CreateCredentialException) {
|
|
78
79
|
ErrorHandler.handleCredentialError(e)
|
|
@@ -6,6 +6,7 @@ import androidx.credentials.exceptions.GetCredentialException
|
|
|
6
6
|
import androidx.credentials.exceptions.NoCredentialException
|
|
7
7
|
import com.credentialsmanager.handlers.CredentialHandler
|
|
8
8
|
import com.credentialsmanager.handlers.ErrorHandler
|
|
9
|
+
import com.facebook.react.bridge.Arguments
|
|
9
10
|
import com.facebook.react.bridge.Promise
|
|
10
11
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
12
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
@@ -74,11 +75,11 @@ class CredentialsManagerModule(
|
|
|
74
75
|
credentialHandler.createPassword(username, password)
|
|
75
76
|
|
|
76
77
|
// Create success response
|
|
77
|
-
val result =
|
|
78
|
-
"type"
|
|
79
|
-
"username"
|
|
80
|
-
"success"
|
|
81
|
-
|
|
78
|
+
val result = Arguments.createMap().apply {
|
|
79
|
+
putString("type", "password")
|
|
80
|
+
putString("username", username)
|
|
81
|
+
putBoolean("success", true)
|
|
82
|
+
}
|
|
82
83
|
promise.resolve(result)
|
|
83
84
|
} catch (e: CreateCredentialException) {
|
|
84
85
|
ErrorHandler.handleCredentialError(e)
|
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
#import <React/RCTLog.h>
|
|
4
4
|
#import <AuthenticationServices/AuthenticationServices.h>
|
|
5
5
|
|
|
6
|
+
static NSArray<NSString *> *RNCMNSArrayFromLazyStringVector(const facebook::react::LazyVector<NSString *> &vec)
|
|
7
|
+
{
|
|
8
|
+
NSMutableArray<NSString *> *result = [NSMutableArray arrayWithCapacity:vec.size()];
|
|
9
|
+
for (size_t i = 0, n = vec.size(); i < n; i++) {
|
|
10
|
+
NSString *value = vec.at(i);
|
|
11
|
+
if (value != nil) {
|
|
12
|
+
[result addObject:value];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@interface CredentialsManager ()
|
|
19
|
+
- (NSArray<ASAuthorizationScope> *)appleAuthorizationScopesFromJSScopes:(NSArray<NSString *> *)scopes;
|
|
20
|
+
- (void)configureAppleIDRequest:(ASAuthorizationAppleIDRequest *)request
|
|
21
|
+
nonce:(NSString *)nonce
|
|
22
|
+
requestedScopes:(NSArray<NSString *> *)requestedScopes;
|
|
23
|
+
@end
|
|
24
|
+
|
|
6
25
|
@implementation CredentialsManager
|
|
7
26
|
|
|
8
27
|
RCT_EXPORT_MODULE()
|
|
@@ -119,6 +138,14 @@ preferImmediatelyAvailableCredentials:(BOOL)preferImmediatelyAvailableCredential
|
|
|
119
138
|
reject:(RCTPromiseRejectBlock)reject {
|
|
120
139
|
|
|
121
140
|
id passkeyParams = params.passkeys();
|
|
141
|
+
|
|
142
|
+
NSString *appleNonce = nil;
|
|
143
|
+
NSArray<NSString *> *appleRequestedScopes = nil;
|
|
144
|
+
std::optional<JS::NativeCredentialsManager::AppleSignInParams> appleSignIn = params.appleSignIn();
|
|
145
|
+
if (appleSignIn.has_value()) {
|
|
146
|
+
appleNonce = appleSignIn->nonce();
|
|
147
|
+
appleRequestedScopes = RNCMNSArrayFromLazyStringVector(appleSignIn->requestedScopes());
|
|
148
|
+
}
|
|
122
149
|
|
|
123
150
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
124
151
|
self.currentResolve = resolve;
|
|
@@ -169,9 +196,7 @@ preferImmediatelyAvailableCredentials:(BOOL)preferImmediatelyAvailableCredential
|
|
|
169
196
|
} else if ([option isEqualToString:@"apple-signin"]) {
|
|
170
197
|
ASAuthorizationAppleIDProvider *appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init];
|
|
171
198
|
ASAuthorizationAppleIDRequest *appleIDRequest = [appleIDProvider createRequest];
|
|
172
|
-
|
|
173
|
-
NSArray<ASAuthorizationScope> *defaultScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
|
|
174
|
-
appleIDRequest.requestedScopes = defaultScopes;
|
|
199
|
+
[self configureAppleIDRequest:appleIDRequest nonce:appleNonce requestedScopes:appleRequestedScopes];
|
|
175
200
|
|
|
176
201
|
[authRequests addObject:appleIDRequest];
|
|
177
202
|
} else if ([option isEqualToString:@"google-signin"]) {
|
|
@@ -206,6 +231,8 @@ preferImmediatelyAvailableCredentials:(BOOL)preferImmediatelyAvailableCredential
|
|
|
206
231
|
- (void)signUpWithApple:(JS::NativeCredentialsManager::AppleSignInParams &)params
|
|
207
232
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
208
233
|
reject:(RCTPromiseRejectBlock)reject {
|
|
234
|
+
NSString *nonce = params.nonce();
|
|
235
|
+
NSArray<NSString *> *requestedScopes = RNCMNSArrayFromLazyStringVector(params.requestedScopes());
|
|
209
236
|
|
|
210
237
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
211
238
|
self.currentResolve = resolve;
|
|
@@ -213,8 +240,7 @@ preferImmediatelyAvailableCredentials:(BOOL)preferImmediatelyAvailableCredential
|
|
|
213
240
|
|
|
214
241
|
ASAuthorizationAppleIDProvider *appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init];
|
|
215
242
|
ASAuthorizationAppleIDRequest *appleIDRequest = [appleIDProvider createRequest];
|
|
216
|
-
|
|
217
|
-
appleIDRequest.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
|
|
243
|
+
[self configureAppleIDRequest:appleIDRequest nonce:nonce requestedScopes:requestedScopes];
|
|
218
244
|
|
|
219
245
|
ASAuthorizationController *authController = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[appleIDRequest]];
|
|
220
246
|
authController.delegate = self;
|
|
@@ -378,6 +404,32 @@ preferImmediatelyAvailableCredentials:(BOOL)preferImmediatelyAvailableCredential
|
|
|
378
404
|
return keyWindow ?: [[UIApplication sharedApplication] windows].firstObject;
|
|
379
405
|
}
|
|
380
406
|
|
|
407
|
+
#pragma mark - Apple Sign In Helpers
|
|
408
|
+
|
|
409
|
+
- (NSArray<ASAuthorizationScope> *)appleAuthorizationScopesFromJSScopes:(NSArray<NSString *> *)scopes {
|
|
410
|
+
NSMutableArray<ASAuthorizationScope> *mappedScopes = [NSMutableArray array];
|
|
411
|
+
for (NSString *scope in scopes) {
|
|
412
|
+
if ([scope isEqualToString:@"fullName"]) {
|
|
413
|
+
[mappedScopes addObject:ASAuthorizationScopeFullName];
|
|
414
|
+
} else if ([scope isEqualToString:@"email"]) {
|
|
415
|
+
[mappedScopes addObject:ASAuthorizationScopeEmail];
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return mappedScopes.count > 0
|
|
420
|
+
? [mappedScopes copy]
|
|
421
|
+
: @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
- (void)configureAppleIDRequest:(ASAuthorizationAppleIDRequest *)request
|
|
425
|
+
nonce:(NSString *)nonce
|
|
426
|
+
requestedScopes:(NSArray<NSString *> *)requestedScopes {
|
|
427
|
+
if (nonce.length > 0) {
|
|
428
|
+
request.nonce = nonce;
|
|
429
|
+
}
|
|
430
|
+
request.requestedScopes = [self appleAuthorizationScopesFromJSScopes:requestedScopes];
|
|
431
|
+
}
|
|
432
|
+
|
|
381
433
|
#pragma mark - Helper Methods
|
|
382
434
|
|
|
383
435
|
- (NSString *)createAuthenticationResponseJSON:(ASAuthorizationPlatformPublicKeyCredentialAssertion *)assertion {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-credentials-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A React Native library that implements the Credential Manager API for Android. This library allows you to manage passwords and passkeys in your React Native applications.",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/commonjs/index.js",
|
|
@@ -126,10 +126,13 @@
|
|
|
126
126
|
"release-it": {
|
|
127
127
|
"git": {
|
|
128
128
|
"commitMessage": "chore: release ${version}",
|
|
129
|
-
"tagName": "v${version}"
|
|
129
|
+
"tagName": "v${version}",
|
|
130
|
+
"requireCommits": true,
|
|
131
|
+
"requireCommitsFail": false
|
|
130
132
|
},
|
|
131
133
|
"npm": {
|
|
132
|
-
"publish": true
|
|
134
|
+
"publish": true,
|
|
135
|
+
"skipChecks": true
|
|
133
136
|
},
|
|
134
137
|
"github": {
|
|
135
138
|
"release": true
|