Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/android/FirebaseAuthenticationPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import static java.util.concurrent.TimeUnit.MILLISECONDS;

import java.util.Map;


public class FirebaseAuthenticationPlugin extends ReflectiveCordovaPlugin implements AuthStateListener {
private static final String TAG = "FirebaseAuthentication";
Expand Down Expand Up @@ -286,4 +288,24 @@ private static UserProfileChangeRequest createProfileChangeRequest(JSONObject js

return requestBuilder.build();
}

@CordovaMethod(ExecutionThread.WORKER)
private void getClaims(boolean forceRefresh, CallbackContext callbackContext) {
FirebaseUser user = this.firebaseAuth.getCurrentUser();

if (user == null) {
callbackContext.error("User is not authorized");
return;
}

user.getIdToken(forceRefresh).addOnCompleteListener(cordova.getActivity(), task -> {
if (task.isSuccessful()) {
Map<String, Object> claims = task.getResult().getClaims();
JSONObject json = new JSONObject(claims);
callbackContext.success(json);
} else {
callbackContext.error(task.getException().getMessage());
}
});
}
}
7 changes: 7 additions & 0 deletions www/FirebaseAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module.exports = {
exec(resolve, reject, PLUGIN_NAME, "getIdToken", [forceRefresh]);
});
},
getClaims: function(forceRefresh) {
return new Promise(function(resolve, reject) {
if (forceRefresh == null) forceRefresh = false;

exec(resolve, reject, PLUGIN_NAME, "getClaims", [forceRefresh]);
});
},
createUserWithEmailAndPassword: function(email, password) {
return new Promise(function(resolve, reject) {
exec(resolve, reject, PLUGIN_NAME, "createUserWithEmailAndPassword", [email, password]);
Expand Down