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
Reply to: Set up Callback Listener in Salesforce
Tuesday, July 13, 2021 at 03:50pmHi Duo
Could you please provide documentation on how to set up callback listener in Guidewire ClaimCenter v8.
Thanks
Reply to: Hi Duo Could you please…
Wednesday, July 14, 2021 at 11:17amHi 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.
Duo
Reply to: Hi Duo Could you please…
Tuesday, August 10, 2021 at 04:42amA really good post, very thankful and hopeful that you will write many more posts like this one.
MyCardStatement
Reply to: Set up Callback Listener in Salesforce
Wednesday, July 14, 2021 at 02:19pmThanks 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 ?
Reply to: Set up Callback Listener in Salesforce
Wednesday, July 14, 2021 at 02:19pmThanks 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 ?
Reply to: Set up Callback Listener in Salesforce
Wednesday, July 14, 2021 at 02:20pmThanks 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 ?
Reply to: Thanks Duo for replying. We…
Wednesday, July 14, 2021 at 02:35pmHi bthirupathireddy,
Localhost 8080 port won't enable OSS callback reach out to you, you will have to expose it to a public URL instead.
Duo
Reply to: Set up Callback Listener in Salesforce
Wednesday, July 14, 2021 at 02:41pmThank you Duo I appreciate your help :)
Reply to: Set up Callback Listener in Salesforce
Monday, July 26, 2021 at 10:19amHi Duo,
Can you respond to this question if you have any insights on this issue ?
https://community.onespan.com/forum/getting-noclassdeffounderror-gwacceleratorsonespanonespanjsonutils
Reply to: Set up Callback Listener in Salesforce
Thursday, August 3, 2023 at 08:32amI 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?
Reply to: Set up Callback Listener in Salesforce
Thursday, August 3, 2023 at 12:20pmHi 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
Reply to: Hi Brian, Is this a…
Thursday, August 3, 2023 at 01:39pmThanks 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.
Reply to: Hi Brian, Is this a…
Thursday, August 3, 2023 at 01:39pmThanks 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.
Reply to: Thanks Duo, I have edited…
Thursday, August 3, 2023 at 01:42pmHi Brian,
Yes, OSS needs to be all upper cases. Can I have your account email so that I can help you check your oAuth settings in backoffice?
Duo
Reply to: Hi Brian, Yes, OSS needs…
Thursday, August 3, 2023 at 02:20pm[email protected]
Please do.
Reply to: [email protected] …
Thursday, August 3, 2023 at 02:29pmHi 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
Reply to: Hi Brian, For the "host"…
Thursday, August 3, 2023 at 02:41pmThanks 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.
Reply to: Thanks Duo, I have made the…
Thursday, August 3, 2023 at 03:00pmJust retracing my steps,
Part 1: Retrieve a Refresh Token: Step 1. Is the {client_id} the "Consumer Key" from the Managed App or is this the Client_id from OneSpan?
Reply to: Thanks Duo, I have made the…
Thursday, August 3, 2023 at 03:07pmHi 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
Reply to: Hi Brian, While I was…
Thursday, August 3, 2023 at 04:47pmThat'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.
Reply to: Set up Callback Listener in Salesforce
Thursday, August 3, 2023 at 05:26pmHi 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
Reply to: Hi Brian, This time it…
Thursday, August 3, 2023 at 05:46pmEurika!!! That was it. We have logs! We have Documents! Thank you Duo!!!!!!xxx!!!!!!!