Overview
This document outlines a Logic+ template for token management in the Sharpen system. The template, which can be implemented via JSON import, establishes a standardized process for:
Retrieving and validating tokens stored in SharpenDB
Automatically obtaining new tokens when existing ones expire
Processing tokens through the Set Variable panel using the Slice function to accommodate database column character limitations
Updating expired tokens in SharpenDB
Making the validated or renewed token available for subsequent API calls within the workflow
Salesforce Get Token and Validate Logic+ JSON Template
{
"panels":[
{
"type": "sharpenDbSelect",
"initiator": true,
"name": "getStoredToken",
"coordinates": {
"x": -1648.7029914654158,
"y": -5.725191587477184
},
"fields": {
"table": "salesforceAccess",
"fields": [
"name",
"accessTokenPartOne",
"accessTokenPartTwo",
"username",
"password",
"clientId",
"clientSecret"
],
"where": [
{
"values": {
"field": "name",
"operator": "=",
"value": "psTest"
},
"type": "condition"
}
],
"whereConditionOperator": "",
"sortBy": "id",
"distinct": false,
"limit": 1,
"offset": "",
"count": true,
"variables": [
{
"name": "resultCount",
"jsonpath": "$.count"
},
{
"name": "accessToken1",
"jsonpath": "$.results.0.accessTokenPartOne"
},
{
"name": "accessToken2",
"jsonpath": "$.results.0.accessTokenPartTwo"
},
{
"name": "username",
"jsonpath": "$.results.0.username"
},
{
"name": "password",
"jsonpath": "$.results.0.password"
},
{
"name": "clientId",
"jsonpath": "$.results.0.clientId"
},
{
"name": "clientSecret",
"jsonpath": "$.results.0.clientSecret"
}
],
"timeout": 20
},
"exits": {
"default": "tokenValidation",
"timeout": "tokenValidation"
},
"version": "1.0.0"
},
{
"type": "sharpenDbUpdate",
"initiator": false,
"name": "updateStoredToken",
"coordinates": {
"x": -586.806936627465,
"y": 259.5645053639638
},
"fields": {
"table": "salesforceAccess",
"fields": [
{
"values": {
"fields": "accessTokenPartOne",
"value": "$(tokenPart1)"
},
"type": "update"
},
{
"values": {
"fields": "accessTokenPartTwo",
"value": "$(tokenPart2)"
},
"type": "update"
}
],
"where": [
{
"values": {
"field": "name",
"operator": "=",
"value": "psTest"
},
"type": "condition"
}
],
"whereConditionOperator": "",
"timeout": 30
},
"exits": {
"default": "getLatestStoredToken",
"timeout": "getLatestStoredToken"
},
"version": "1.0.0"
},
{
"type": "integration",
"initiator": false,
"name": "getToken",
"coordinates": {
"x": -1633.495816462307,
"y": 253.10317594805343
},
"fields": {
"integrationId": "004hq3tmn7b4pyfv84",
"path": "/services/oauth2/token",
"method": "POST",
"headers": null,
"contentType": "Form Data",
"timeout": 27,
"variables": [
{
"name": "accessToken",
"jsonpath": "$.data.access_token"
}
],
"fireAndForget": false,
"requestBody": {
"grant_type": "client_credentials",
"client_id": "$(clientId)",
"client_secret": "$(clientSecret)",
"username": "$(username)",
"password": "$(password)"
}
},
"exits": {
"default": "splitToken",
"timeout": "splitToken",
"error": "splitToken"
},
"version": "2.2.0"
},
{
"type": "setVariable",
"initiator": false,
"name": "splitToken",
"coordinates": {
"x": -1014.8613982254002,
"y": 284.8752091560384
},
"fields": {
"variables": [
{
"name": "tokenPart1",
"value": {
"operation": "SLC",
"values": [
"$(accessToken)",
"0:50"
]
}
},
{
"name": "tokenPart2",
"value": {
"operation": "SLC",
"values": [
"$(accessToken)",
"50:null"
]
}
}
]
},
"exits": {
"default": "updateStoredToken"
},
"version": "2.0.0"
},
{
"type": "switch",
"initiator": false,
"name": "Expired Token?",
"coordinates": {
"x": -715.7627666037606,
"y": 45.33946691796828
},
"fields": {
"value": "$(active)",
"evaluations": [
{
"values": {
"name": "expiredToken",
"operator": "equal",
"valueToEvaluate": "false"
},
"type": "evaluation"
}
],
"ignoreCase": false
},
"exits": {
"expiredToken": "getToken",
"default": "Bad Request?"
},
"version": "3.0.0"
},
{
"type": "integration",
"initiator": false,
"name": "tokenValidation",
"coordinates": {
"x": -1172.0455742870972,
"y": 34.22979621822381
},
"fields": {
"integrationId": "00448pudx9snbub6g0",
"path": "/services/oauth2/introspect",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"requestBody": {
"token": "$(accessToken1)$(accessToken2)",
"client_id": "$(clientId)",
"client_secret": "$(clientSecret)"
},
"contentType": "Form Data",
"timeout": 5,
"variables": [
{
"name": "statusText",
"jsonpath": "statusText"
},
{
"name": "active",
"jsonpath": "$.data.active"
},
{
"name": "status",
"jsonpath": "status"
}
],
"fireAndForget": false
},
"exits": {
"default": "Expired Token?",
"timeout": "Expired Token?",
"error": "Expired Token?"
},
"version": "2.2.0"
},
{
"type": "switch",
"initiator": false,
"name": "Bad Request?",
"coordinates": {
"x": -274.39466725732234,
"y": 68.4643037495182
},
"fields": {
"value": "$(status)",
"evaluations": [
{
"values": {
"name": "badRequest",
"operator": "equal",
"valueToEvaluate": "400"
},
"type": "evaluation"
}
],
"ignoreCase": false
},
"exits": {
"badRequest": "getToken",
"default": ""
},
"version": "3.0.0"
},
{
"type": "sharpenDbSelect",
"initiator": false,
"name": "getLatestStoredToken",
"coordinates": {
"x": -166.8839924285984,
"y": 256.6536164309981
},
"fields": {
"table": "salesforceAccess",
"fields": [
"name",
"accessTokenPartOne",
"accessTokenPartTwo"
],
"where": [
{
"values": {
"field": "name",
"operator": "=",
"value": "psTest"
},
"type": "condition"
}
],
"whereConditionOperator": "",
"sortBy": "id",
"distinct": false,
"limit": 1,
"offset": "",
"count": true,
"variables": [
{
"name": "resultCount",
"jsonpath": "$.count"
},
{
"name": "accessToken1",
"jsonpath": "$.results.0.accessTokenPartOne"
},
{
"name": "accessToken2",
"jsonpath": "$.results.0.accessTokenPartTwo"
}
],
"timeout": 3
},
"exits": {
"default": "",
"timeout": ""
},
"version": "1.0.0"
}
]
}