SecureStorage

    SecureStorage


    Article summary


    title: SecureStorage

    version: 0.15.0
    layout: default
    sdk: core

    # SecureStorage Module

    Version SecureStorage 0.15.0

    Table of Contents

    Usage

    To use the SecureStorage module, you can import it into your project from the Firebolt SDK:

    import { SecureStorage } from '@firebolt-js/sdk'
    

    Overview

    A module for storing and retrieving secure data owned by the app

    Methods

    clear

    Clears all the secure data values

    function clear(scope: StorageScope): Promise<void>
    

    Parameters:

    ParamTypeRequiredDescription
    scopeStorageScopetrueThe scope of the key/value
    values: 'device' \| 'account'

    Promise resolution:

    void
    

    Capabilities:

    RoleCapability
    usesxrn:firebolt:capability:storage:secure

    Examples

    Clears all the data values of storage

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.clear("account")
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:Request:
    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"method": "SecureStorage.clear",
    	"params": {
    		"scope": "account"
    	}
    }
    

    Response:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": null
    }
    

    get

    Get stored value by key

    function get(scope: StorageScope, key: string): Promise<string | null>
    

    Parameters:

    ParamTypeRequiredDescription
    scopeStorageScopetrueThe scope of the key/value
    values: 'device' \| 'account'
    keystringtrueKey to get

    Promise resolution:

    string | null
    

    Capabilities:

    RoleCapability
    usesxrn:firebolt:capability:storage:secure

    Examples

    Successfully retrieve a refresh token with key authRefreshToken

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.get("device", "authRefreshToken")
        .then(value => {
            console.log(value)
        })
    

    Value of value:

    "VGhpcyBub3QgYSByZWFsIHRva2VuLgo="
    
    JSON-RPC:Request:
    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"method": "SecureStorage.get",
    	"params": {
    		"scope": "device",
    		"key": "authRefreshToken"
    	}
    }
    

    Response:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": "VGhpcyBub3QgYSByZWFsIHRva2VuLgo="
    }
    

    Attempt to retrieve a key with no value set

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.get("account", "authRefreshToken")
        .then(value => {
            console.log(value)
        })
    

    Value of value:

    "VGhpcyBub3QgYSByZWFsIHRva2VuLgo="
    
    JSON-RPC:Request:
    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"method": "SecureStorage.get",
    	"params": {
    		"scope": "account",
    		"key": "authRefreshToken"
    	}
    }
    

    Response:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": null
    }
    

    remove

    Remove a secure data value

    function remove(scope: StorageScope, key: string): Promise<void>
    

    Parameters:

    ParamTypeRequiredDescription
    scopeStorageScopetrueThe scope of the data key
    values: 'device' \| 'account'
    keystringtrueKey to remove

    Promise resolution:

    void
    

    Capabilities:

    RoleCapability
    usesxrn:firebolt:capability:storage:secure

    Examples

    Remove the value with key authRefreshToken for device

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.remove("device", "authRefreshToken")
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:Request:
    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"method": "SecureStorage.remove",
    	"params": {
    		"scope": "device",
    		"key": "authRefreshToken"
    	}
    }
    

    Response:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": null
    }
    

    Remove the value with key authRefreshToken for account

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.remove("account", "authRefreshToken")
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:Request:
    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"method": "SecureStorage.remove",
    	"params": {
    		"scope": "account",
    		"key": "authRefreshToken"
    	}
    }
    

    Response:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": null
    }
    

    set

    Set or update a secure data value

    function set(scope: StorageScope, key: string, value: string, options?: StorageOptions): Promise<void>
    

    Parameters:

    ParamTypeRequiredDescription
    scopeStorageScopetrueThe scope of the data key
    values: 'device' \| 'account'
    keystringtrueKey to set
    valuestringtrueValue to set
    optionsStorageOptionsfalseOptional parameters to set

    Promise resolution:

    void
    

    Capabilities:

    RoleCapability
    usesxrn:firebolt:capability:storage:secure

    Examples

    Set a refresh token with name authRefreshToken with optional paramter

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.set("device", "authRefreshToken", "VGhpcyBub3QgYSByZWFsIHRva2VuLgo=", {"ttl":600})
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:Request:
    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"method": "SecureStorage.set",
    	"params": {
    		"scope": "device",
    		"key": "authRefreshToken",
    		"value": "VGhpcyBub3QgYSByZWFsIHRva2VuLgo=",
    		"options": {
    			"ttl": 600
    		}
    	}
    }
    

    Response:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": null
    }
    

    Set a refresh token with name authRefreshToken without optional parameter

    JavaScript:

    import { SecureStorage } from '@firebolt-js/sdk'
    
    SecureStorage.set("account", "authRefreshToken", "VGhpcyBub3QgYSByZWFsIHRva2VuLgo=", null)
        .then(success => {
            console.log(success)
        })
    

    Value of success:

    null
    
    JSON-RPC:Request:
    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"method": "SecureStorage.set",
    	"params": {
    		"scope": "account",
    		"key": "authRefreshToken",
    		"value": "VGhpcyBub3QgYSByZWFsIHRva2VuLgo="
    	}
    }
    

    Response:

    {
    	"jsonrpc": "2.0",
    	"id": 1,
    	"result": null
    }
    

    Types

    StorageScope

    The scope of the data

    enum StorageScope {
    	DEVICE = 'device',
    	ACCOUNT = 'account'
    }
    
    

    StorageOptions

    type StorageOptions = {
      ttl: number            // Seconds from set time before the data expires and is removed
    }
    


    Was this article helpful?

    What's Next