-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
791a05e
commit 531bb45
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
petcare-sample/b2c/web-app/petdesk/webhooks/asgardeo_registration_webhook/.devcontainer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"image": "ballerina/ballerina-devcontainer:2201.3.2", | ||
"extensions": ["WSO2.ballerina"], | ||
} |
1 change: 1 addition & 0 deletions
1
petcare-sample/b2c/web-app/petdesk/webhooks/asgardeo_registration_webhook/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
8 changes: 8 additions & 0 deletions
8
petcare-sample/b2c/web-app/petdesk/webhooks/asgardeo_registration_webhook/Ballerina.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
org = "WSO2" | ||
name = "asgardeo_registration_webhook" | ||
version = "0.1.0" | ||
distribution = "2201.3.2" | ||
|
||
[build-options] | ||
observabilityIncluded = true |
74 changes: 74 additions & 0 deletions
74
petcare-sample/b2c/web-app/petdesk/webhooks/asgardeo_registration_webhook/main.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import ballerinax/trigger.asgardeo; | ||
import ballerina/log; | ||
import ballerinax/salesforce; | ||
import ballerina/http; | ||
|
||
// Create Salesforce client configuration by reading from environment. | ||
configurable string salesforceAppClientId = ?; | ||
configurable string salesforceAppClientSecret = ?; | ||
configurable string salesforceAppRefreshToken = ?; | ||
configurable string salesforceAppRefreshUrl = ?; | ||
configurable string salesforceAppBaseUrl = ?; | ||
|
||
// Using direct-token config for client configuration | ||
salesforce:ConnectionConfig sfConfig = { | ||
baseUrl: salesforceAppBaseUrl, | ||
auth: { | ||
clientId: salesforceAppClientId, | ||
clientSecret: salesforceAppClientSecret, | ||
refreshToken: salesforceAppRefreshToken, | ||
refreshUrl: salesforceAppRefreshUrl | ||
} | ||
}; | ||
|
||
configurable asgardeo:ListenerConfig config = ?; | ||
|
||
listener http:Listener httpListener = new(8090); | ||
listener asgardeo:Listener webhookListener = new(config,httpListener); | ||
|
||
service asgardeo:RegistrationService on webhookListener { | ||
|
||
remote function onAddUser(asgardeo:AddUserEvent event ) returns error? { | ||
|
||
salesforce:Client baseClient = check new (sfConfig); | ||
|
||
log:printInfo(event.toJsonString()); | ||
|
||
json responseData = event.eventData.toJson(); | ||
|
||
map<json> mj = <map<json>> responseData; | ||
map<json> userClaims = <map<json>> mj.get("claims"); | ||
|
||
string lastName = <string>userClaims["http://wso2.org/claims/lastname"]; | ||
string firstName = <string>userClaims["http://wso2.org/claims/givenname"]; | ||
string email = <string>userClaims["http://wso2.org/claims/emailaddress"]; | ||
|
||
record {} leadRecord = { | ||
"Company": string `${firstName}_${lastName}`, | ||
"Email": email, | ||
"FirstName": firstName, | ||
"LastName": lastName | ||
}; | ||
|
||
salesforce:CreationResponse|error res = baseClient->create("Lead", leadRecord); | ||
|
||
if res is salesforce:CreationResponse { | ||
log:printInfo("Lead Created Successfully. Lead ID : " + res.id); | ||
} else { | ||
log:printError(msg = res.message()); | ||
} | ||
} | ||
|
||
remote function onConfirmSelfSignup(asgardeo:GenericEvent event ) returns error? { | ||
|
||
log:printInfo(event.toJsonString()); | ||
} | ||
|
||
remote function onAcceptUserInvite(asgardeo:GenericEvent event ) returns error? { | ||
|
||
log:printInfo(event.toJsonString()); | ||
} | ||
} | ||
|
||
service /ignore on httpListener {} | ||
|