Skip to content

Instantly share code, notes, and snippets.

View antonkrasov's full-sized avatar

Anton Krasov antonkrasov

View GitHub Profile
try {
const pushTokenDoc = await db.collection(`push_tokens/${userRef.id}`).doc();
const token = pushTokenDoc.data().token;
const title = 'TITLE';
const message = 'MESSAGE';
const payload = {
notification: {
title: title,
const functions = require("firebase-functions");
const serviceAccount = require("./service-account.json");
const { initializeApp, cert } = require('firebase-admin/app');
const { getAuth } = require('firebase-admin/auth');
const app = initializeApp({
credential: cert(serviceAccount)
})
const auth = getAuth(app)
exports.protectedEndpoint = functions.https.onRequest(async (request, response) => {
try {
➜ ~ curl https://us-central1-givemefirebasetoken-sample.cloudfunctions.net/protectedEndpoint
{"error":"'x-api-token' header is required!"}%
curl --location --request POST '<https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=AIzaSyAHV1eUu8EqCSUeycofXqfL******>' \\
--header 'Content-Type: application/json' \\
--data-raw '{
"email": "anton.krasov@gmail.com",
"password": "******",
"returnSecureToken": true
}'
{
"kind": "identitytoolkit#SignupNewUserResponse",
"idToken": "eyJhbGciOiJSUzI1NiIsImtpZ....gkULJig1ypXaA",
"email": "anton.krasov@gmail.com",
"refreshToken": "AIwUaOkfNuMg8Kdatx-Hy8_5Ti0sm....-dKiN0CGkDfX1ch5f69g5Y5K",
"expiresIn": "3600",
"localId": "aoiC7bM0v....ueGMRegf1k2"
}
curl --location --request GET '<https://us-central1-givemefirebasetoken-sample.cloudfunctions.net/protectedEndpoint>' \\
--header 'x-api-token: eyJhbGciOiJSUzI1NiIsImtpZ....09HlrF49MRWo9qq0_c6UiMHdBZUavNXyuFyjC85dpSxJrNtJSwH5OQa22dIwdbNmfMqz6ljAivIkjw5aX2GrF5ViFCdp4Tew5iw'
{
"decodedToken": {
"iss": "<https://securetoken.google.com/givemefirebasetoken-sample",
"aud": "givemefirebasetoken-sample",
"auth_time": 1651977397,
"user_id": "aoiC7bM0vFQTMPj24ueGMRegf1k2",
"sub": "aoiC7bM0vFQTMPj24ueGMRegf1k2",
"iat": 1651977397,
"exp": 1651980997,
"email": "anton.krasov@gmail.com",
var jsonData = JSON.parse(responseBody);
pm.expect(jsonData.idToken).to.be.a('string');
postman.setEnvironmentVariable("firebaseIdToken", jsonData.idToken);
const firebaseApiKey = pm.environment.get("firebaseApiKey")
const firebaseTestUserEmail = pm.environment.get("firebaseTestUserEmail")
const firebaseTestUserPassword = pm.environment.get("firebaseTestUserPassword")
const options = {
url: `https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=${firebaseApiKey}`,
method: 'POST',
header: {
'Accept': '*/*',
'Content-Type': 'application/json',
@antonkrasov
antonkrasov / app_test.dart
Created November 22, 2022 22:12
Integration test file for Flutter Automation tutorial
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:taskezdev/main.dart' as app;
import 'package:taskezdev/main.dart';
import 'helpers.dart';
void main() {