Skip to content

Latest commit

 

History

History
 
 

authenticated-json-api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Authenticated JSON API

This sample shows how to authenticate access to a JSON API to only allow access to data for a specific Firebase user.

Only users who pass a valid Firebase ID token as a Bearer token in the Authorization header of the HTTP request are authorized to use the API.

This sample comes with a web-based API explorer UI whose code is in the public directory. It lets you sign in to Firebase with your Google account, and create messages whose sentiments are detected by the Cloud Natural Language API.

Setting up the sample

  1. Create a Firebase Project using the Firebase Console.
  2. Enable the Google Provider in the Auth section.
  3. Enable Billing on your project (to connect to the Natural Language API) by switching to the Blaze or Flame plan.
  4. Clone or download this repo and open the authenticated-json-api directory.
  5. You must have the Firebase CLI installed. If you don't have it install it with npm install -g firebase-tools and then configure it with firebase login.
  6. Configure the CLI locally by using firebase use --add and select your project in the list.
  7. Install dependencies locally by running: cd functions; npm install; cd -
  8. Enable the Google Cloud Natural Language API

Deploy and test

This sample comes with a web-based UI for testing the function. To test locally do:

  1. Start serving your project locally using firebase serve --only hosting,functions
  2. Open the app in a browser at https://localhost:5000.
  3. Sign in to the web app in the browser using Google Sign-In
  4. Create messages and explore them using the List and Detail sections.
  5. Sign out. You should no longer be able to access the API.

To deploy and test on prod do:

  1. Deploy your project using firebase deploy
  2. Open the app using firebase open hosting:site, this will open a browser.
  3. Sign in to the web app in the browser using Google Sign-In
  4. Create messages and explore them using the List and Detail sections.
  5. Sign out. You should no longer be able to access the API.

Contributing

We'd love that you contribute to the project. Before doing so please read our Contributor guide.

License

© Google, 2017. Licensed under an Apache-2 license.