Duo_Liang submitted April 21 2021

Before you applying this code to your Salesforce environment, make sure you have read the my blog series and completed the following tasks:

  • Register a Salesforce Connected App and enable Oauth2 authentication
  • Retrieve a refresh token for this app
  • Update OneSpan Sign Callback Service

OAuth Event Notification for Salesforce – Part 1
OAuth Event Notification for Salesforce – Part 2
OAuth Event Notification for Salesforce – Part 3
 

Rate this Code Share

Comments

bthirupathireddy | Posts: 14

Reply to: Set up Callback Listener in Salesforce

0 votes

Hi Duo

Could you please provide documentation on how to set up callback listener in Guidewire ClaimCenter v8.

Thanks

Duo_Liang | Posts: 3776

Reply to:

0 votes

Hi bthirupathireddy,

 

Have you downloaded the OSS Guidewire v9 Accelerator from marketplace? Not sure how different it is from v8, but it exposes a callback endpoint by creating and registering a servlet class.

Step1:

It's registered at the \modules\configuration\config\servlet\servlets.xml

Step2: the servlet looks like below: (I've simplified the code)

@Servlet("/onespanstatus")
public class OneSpanListener extends AbstractBasicAuthenticationServlet {

  ......
  override function doPost(request : HttpServletRequest, response : HttpServletResponse) {

    try {
      var servletUser : User

      servletUser = ServletUtils.getBasicAuthenticatedUser(request)

      response.setContentType("text/html")
      response.setStatus(HttpServletResponse.SC_OK)

      var content = new StringBuilder()
      var inputLine = request.getReader().readLine()
      while (inputLine != null) {
        content.append(inputLine)
        inputLine = request.getReader().readLine()
      }
      var text = content.toString()

      //process callback payload

      ......

    } catch (ex : Exception) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)
    }
  }


  override function isAuthenticationRequired(req : HttpServletRequest) : boolean {
      return true
  }

}

Step3: in this case, the endpoint is exposed at {server_url}/cc/service/onespanstatus

Step4: Guidewire servlet accepts Basic authentication, therefore, base64 encode your Guidewire username and password in format of:

{username}:{password}

And use it as the callback key in your OneSpan Sign account.

setup_callback_notification_2_0.png

 

Duo

bthirupathireddy | Posts: 14

Reply to: Set up Callback Listener in Salesforce

0 votes

Thanks Duo for replying. We did as you said but we are getting exception 503 service unavailable 

Our URL :http://localhost:8080//cc/service/onespanstatus 

Exception:Payload:

{"@class":"com.silanis.esl.packages.event.ESLProcessEvent","name":"PACKAGE_COMPLETE","sessionUser":"Signer1","packageId":"**********","message":null,"documentId":null,"createdDate":"2021-07-14T17:33:09.784Z"}
Reason(s): status code: 503, reason phrase: 503: Service Unavailable 

What should we do in this case ?

bthirupathireddy | Posts: 14

Reply to: Set up Callback Listener in Salesforce

0 votes

Thanks Duo for replying. We did as you said but we are getting exception 503 service unavailable 

Our URL :http://localhost:8080//cc/service/onespanstatus 

Exception:Payload:

{"@class":"com.silanis.esl.packages.event.ESLProcessEvent","name":"PACKAGE_COMPLETE","sessionUser":"Signer1","packageId":"**********","message":null,"documentId":null,"createdDate":"2021-07-14T17:33:09.784Z"}
Reason(s): status code: 503, reason phrase: 503: Service Unavailable 

What should we do in this case ?

bthirupathireddy | Posts: 14

Reply to: Set up Callback Listener in Salesforce

0 votes

Thanks Duo for replying. We did as you said but we are getting exception 503 service unavailable 

Our URL :http://localhost:8080//cc/service/onespanstatus 

Exception:Payload:

{"@class":"com.silanis.esl.packages.event.ESLProcessEvent","name":"PACKAGE_COMPLETE","sessionUser":"Signer1","packageId":"**********","message":null,"documentId":null,"createdDate":"2021-07-14T17:33:09.784Z"}
Reason(s): status code: 503, reason phrase: 503: Service Unavailable 

What should we do in this case ?

bthirupathireddy | Posts: 14

Reply to: Set up Callback Listener in Salesforce

0 votes

Thank you Duo I appreciate your help :)

bthirupathireddy | Posts: 14

Reply to: Set up Callback Listener in Salesforce

0 votes

Hi Duo,

 

Can you respond to this question if you have any insights on this issue ?

https://community.onespan.com/forum/getting-noclassdeffounderror-gwacceleratorsonespanonespanjsonutils

talk2bks | Posts: 35

Reply to: Set up Callback Listener in Salesforce

0 votes

I am working through this process. I have the reset_token from part 1 and it tested sucessfully in the first of part 2. I have pushed these settings to OneSpan using Postman and I used the "get" to test and it looks like it returned just fine.

However, when completing the signing of a transaction, I'm not seeing any signs that it's coming through. There are no logs popping up in the Dev Console. It could be the key.

From my understanding, the key is a base64 json line derived from:

{"host":"test.salesforce.com",
"client_id":"3MVG97wqan.......14tfqr8JKu1T4f6Zx",
"refresh_token":"5Aep861MbVwd.....X_I1oLvvdMyo2Z.i.Q"}

host - this is my sandbox
client_id - this was created from my connected app in Salesforce
refresh_token - this was created in part 1 and tested successfully in part 2.

I took this code and put it in https://codebeautify.org/json-to-base64-converter which created a really long string. This string is what I'm using as a part of the key.

I'm hoping I've done everything correctly?

Duo_Liang | Posts: 3776

Reply to: Set up Callback Listener in Salesforce

0 votes

Hi Brian,

 

Is this a Salesforce initiated transaction? If that's the case, try to set this package data when transaction creation:
 “data” > “origin” : “OSS” 

Apex code could look like this:

OneSpanAPIObjects.Data data = new OneSpanAPIObjects.Data();

data.origin = 'OSS';

pkg.data = data;

 

Duo

 

talk2bks | Posts: 35

Reply to:

0 votes

Thanks Duo,

I have edited the OneSpanAPIObjects.cls. The dev log shows this when sending the package

{"status":"SENT","data":{"sdk":"Apex v1.0","origin":"oss","esl_doc_extract_type":"1"}}

 

Originally, origin had "Salesforce". It also should be noted that "oss" is in lowercase. Does this need to be all uppercase?

Also, I've used 3 different websites to create a base64 string of the json code. All three have returned different results. They are small but they are different.

talk2bks | Posts: 35

Reply to:

0 votes

Thanks Duo,

I have edited the OneSpanAPIObjects.cls. The dev log shows this when sending the package

{"status":"SENT","data":{"sdk":"Apex v1.0","origin":"oss","esl_doc_extract_type":"1"}}

 

Originally, origin had "Salesforce". It also should be noted that "oss" is in lowercase. Does this need to be all uppercase?

Also, I've used 3 different websites to create a base64 string of the json code. All three have returned different results. They are small but they are different.

Duo_Liang | Posts: 3776

Reply to:

0 votes

Hi Brian,

 

For the "host" field in your base64 decoded oAuth key, can you try to make it "login.salesforce.com" (now it's test.salesforce.com):

{"host":"login.salesforce.com","client_id":"3MVG9dZJoxxxRyqipjGciXo561Fg","refresh_token":"5Aep861vxxxQ63xq70o9usDz"}

Your client id and refresh token look good to me.

 

Duo

talk2bks | Posts: 35

Reply to:

0 votes

Thanks Duo,

I have made the origin "OSS". I have also changed the host field to login.salesforce.com"...

I'm taking all that and putting it in https://www.base64encode.org. And I'm putting all that in the postman ->

 

Post: https://sandbox.esignlive.com/api/callback/connectors/salesforceOauth2

{

  "url": "https://xxx/services/apexrest/oss/callback",
  "events": ["DOCUMENT_SIGNED"...."TEMPLATE_CREATE"],
  "key": "eyJob3N0IjoibG9nxxxbzJaLmkuUSJ9"
}

The Key: is 316 characters

I just put uploaded a new transaction and signed. I didn't get any logs nor the documents didn't get downloaded.

I did go into Salesforce Workbench and posted the package and that works. I believe any issues is hungup in this one process.

Duo_Liang | Posts: 3776

Reply to:

0 votes

Hi Brian,

 

While I was checking your oAuth info, I found that your callback URL is:

https://oxxn--bxxn.my.salesforce.com/services/apexrest/oss/callback

However after I manually retrieved an access token via refresh token flow by building this link:

https://login.salesforce.com/services/oauth2/token?client_id={client_id}&grant_type=refresh_token&refresh_token={refresh_token}

The instance URL in response says "https://oxxn.my.salesforce.com".

And with this access token, I can't authenticate the callback request to your callback URL.

 

Duo

 

talk2bks | Posts: 35

Reply to:

0 votes

That's what I get for being signed into production while setting this up.

I have redone the token and I have double checked that it should be going to oceancanyon--brian.... If you want to double check, please do.

Even with the change, I'm still not posting any logs in the dev console and I'm not seeing the files downloaded. I have double checked the code through workbench so the OssCallbackResources.cls seems to be working.

In the key, I have "url":"login.salesforce.com" even though I'm testing in a sandbox. Didn't know if that was okay.

Duo_Liang | Posts: 3776

Reply to: Set up Callback Listener in Salesforce

0 votes

Hi Brian,

 

This time it looks better. 

(1)Try to set your oAuth callback URL as 

https://oxxxn--bxxn.sandbox.my.salesforce.com/services/apexrest/oss/callback

(2)In oAuth key, set the host as "test.salesforce.com"

{"host":"test.salesforce.com","client_id":"3MVG97wqaxxxT4f6Zx","refresh_token":"5Aep861Wxxx3KL1Slpq3"}

 

Duo

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off