8 Replies Latest reply on Feb 4, 2020 11:01 AM by ndass

    how to assign Authentication token to REST Service Task

    aha001

      I am calling a REST service from jbpm using the REST service task but I don't know how to specify the Authorization Token (assignment picture attached). Does anyone know how to do this? Your help will be much appreciated.

       

      This is the curl command:

      curl -H "Authorization: Token 76f6fa094dec43f244bf1e1f45548eca123456c1" https://abc.com/api/customers/ -k

        • 1. Re: how to assign Authentication token to REST Service Task
          swiderski.maciej

          jbpm REST work item handler accepts only BASIC and FORM based authentication so you need to configure handler accordingly. I am afraid there is no support for tokens.

           

          HTH

          • 2. Re: how to assign Authentication token to REST Service Task
            aha001

            Thanks Maciej,

             

            I created a custom REST WorkItemahandler. Then

             

            (1) copy the jar to [jbpm]/standalone/deployments/business-central.war/WEB-INF/lib

            (2) add "CustomREST": new com.developer.CustomRestWorkItemHandler() to [jbpm]/standalone/deployments/business-central.war/WEB-INF/classes/META-INFCustomWorkItemHandlers.conf

            (3) create a new project in workbench

            (4) navigate to src/main/resources/META-INF/ and upload CustomWorkItem.wid file

                 

                import org.drools.core.process.core.datatype.impl.type.StringDataType;

                 import org.drools.core.process.core.datatype.impl.type.ObjectDataType;

                 import org.drools.core.process.core.datatype.impl.type.BooleanDataType;

                 [

                        [

                          "name" : "CustomREST",

                          "parameters" : [

                              "Url" : new StringDataType(),

                              "Method" : new StringDataType(),

                              "Body" : new StringDataType(),

                              "ConnectTimeout" : new StringDataType(),

                              "ReadTimeout" : new StringDataType(),

                              "Username" : new StringDataType(),

                              "Password" : new StringDataType(),

                              "ContentType" : new StringDataType(),

                              "Authorization" : new StringDataType(),

                              "IgnoreSSL" : new BooleanDataType()

                          ],

                          "results" : [

                              "Result" : new ObjectDataType(),

                          ],

                          "displayName" : "CustomREST",

                          "icon" : "icons/restlogo.png"

                        ]

                 ]

             

            (5) create a new "Business Process".


            From the process designer in the palette on the left in "Service Tasks" the activity should appear CustomREST, but for some reason I can't see this icon. Can you please advise if I missed out any configuration? Thanks.

            • 3. Re: how to assign Authentication token to REST Service Task
              swiderski.maciej

              it could be that the icon is not found and thus not showing on palette. Could you try to use the default icon as it used by default here.

               

              HTH

              • 4. Re: how to assign Authentication token to REST Service Task
                iiq374

                Surely there should be a way to set HTTP Headers generally? 

                It's pretty common for things to be needed in the header as well or instead of the JSON Body.

                • 5. Re: how to assign Authentication token to REST Service Task
                  swiderski.maciej

                  it does allow to set some headers like content type etc but does not support any header to be set. If you see this as valuable addition feel free to drop feature request jira for it.

                   

                  HTH

                  • 6. Re: how to assign Authentication token to REST Service Task
                    aha001

                    Thanks Maciej,

                     

                    I have resolved this issue. I loaded the CustomWorkItem.wid file to the wrong directory. It should be loaded into src/main/resources instead of src/main/resources/META-INF


                    • 7. Re: how to assign Authentication token to REST Service Task
                      smcco321

                      Hi Maciej,

                      I believe I'm hitting this same issue running version 7 of Business Central (7.21.0.Final). Is Rest token support still not available in v7?

                      Thanks.

                      • 8. Re: how to assign Authentication token to REST Service Task
                        ndass

                        I have been able to set the in REST service task using the "Headers" attribute in 7.32.

                         

                        Attribute name: Headers

                        Data type: String

                        Value:

                        x-txn-correlation-id=test123;Authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjMI6arZ3Y922BhjWgQzWXcXNrz0ogtVhfEd2o

                         

                        Attribute name is case sensitive and multiple headers are separated by ";" and name value pair has "=" between it.

                         

                        Hope this helps.