Stores SmartApp configuration and auth tokens for use in app-initiated calls
Stores SmartApp configuration and auth tokens for use in app-initiated calls
Used by the SmartApp SDK to store IDs and access tokens for an installed instance of a SmartApp
and retrieves that information for use in asynchronous API calls. The use of a context store
is only needed when SmartApps have to call the SmartThings API in response to external
events. SmartApps that only response to lifecycle events from the SmartThings platform
will automatically have the proper context without the app having to store it.
The context stored by this module consists of the following data elements:
npm install @smartthings/firestore-context-store --save
This package currently targets initializing Cloud Firestore from your own server by using a Service Account. If you are hosted on something like Firebase Cloud Functions or Google Cloud Platform, we don’t currently support those methodologies – feel free to contribute!
To use this module to add Firebase Cloud Firestore context storage to your SmartApp, you should:
Generate a service account. We use the Firebase Admin SDK. Go to IAM & admin > Service accounts in the Cloud Platform Console. Generate a new private key and save the JSON file. Then use the file to initialize the SDK in the next step.
require()
your Google Services service account JSON file. Be certain that you don’t ever commit this file to a public repository.
Create a context store instance with the service account object and the document collection name and pass it to the SmartApp SDK object. For example, the following code:
const SmartApp = require('@smartthings/smartapp');
const FirestoreDBContextStore = require('@smartthings/firestore-context-store');
const serviceAccount = require('./googleservices-YOURAPPNAME-AND-ID.json')
const smartapp = new SmartApp()
.contextStore(new FirestoreDBContextStore(serviceAccount, 'installedapps'))
This will use a document collection named installedapps
to store documents as keyed by the installedAppId
value.
From the Firebase Cloud Firestore console, you will see a new document collection with persisted contexts.
If you are not familiar with SmartThings, we have
extensive on-line documentation.
To create and manage your services and devices on SmartThings, create an account in the
developer workspace.
The SmartThings Community is a good place share and
ask questions.
There is also a SmartThings reddit community where you
can read and share information.
Licensed under the Apache License, Version 2.0
Copyright 2019 Samsung Electronics Co., LTD.