FirebaseAuth auth = FirebaseAuth.getInstance(); if (auth.getCurrentUser() != null) { startActivity(SignedInActivity.createIntent(this, null)); finish(); }
@OnClick(R.id.sign_in) public void signIn(View view) { startActivityForResult( AuthUI.getInstance().createSignInIntentBuilder() .setTheme(getSelectedTheme()) .setLogo(getSelectedLogo()) .setProviders(getSelectedProviders()) .setTosUrl(getSelectedTosUrl()) .setIsSmartLockEnabled(mEnableSmartLock.isChecked()) .build(), RC_SIGN_IN); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { handleSignInResponse(resultCode, data); return; } showSnackbar(R.string.unknown_response); }
private void handleSignInResponse(int resultCode, Intent data) { IdpResponse response = IdpResponse.fromResultIntent(data); // Successfully signed in if (resultCode == ResultCodes.OK) { startActivity(SignedInActivity.createIntent(this, response)); finish(); return; } else { // handle failure conditions } }
<style name="DarkTheme" parent="FirebaseUI"> <item name="colorPrimary">@color/material_gray_900</item> <item name="colorPrimaryDark">@android:color/black</item> … </style>
@OnClick(R.id.sign_in) public void signIn(View view) { startActivityForResult( AuthUI.getInstance().createSignInIntentBuilder() .setTheme(R.style.DarkTheme) .setLogo(getSelectedLogo())
FIRAnalytics.logEvent(withName: "workout_complete", parameters: [ "time": 1804 "exercise_type": "interval" "intensity": 2 ])
FIRAnalytics.logEvent(withName: "workout_complete", parameters: [ "time": 1804 "exercise_type": "interval" "intensity": 2 kFIRParameterValue: 1804 ])
workout_complete
invite_friends
eat_meal
<!DOCTYPE html> < html lang="en"> < head> < title>EasyAuth</title> <meta charset="UTF-8"> </head> <!-- Below is the initialization snippet for my Firebase project. It will vary for each project --> <script src="https://www.gstatic.com/firebasejs/3.6.4/firebase.js"></script> <script> // Initialize Firebase var config = { apiKey: "AIzaSyAPtNmUso5tA8d83vaJlgDHA_4C7HEgYNY", authDomain: "authui-6818f.firebaseapp.com", databaseURL: "https://authui-6818f.firebaseio.com", storageBucket: "authui-6818f.appspot.com", messagingSenderId: "596916061379" }; firebase.initializeApp(config); </script> <!-- The code below initializes the sign-in widget from FirebaseUI web. --> <script src="https://cdn.firebase.com/libs/firebaseui/1.0.0/firebaseui.js"></script> <link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/1.0.0/firebaseui.css" /> <script type="text/javascript"> var uiConfig = { signInSuccessUrl: 'loggedIn.html', signInOptions: [ // Specify providers you want to offer your users. firebase.auth.GoogleAuthProvider.PROVIDER_ID, firebase.auth.EmailAuthProvider.PROVIDER_ID ], // Terms of service url can be specified and will show up in the widget. tosUrl: '<your-tos-url>' }; // Initialize the FirebaseUI Widget using Firebase. var ui = new firebaseui.auth.AuthUI(firebase.auth()); // The start method will wait until the DOM is loaded. ui.start('#firebaseui-auth-container', uiConfig); </script> <!-- Include a simple background image & and title --> <div></div> <body> <h1 align="center" style="color:white;">Firebase Auth Quickstart Demo</h1> <div id="firebaseui-auth-container"></div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <title>EasyAuth</title> <meta charset="UTF-8"> </head> <!-- Below is the initialization snippet for my Firebase project. It will vary for each project --> <script src="https://www.gstatic.com/firebasejs/3.6.4/firebase.js"></script> <script> // Initialize Firebase var config = { apiKey: "AIzaSyAPtNmUso5tA8d83vaJlgDHA_4C7HEgYNY", authDomain: "authui-6818f.firebaseapp.com", databaseURL: "https://authui-6818f.firebaseio.com", storageBucket: "authui-6818f.appspot.com", messagingSenderId: "596916061379" }; firebase.initializeApp(config); </script> <body> <!-- A simple example script to add text to the page that displays the user's Display Name and Email --> <script> // Track the UID of the current user. var currentUid = null; firebase.auth().onAuthStateChanged(function(user) { // onAuthStateChanged listener triggers every time the user ID token changes. // This could happen when a new user signs in or signs out. // It could also happen when the current user ID token expires and is refreshed. if (user && user.uid != currentUid) { // Update the UI when a new user signs in. // Otherwise ignore if this is a token refresh. // Update the current user UID. currentUid = user.uid; document.body.innerHTML = '<h1> Congrats ' + user.displayName + ', you are done! </h1> <h2> Now get back to what you love building. </h2> <h2> Need to verify your email address or reset your password? Firebase can handle all of that for you using the email you provided: ' + user.email + '. <h/2>'; } else { // Sign out operation. Reset the current user UID. currentUid = null; console.log("no user signed in"); } }); </script> <h1>Congrats you're done! Now get back to what you love building.</h1> </html>
/topics/falcons
/topics/patriots
var admin = require("firebase-admin"); // Fetch the service account key JSON file contents var serviceAccount = require("path/to/serviceAccountKey.json"); // Initialize the app with a service account, granting admin privileges admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: "https://<DATABASE_NAME>.firebaseio.com" }); // Define who to send the message to var condition = "'falcons' in topics || 'patriots' in topics"; // Define the message payload var payload = { notification: { title: "Super Bowl LI: Falcons vs. Patriots", body: "Your team is Super Bowl bound! Get the inside scoop on the big game." } }; // Send a message to the condition with the provided payload admin.messaging.sendToCondition(condition, payload) .then(function(response) { console.log("Successfully sent message! Server response:", response); }) .catch(function(error) { console.log("Error sending message:", error); });
// condition and payload are the same as above var options = { priority: "high", timeToLive: 60 * 60 * 24 * 7 }; admin.messaging.sendToCondition(condition, payload, options) .then(function(response) { console.log("Successfully sent message! Server response:", response); }) .catch(function(error) { console.log("Error sending message:", error); });
setServiceAccount()
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountCredentials.json"); FirebaseOptions options = new FirebaseOptions.Builder() .setServiceAccount(serviceAccount) .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com") .build(); FirebaseApp.initializeApp(options);
setCredential()
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountCredentials.json"); FirebaseOptions options = new FirebaseOptions.Builder() .setCredential(FirebaseCredentials.fromCertificate(serviceAccount)) .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com") .build(); FirebaseApp.initializeApp(options);
FirebaseOptions options = new FirebaseOptions.Builder() .setCredential(FirebaseCredentials.applicationDefault()) .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com") .build(); FirebaseApp.initializeApp(options);