Configuration
Adding a view to your app is as simple as adding the OsSdkView
component to your React app.
import React, { Component } from 'react'
import OsSdkView from '@opensolar/ossdk-react'
class Example extends Component {
render() {
return (
<OsSdkView
key={'unique-identifier-within-page'}
osToken={'jwt'}
osScriptLocation={'https://app.opensolar.com/sdk/v1.0/min.js'}
osSdkKey={'client-code'}
projectData={[{identifier: '123-main-st-uuid'}]}
projectIdentifiersToken={'xyz'}
onLoad={(ossdk) => {
clearSignalHandlers(ossdk);
ossdk.studio.objectSelected.add((object) => {
console.log("objectSelected", object);
});
}}
onRemove={(ossdk) => {
clearSignalHandlers(ossdk);
}}
/>
)
}
}
Signing Key
The Signing Key is required to create the JWTs (osToken) that are used to authenticate to the OpenSolar SDK. Follow the steps below to create the Signing Key.
1. Generate a bearer token
A bearer token can be created by via the OpenSolar API. Note the ID of the Org that is used when creating the bearer token as this is required for the next step.
2. Create the Signing Key
You will need the following in order to create an Signing Key:
- The ID of your Org
- The bearer token
Using the following curl command to create the Signing Key (replace 'BEARER_TOKEN' and 'ORG_ID' with your values):
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {BEARER_TOKEN}" \
"https://api.opensolar.com/api/orgs/{ORG_ID}/os_sdk_token_keys/"
Example response:
{
"url": "https://api.opensolar.com/api/orgs/11111/os_sdk_token_keys/1/",
"id": 1,
"org_id": 11111,
"secret_key":"ZmgnWaoHcsgTodQwR-GSqVFGTGbxeEXH3EZEIcXPl6U",
"created_at":"2024-03-26T04:41:43.963332Z"
}
If you have previously created an Signing Key, you can retrieve your previous keys by using the following command:
curl \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {BEARER_TOKEN}" \
"https://api.opensolar.com/api/orgs/{ORG_ID}/os_sdk_token_keys/"
Now that you have created an Signing Key, please note down the details before proceeding to creating the JWT (osToken) below.
JWTs (osToken)
The osToken is a JWT which is required in order to authenticate against the OpenSolar SDK. JWTs can be automatically generated in either the frontend or backend of your application. Please contact Partner Services to find out how you can generate JWTs to access the SDK. Please provide the following details from the Signing Key you generated previously:
- Signing Key
- Signing Secret
- Your Org ID (used when creating the Signing Key)