Get Access Token

You can now make direct calls to the Field Service REST API, Fusion REST API, or external APIs from your custom plugin using a JWT access token.

  • Configuration: In the plugin configuration, the Applications section lets you select which applications your plugin can access.
  • Initialization: During the init stage, the Mobile Plugin Framework sends the list of configured applications to the plugin.
  • Access token: Use the getAccessToken procedure to retrieve a JWT access token and authorize your direct API requests.
  • Availability: When available, getAccessToken is listed in the allowedProcedure collection sent in the open/wakeup method, indicating the procedure can be used.
{
    "apiVersion": 1,
    "method": "open"/"wakeup",
    "entity": "...",
    ...
    "buttonId": "...",
    "openParams": {},
    "allowedProcedures": {
        ...
        "getAccessToken": true
     }
}

On init stage, OFS returns the data of the configured Application for the particular Plugin in the "init" method.

The "resourceUrl" field is populated with the URL of the resource server. In case of Field Service API application, it is populated with the URL of the Plugin in order to use it in direct REST API requests. In the case of OAuth User Assertion or OAuth Client Credentials application, it is retuned the same as it is configured on the Modify Application screen.

init method

{
    "apiVersion": 1,
    "method": "init",
    "attributeDescription": {},
    "buttons": [],
    "applications": {
        "ofs_rest_api": {
            "type": "ofs",
            "resourceUrl": "https:// plugins-0-ofsc-xxxx.test.fs.ocs.oc-test.example.com",
        },
        "fusion_rest_api": {
            "type": “oath_user_assertion",
            "resourceUrl": "https://fa-xxxx-pintlabfadev.fa.ocs.oc-test.example.com"
        },
        "external_rest_api": {
            "type": "oauth_client_credentials"
            "resourceUrl": "https://external-rest-api-url.example.com"
        }
    }
}

init method with application that is not configured on Plugin Edit screen

{
        "empty": {
            "type": "unknown",
            "resourceUrl": ""
        }
    }
}

callProcedure method

{
    "apiVersion": 1,
    "method": "callProcedure",
    "callId": "1111111111",
    "procedure": "getAccessToken",
    "params": {       
        "applicationKey": "ofs_rest_api"
    }
}

callProcedureResult method - success case

{
    "apiVersion": 1,
    "method": "callProcedureResult",
    "callId": "1111111111",
    "resultData": {
        "token": "...",
        "status": "success",
        "detail": ""
    }
}

callProcedureResult method - fail case

{
    "apiVersion": 1,
    "method": "error",
    "errors": [
        {
            "type": "TYPE_PROCEDURE_PARAM",
            "code": "CODE_PROCEDURE_PARAM_VALUE_INVALID",
            "procedure": "getAccessToken",
            "paramName": "applicationKey"
         }
    ],
    "callId": "1111111111"
}
 
{
    "apiVersion": 1,
    "method": "error",
    "errors": [
        {
            "type": "TYPE_PROCEDURE_GET_ACCESS_TOKEN_ERROR",
            "code": "CODE_GET_ACCESS_TOKEN_APPLICATION_NOT_CONFIGURED",
            "procedure": "getAccessToken",
            "data": {
                "status": "unexpected_response",
                "detail": "",
                "token": ""
            }
         }
    ],
    "callId": "1111111111"
}