AcknowledgeChallenge Module


Version AcknowledgeChallenge 1.0.0

Table of Contents

Usage

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

import { AcknowledgeChallenge } from '@firebolt-js/manage-sdk'

Overview

A module for registering as a provider for a user grant in which the user confirms access to a capability

Methods

challengeError

This is an private RPC method.

Internal API for Challenge Provider to send back error.

Parameters:

Param Type Required Description
error ProviderResponse true  

Result:

null

Capabilities:

Role Capability
provides xrn:firebolt:capability:usergrant:acknowledgechallenge

Examples

Example 1

JSON-RPC:

Request:

{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "AcknowledgeChallenge.challengeError",
	"params": {
		"error": {
			"correlationId": "123",
			"result": {
				"code": 1,
				"message": "Error"
			}
		}
	}
}

Response:

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

challengeFocus

This is an private RPC method.

Internal API for Challenge Provider to request focus for UX purposes.

Result:

null

Capabilities:

Role Capability
provides xrn:firebolt:capability:usergrant:acknowledgechallenge

Examples

Example

JSON-RPC:

Request:

{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "AcknowledgeChallenge.challengeFocus",
	"params": {}
}

Response:

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

challengeResponse

This is an private RPC method.

Internal API for Challenge Provider to send back response.

Parameters:

Param Type Required Description
response ProviderResponse true  

Result:

null

Capabilities:

Role Capability
provides xrn:firebolt:capability:usergrant:acknowledgechallenge

Examples

Example #1

JSON-RPC:

Request:

{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "AcknowledgeChallenge.challengeResponse",
	"params": {
		"response": {
			"correlationId": "123",
			"result": {
				"granted": true
			}
		}
	}
}

Response:

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

Example #2

JSON-RPC:

Request:

{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "AcknowledgeChallenge.challengeResponse",
	"params": {
		"response": {
			"correlationId": "123",
			"result": {
				"granted": false
			}
		}
	}
}

Response:

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

Example #3

JSON-RPC:

Request:

{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "AcknowledgeChallenge.challengeResponse",
	"params": {
		"response": {
			"correlationId": "123",
			"result": {
				"granted": null
			}
		}
	}
}

Response:

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

provide

To provide a specific capability to the platform. See Provider Interfaces for a list of interfaces available to provide in this module.

provide(capability: string, provider: any): void

Parameters:

Param Type Required Summary
capability string Yes The capability that is being provided.
provider any Yes An implementation of the required interface.

See Provider Interfaces for each capabilities interface definition.

Events

onRequestChallenge

This is an private RPC method.

Registers as a provider for when the user should be challenged in order to confirm access to a capability

Parameters:

Param Type Required Description
listen boolean true  

Result:

ChallengeProviderRequest

Capabilities:

Role Capability
provides xrn:firebolt:capability:usergrant:acknowledgechallenge

Examples

Default Example

JSON-RPC:

Request:

{
	"jsonrpc": "2.0",
	"id": 1,
	"method": "AcknowledgeChallenge.onRequestChallenge",
	"params": {
		"listen": true
	}
}

Response:

{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"correlationId": "abc",
		"parameters": {
			"capability": "xrn:firebolt:capability:localization::postal-code",
			"requestor": {
				"id": "ReferenceApp",
				"name": "Firebolt Reference App"
			}
		}
	}
}

Provider Interfaces

ChallengeProvider

The provider interface for the xrn:firebolt:capability:usergrant:acknowledgechallenge capability.


Usage:

AcknowledgeChallenge.provide('xrn:firebolt:capability:usergrant:acknowledgechallenge', provider: ChallengeProvider | object)

challenge

Registers as a provider for when the user should be challenged in order to confirm access to a capability

function challenge(parameters?: Challenge, session?: FocusableProviderSession): Promise<GrantResult>

Provider methods always have two arguments:

Param Type Required Summary
parameters Challenge false  
session FocusableProviderSession false  
Parameters Property Type Required Summary
capability string true The capability that is being requested by the user to approve
requestor ChallengeRequestor true  
type Challenge = object

Promise resolution:

Property Type Description  
granted boolean void  

Examples

Register your app to provide the xrn:firebolt:capability:usergrant:acknowledgechallenge capability.

import { AcknowledgeChallenge } from '@firebolt-js/manage-sdk'

class MyChallengeProvider {

    async challenge(parameters, session) {
        return await Promise.resolve({
            "granted": true
        })
    }

}

AcknowledgeChallenge.provide('xrn:firebolt:capability:usergrant:acknowledgechallenge', new MyChallengeProvider())
<summary>JSON-RPC</summary>

Register to recieve each provider API

Request:


{
    "id": 1,
    "method": "AcknowledgeChallenge.onRequestChallenge",
    "params": {
        "listen": true
    }
}

Response:


{
    "id": 1,
    "result": {
        "listening": true,
        "event": "AcknowledgeChallenge.onRequestChallenge"
    }            
 
}

Asynchronous event to initiate challenge()

Event Response:

{
    "id": 1,
    "result": {
        "correlationId": "abc",
        "parameters": {
            "capability": "xrn:firebolt:capability:localization::postal-code",
            "requestor": {
                "id": "ReferenceApp",
                "name": "Firebolt Reference App"
            }
        }
    }
}

App initiated response to event

Request:

{
    "id": 2,
    "method": "AcknowledgeChallenge.challengeResponse",
    "params": {
        "correlationId": "abc",
        "result": {
            "granted": true
        }
    }
}

Response:

{
    "id": 2,
    "result": true
}

Types

GrantResult

type GrantResult = {
  granted: boolean | void
}

ChallengeRequestor

type ChallengeRequestor = {
  id: string                 // The id of the app that requested the challenge
  name: string               // The name of the app that requested the challenge
}

Challenge

type Challenge = {
  capability: string             // The capability that is being requested by the user to approve
  requestor: ChallengeRequestor
}

See also:

ChallengeRequestor


ChallengeProviderRequest

type ChallengeProviderRequest = {
  parameters: Challenge
  correlationId: string            // The id that was passed in to the event that triggered a provider method to be called
}

See also:

ProviderRequest Challenge