cordova-plugin-firebase-authentication 4.0.2 → 7.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-firebase-authentication",
3
- "version": "4.0.2",
3
+ "version": "7.0.0",
4
4
  "description": "Cordova plugin for Firebase Authentication",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-firebase-authentication",
@@ -18,10 +18,6 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/chemerisuk/cordova-plugin-firebase-authentication/issues"
20
20
  },
21
- "scripts": {
22
- "version": "replace -s 'version=\"(.+)(?=\">)' 'version=\"'$npm_package_version plugin.xml && git add plugin.xml",
23
- "postversion": "git push && git push --tags"
24
- },
25
21
  "homepage": "https://github.com/chemerisuk/cordova-plugin-firebase-authentication#readme",
26
22
  "funding": "https://github.com/chemerisuk/cordova-plugin-firebase-authentication?sponsor=1",
27
23
  "keywords": [
@@ -32,5 +28,17 @@
32
28
  "ecosystem:cordova",
33
29
  "cordova-android",
34
30
  "cordova-ios"
35
- ]
31
+ ],
32
+ "scripts": {
33
+ "preversion": "npm run docs && rm -rf docs",
34
+ "version": "perl -i -pe 's/(version=)\"\\d+\\.\\d+\\.\\d+\"/$1\"'$npm_package_version'\"$2/' plugin.xml && git add .",
35
+ "postversion": "git push && git push --tags",
36
+ "predocs": "tsc www/* --declaration --allowJs --checkJs --lib es2015,dom --emitDeclarationOnly --outDir types",
37
+ "docs": "typedoc && perl -i -pe 's/README.md#/#/g' ./docs/README.md",
38
+ "postdocs": "perl -i -0pe 's/(<!-- TypedocGenerated -->).*/$1\n\n/gms' README.md && cat ./docs/README.md >> README.md"
39
+ },
40
+ "devDependencies": {
41
+ "typedoc": "^0.23.9",
42
+ "typedoc-plugin-markdown": "^3.13.4"
43
+ }
36
44
  }
package/plugin.xml CHANGED
@@ -1,7 +1,7 @@
1
1
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2
2
  xmlns:android="http://schemas.android.com/apk/res/android"
3
3
  id="cordova-plugin-firebase-authentication"
4
- version="4.0.2">
4
+ version="7.0.0">
5
5
 
6
6
  <name>cordova-plugin-firebase-authentication</name>
7
7
  <description>Cordova plugin for Firebase Authentication</description>
@@ -15,13 +15,13 @@ xmlns:android="http://schemas.android.com/apk/res/android"
15
15
  </js-module>
16
16
 
17
17
  <engines>
18
- <engine name="cordova" version=">=9.0.0"/>
19
- <engine name="cordova-android" version=">=8.0.0"/>
18
+ <engine name="cordova" version=">=10.0.0"/>
19
+ <engine name="cordova-android" version=">=11.0.0"/>
20
20
  <engine name="cordova-ios" version=">=6.0.0"/>
21
21
  </engines>
22
22
 
23
23
  <platform name="ios">
24
- <preference name="IOS_FIREBASE_AUTH_VERSION" default="~> 7.0.0"/>
24
+ <preference name="IOS_FIREBASE_POD_VERSION" default="9.3.0" />
25
25
 
26
26
  <config-file target="config.xml" parent="/*">
27
27
  <feature name="FirebaseAuthentication">
@@ -37,14 +37,14 @@ xmlns:android="http://schemas.android.com/apk/res/android"
37
37
  <config>
38
38
  <source url="https://cdn.cocoapods.org/"/>
39
39
  </config>
40
- <pods>
41
- <pod name="Firebase/Auth" spec="$IOS_FIREBASE_AUTH_VERSION" />
40
+ <pods use-frameworks="true">
41
+ <pod name="Firebase/Auth" spec="$IOS_FIREBASE_POD_VERSION" />
42
42
  </pods>
43
43
  </podspec>
44
44
  </platform>
45
45
 
46
46
  <platform name="android">
47
- <preference name="ANDROID_FIREBASE_AUTH_VERSION" default="20.0.+"/>
47
+ <preference name="ANDROID_FIREBASE_BOM_VERSION" default="30.3.1" />
48
48
 
49
49
  <config-file target="res/xml/config.xml" parent="/*">
50
50
  <feature name="FirebaseAuthentication">
@@ -54,14 +54,15 @@ xmlns:android="http://schemas.android.com/apk/res/android"
54
54
  </config-file>
55
55
 
56
56
  <config-file target="config.xml" parent="/*">
57
+ <preference name="AndroidXEnabled" value="true" />
57
58
  <preference name="GradlePluginGoogleServicesEnabled" value="true" />
58
- <preference name="GradlePluginGoogleServicesVersion" value="4.3.3" />
59
+ <preference name="GradlePluginGoogleServicesVersion" value="4.3.13" />
59
60
  </config-file>
60
61
 
61
- <dependency id="cordova-support-android-plugin" version="~1.0.0"/>
62
- <dependency id="cordova-support-google-services" version="^1.3.2"/>
62
+ <dependency id="cordova-support-android-plugin" version="~2.0.3"/>
63
63
 
64
- <framework src="com.google.firebase:firebase-auth:$ANDROID_FIREBASE_AUTH_VERSION" />
64
+ <framework src="platform('com.google.firebase:firebase-bom:$ANDROID_FIREBASE_BOM_VERSION')" />
65
+ <framework src="com.google.firebase:firebase-auth" />
65
66
 
66
67
  <source-file src="src/android/FirebaseAuthenticationPlugin.java"
67
68
  target-dir="src/by/chemerisuk/cordova/firebase/" />
@@ -1,18 +1,19 @@
1
1
  package by.chemerisuk.cordova.firebase;
2
2
 
3
+ import static com.google.android.gms.tasks.Tasks.await;
4
+
3
5
  import android.net.Uri;
4
6
  import android.util.Log;
5
7
 
6
8
  import by.chemerisuk.cordova.support.CordovaMethod;
7
9
  import by.chemerisuk.cordova.support.ReflectiveCordovaPlugin;
8
10
 
9
- import com.google.android.gms.tasks.OnCompleteListener;
10
- import com.google.android.gms.tasks.Task;
11
11
  import com.google.firebase.auth.AuthCredential;
12
12
  import com.google.firebase.auth.FacebookAuthProvider;
13
13
  import com.google.firebase.auth.FirebaseAuth;
14
14
  import com.google.firebase.auth.FirebaseUser;
15
15
  import com.google.firebase.auth.FirebaseAuth.AuthStateListener;
16
+ import com.google.firebase.auth.GetTokenResult;
16
17
  import com.google.firebase.auth.GoogleAuthProvider;
17
18
  import com.google.firebase.auth.PhoneAuthCredential;
18
19
  import com.google.firebase.auth.PhoneAuthOptions;
@@ -22,6 +23,7 @@ import com.google.firebase.FirebaseException;
22
23
  import com.google.firebase.auth.UserProfileChangeRequest;
23
24
 
24
25
  import org.apache.cordova.CallbackContext;
26
+ import org.apache.cordova.CordovaArgs;
25
27
  import org.apache.cordova.PluginResult;
26
28
 
27
29
  import org.json.JSONException;
@@ -29,6 +31,8 @@ import org.json.JSONObject;
29
31
 
30
32
  import static java.util.concurrent.TimeUnit.MILLISECONDS;
31
33
 
34
+ import androidx.annotation.NonNull;
35
+
32
36
 
33
37
  public class FirebaseAuthenticationPlugin extends ReflectiveCordovaPlugin implements AuthStateListener {
34
38
  private static final String TAG = "FirebaseAuthentication";
@@ -39,19 +43,18 @@ public class FirebaseAuthenticationPlugin extends ReflectiveCordovaPlugin implem
39
43
  @Override
40
44
  protected void pluginInitialize() {
41
45
  Log.d(TAG, "Starting Firebase Authentication plugin");
42
-
43
46
  firebaseAuth = FirebaseAuth.getInstance();
44
47
  }
45
48
 
46
49
  @CordovaMethod
47
- private void setAuthStateChanged(boolean disable, CallbackContext callbackContext) {
48
- if (this.authStateCallback != null) {
49
- this.authStateCallback = null;
50
+ private void setAuthStateChanged(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
51
+ boolean disable = args.getBoolean(0);
52
+ if (authStateCallback != null) {
53
+ authStateCallback = null;
50
54
  firebaseAuth.removeAuthStateListener(this);
51
55
  }
52
-
53
56
  if (!disable) {
54
- this.authStateCallback = callbackContext;
57
+ authStateCallback = callbackContext;
55
58
  firebaseAuth.addAuthStateListener(this);
56
59
  }
57
60
  }
@@ -63,112 +66,108 @@ public class FirebaseAuthenticationPlugin extends ReflectiveCordovaPlugin implem
63
66
  }
64
67
 
65
68
  @CordovaMethod
66
- private void getIdToken(boolean forceRefresh, final CallbackContext callbackContext) {
69
+ private void getIdToken(CordovaArgs args, CallbackContext callbackContext) throws Exception {
70
+ boolean forceRefresh = args.getBoolean(0);
67
71
  FirebaseUser user = firebaseAuth.getCurrentUser();
68
-
69
72
  if (user == null) {
70
73
  callbackContext.error("User is not authorized");
71
74
  } else {
72
- user.getIdToken(forceRefresh).addOnCompleteListener(cordova.getActivity(), task -> {
73
- if (task.isSuccessful()) {
74
- callbackContext.success(task.getResult().getToken());
75
- } else {
76
- callbackContext.error(task.getException().getMessage());
77
- }
78
- });
75
+ GetTokenResult result = await(user.getIdToken(forceRefresh));
76
+ callbackContext.success(result.getToken());
79
77
  }
80
78
  }
81
79
 
82
80
  @CordovaMethod
83
- private void createUserWithEmailAndPassword(String email, String password, CallbackContext callbackContext) {
84
- firebaseAuth.createUserWithEmailAndPassword(email, password)
85
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
81
+ private void createUserWithEmailAndPassword(CordovaArgs args, CallbackContext callbackContext) throws Exception {
82
+ String email = args.getString(0);
83
+ String password = args.getString(1);
84
+ await(firebaseAuth.createUserWithEmailAndPassword(email, password));
85
+ callbackContext.success();
86
86
  }
87
87
 
88
88
  @CordovaMethod
89
- private void sendEmailVerification(CallbackContext callbackContext) {
89
+ private void sendEmailVerification(CallbackContext callbackContext) throws Exception {
90
90
  FirebaseUser user = firebaseAuth.getCurrentUser();
91
-
92
91
  if (user == null) {
93
92
  callbackContext.error("User is not authorized");
94
93
  } else {
95
- user.sendEmailVerification()
96
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
94
+ await(user.sendEmailVerification());
95
+ callbackContext.success();
97
96
  }
98
97
  }
99
98
 
100
99
  @CordovaMethod
101
- private void sendPasswordResetEmail(String email, CallbackContext callbackContext) {
102
- firebaseAuth.sendPasswordResetEmail(email)
103
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
100
+ private void sendPasswordResetEmail(CordovaArgs args, CallbackContext callbackContext) throws Exception {
101
+ String email = args.getString(0);
102
+ await(firebaseAuth.sendPasswordResetEmail(email));
103
+ callbackContext.success();
104
104
  }
105
105
 
106
106
  @CordovaMethod
107
- private void signInAnonymously(final CallbackContext callbackContext) {
108
- firebaseAuth.signInAnonymously()
109
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
107
+ private void signInAnonymously(CallbackContext callbackContext) throws Exception {
108
+ await(firebaseAuth.signInAnonymously());
109
+ callbackContext.success();
110
110
  }
111
111
 
112
112
  @CordovaMethod
113
- private void signInWithEmailAndPassword(String email, String password, CallbackContext callbackContext) {
114
- firebaseAuth.signInWithEmailAndPassword(email, password)
115
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
113
+ private void signInWithEmailAndPassword(CordovaArgs args, CallbackContext callbackContext) throws Exception {
114
+ String email = args.getString(0);
115
+ String password = args.getString(1);
116
+ await(firebaseAuth.signInWithEmailAndPassword(email, password));
117
+ callbackContext.success();
116
118
  }
117
119
 
118
120
  @CordovaMethod
119
- private void signInWithGoogle(String idToken, String accessToken, CallbackContext callbackContext) {
121
+ private void signInWithGoogle(CordovaArgs args, CallbackContext callbackContext) throws Exception {
122
+ String idToken = args.getString(0);
123
+ String accessToken = args.getString(1);
120
124
  signInWithCredential(GoogleAuthProvider.getCredential(idToken, accessToken), callbackContext);
121
125
  }
122
126
 
123
127
  @CordovaMethod
124
- private void signInWithFacebook(String accessToken, CallbackContext callbackContext) {
128
+ private void signInWithFacebook(CordovaArgs args, CallbackContext callbackContext) throws Exception {
129
+ String accessToken = args.getString(0);
125
130
  signInWithCredential(FacebookAuthProvider.getCredential(accessToken), callbackContext);
126
131
  }
127
132
 
128
133
  @CordovaMethod
129
- private void signInWithTwitter(String token, String secret, CallbackContext callbackContext) {
134
+ private void signInWithTwitter(CordovaArgs args, CallbackContext callbackContext) throws Exception {
135
+ String token = args.getString(0);
136
+ String secret = args.getString(1);
130
137
  signInWithCredential(TwitterAuthProvider.getCredential(token, secret), callbackContext);
131
138
  }
132
139
 
133
- private void signInWithCredential(AuthCredential credential, CallbackContext callbackContext) {
134
- firebaseAuth.signInWithCredential(credential)
135
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
136
- }
137
-
138
- private Task<?> signInWithPhoneCredential(PhoneAuthCredential credential) {
139
- FirebaseUser user = firebaseAuth.getCurrentUser();
140
-
141
- if (user != null) {
142
- return user.updatePhoneNumber(credential);
143
- } else {
144
- return firebaseAuth.signInWithCredential(credential);
145
- }
146
- }
147
-
148
140
  @CordovaMethod
149
- private void signInWithVerificationId(String verificationId, String code, CallbackContext callbackContext) {
150
- signInWithPhoneCredential(PhoneAuthProvider.getCredential(verificationId, code))
151
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
141
+ private void signInWithVerificationId(CordovaArgs args, CallbackContext callbackContext) throws Exception {
142
+ String verificationId = args.getString(0);
143
+ String code = args.getString(1);
144
+ await(firebaseAuth.signInWithCredential(PhoneAuthProvider.getCredential(verificationId, code)));
145
+ callbackContext.success();
152
146
  }
153
147
 
154
148
  @CordovaMethod
155
- private void verifyPhoneNumber(String phoneNumber, long timeoutMillis, final CallbackContext callbackContext) {
149
+ private void verifyPhoneNumber(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
150
+ String phoneNumber = args.getString(0);
151
+ long timeoutMillis = args.optLong(1);
156
152
  PhoneAuthOptions.Builder options = PhoneAuthOptions.newBuilder(firebaseAuth)
157
153
  .setActivity(cordova.getActivity())
158
154
  .setPhoneNumber(phoneNumber)
159
155
  .setCallbacks(new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
160
156
  @Override
161
- public void onVerificationCompleted(PhoneAuthCredential credential) {
162
- signInWithPhoneCredential(credential);
157
+ public void onVerificationCompleted(@NonNull PhoneAuthCredential credential) {
158
+ FirebaseUser user = firebaseAuth.getCurrentUser();
159
+ if (user != null) {
160
+ user.updatePhoneNumber(credential);
161
+ }
163
162
  }
164
163
 
165
164
  @Override
166
- public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
165
+ public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
167
166
  callbackContext.success(verificationId);
168
167
  }
169
168
 
170
169
  @Override
171
- public void onVerificationFailed(FirebaseException e) {
170
+ public void onVerificationFailed(@NonNull FirebaseException e) {
172
171
  callbackContext.error(e.getMessage());
173
172
  }
174
173
  });
@@ -176,77 +175,68 @@ public class FirebaseAuthenticationPlugin extends ReflectiveCordovaPlugin implem
176
175
  if (timeoutMillis > 0) {
177
176
  options.setTimeout(timeoutMillis, MILLISECONDS);
178
177
  }
179
-
180
178
  PhoneAuthProvider.verifyPhoneNumber(options.build());
181
179
  }
182
180
 
183
181
  @CordovaMethod
184
- private void signInWithCustomToken(String idToken, CallbackContext callbackContext) {
185
- firebaseAuth.signInWithCustomToken(idToken)
186
- .addOnCompleteListener(cordova.getActivity(),createCompleteListener(callbackContext));
182
+ private void signInWithCustomToken(CordovaArgs args, CallbackContext callbackContext) throws Exception {
183
+ String idToken = args.getString(0);
184
+ await(firebaseAuth.signInWithCustomToken(idToken));
185
+ callbackContext.success();
187
186
  }
188
187
 
189
188
  @CordovaMethod
190
189
  private void signOut(CallbackContext callbackContext) {
191
190
  firebaseAuth.signOut();
192
-
193
191
  callbackContext.success();
194
192
  }
195
193
 
196
194
  @CordovaMethod
197
- private void setLanguageCode(String languageCode, CallbackContext callbackContext) {
195
+ private void setLanguageCode(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
196
+ String languageCode = args.getString(0);
198
197
  if (languageCode == null) {
199
198
  firebaseAuth.useAppLanguage();
200
199
  } else {
201
200
  firebaseAuth.setLanguageCode(languageCode);
202
201
  }
203
-
204
202
  callbackContext.success();
205
203
  }
206
204
 
207
205
  @CordovaMethod
208
- private void updateProfile(JSONObject params, CallbackContext callbackContext) {
206
+ private void updateProfile(CordovaArgs args, CallbackContext callbackContext) throws Exception {
209
207
  FirebaseUser user = firebaseAuth.getCurrentUser();
210
-
211
208
  if (user == null) {
212
209
  callbackContext.error("User is not authorized");
213
- }
214
- else {
210
+ } else {
211
+ JSONObject params = args.getJSONObject(0);
215
212
  UserProfileChangeRequest request = createProfileChangeRequest(params);
216
- user.updateProfile(request)
217
- .addOnCompleteListener(cordova.getActivity(), createCompleteListener(callbackContext));
213
+ await(user.updateProfile(request));
214
+ callbackContext.success();
218
215
  }
219
216
  }
220
217
 
221
218
  @CordovaMethod
222
- private void useEmulator(String host, int port, CallbackContext callbackContext) {
219
+ private void useEmulator(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
220
+ String host = args.getString(0);
221
+ int port = args.getInt(1);
223
222
  firebaseAuth.useEmulator(host, port);
223
+ callbackContext.success();
224
+ }
224
225
 
226
+ private void signInWithCredential(AuthCredential credential, CallbackContext callbackContext) throws Exception {
227
+ await(firebaseAuth.signInWithCredential(credential));
225
228
  callbackContext.success();
226
229
  }
227
230
 
228
231
  @Override
229
- public void onAuthStateChanged(FirebaseAuth auth) {
230
- if (this.authStateCallback != null) {
232
+ public void onAuthStateChanged(@NonNull FirebaseAuth auth) {
233
+ if (authStateCallback != null) {
231
234
  PluginResult pluginResult = getProfileResult(firebaseAuth.getCurrentUser());
232
235
  pluginResult.setKeepCallback(true);
233
- this.authStateCallback.sendPluginResult(pluginResult);
236
+ authStateCallback.sendPluginResult(pluginResult);
234
237
  }
235
238
  }
236
239
 
237
- private static <T> OnCompleteListener<T> createCompleteListener(final CallbackContext callbackContext) {
238
- return new OnCompleteListener<T>() {
239
- @Override
240
- public void onComplete(Task task) {
241
- if (task.isSuccessful()) {
242
- callbackContext.success();
243
- } else {
244
- callbackContext.error(task.getException().getMessage());
245
- }
246
- }
247
- };
248
- }
249
-
250
240
  private static PluginResult getProfileResult(FirebaseUser user) {
251
241
  if (user == null) {
252
242
  return new PluginResult(PluginResult.Status.OK, (String)null);
@@ -271,19 +261,16 @@ public class FirebaseAuthenticationPlugin extends ReflectiveCordovaPlugin implem
271
261
  }
272
262
  }
273
263
 
274
- private static UserProfileChangeRequest createProfileChangeRequest(JSONObject jsonObject) {
264
+ private static UserProfileChangeRequest createProfileChangeRequest(JSONObject jsonObject) throws JSONException {
275
265
  UserProfileChangeRequest.Builder requestBuilder = new UserProfileChangeRequest.Builder();
276
-
277
266
  if (jsonObject.has("displayName")) {
278
- String displayName = jsonObject.optString("displayName", null);
267
+ String displayName = jsonObject.getString("displayName");
279
268
  requestBuilder = requestBuilder.setDisplayName(displayName);
280
269
  }
281
-
282
270
  if (jsonObject.has("photoURL")) {
283
- String photoURL = jsonObject.optString("photoURL", null);
271
+ String photoURL = jsonObject.getString("photoURL");
284
272
  requestBuilder = requestBuilder.setPhotoUri(Uri.parse(photoURL));
285
273
  }
286
-
287
274
  return requestBuilder.build();
288
275
  }
289
276
  }
@@ -1,6 +1,6 @@
1
1
  #import <Cordova/CDV.h>
2
2
 
3
- @import Firebase;
3
+ @import FirebaseAuth;
4
4
 
5
5
  @interface FirebaseAuthenticationPlugin : CDVPlugin
6
6
 
@@ -1,5 +1,7 @@
1
1
  #import "FirebaseAuthenticationPlugin.h"
2
2
 
3
+ @import FirebaseCore;
4
+
3
5
  @implementation FirebaseAuthenticationPlugin
4
6
 
5
7
  - (void)pluginInitialize {
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "typedocOptions": {
3
+ "out": "docs",
4
+ "readme": "none",
5
+ "entryPoints": "./types",
6
+ "exclude": "./types/index.d.ts",
7
+ "entryPointStrategy": "expand",
8
+ "hideBreadcrumbs": true,
9
+ "hideInPageTOC": true,
10
+ "hidePageTitle": true,
11
+ "hideMembersSymbol": true,
12
+ "disableSources": true,
13
+ "githubPages": false
14
+ }
15
+ }