In this article I am going to explain the steps to integrate Salesforce and Xero by using OAuth 2.0, the latest version of xero authentication.
Note: OAuth 1.0a will no longer be supported for any apps.
I am going to connect the salesforce and xero with 'OpenID Connect' authentication. If you want learn more about openID connect click here.
Create a app in Xero:
1. Open the below link and click 'New app' in right corner.
https://developer.xero.com/myapps/
2. Provide the details as mentioned below
App name: Demo (You can give any name)
OAuth 2.0 grant type: Auth code (Web app)
Company or application URL:
https://lweb-dev-ed.lightning.force.com/services/auth/oauth/XeroAuthProvider
<Salesforce domain URL>/services/auth/oauth/<name of the auth. provider which are going to create in the next step>
OAuth 2.0 redirect URI:
https://lweb-dev-ed.lightning.force.com/services/authcallback/XeroAuthProvider
<Salesforce domain URL>/services/authcallback/<name of the auth. provider which are going to create in the next step>
3. Agree the terms and condition and click 'Create app'. Now you are on the App detail screen. Click ‘Generate Secret’ button to create the secret key.
4. Copy both the Client id and Client Secret and keep it in a separate note pad. We need this for our next step.
Create a Auth. Provider and Named Credential in Salesforce:
1. In Salesforce go to Setup --> enter 'Auth' in the quick find and select the 'Auth. Providers'. Click 'New' and select 'Open ID Connect'. As I mentioned earlier I am going to connect open ID connect for integration.
2. Enter the details as mentioned below
Name: XeroAuthProvider
URL Suffix: This will be auto populated leave it as it is.
Consumer Key: Paste the client id which you copied on the step 4
Consumer Secret: Paste the client secret which you copied on the step 4.
Authorize Endpoint URL: https://login.xero.com/identity/connect/authorize
Token Endpoint URL: https://identity.xero.com/connect/token
Include Consumer Secret in API Responses: Uncheck this checkbox
Click Save. Now you are on the Auth. Provider detail page, on this page there is a section called 'Salesforce configuration' with 'OAuth-Only Initialization URL' and 'Callback URL'. Make sure this URL is same as in xero app which we create in the above steps. If this URL is not matching then connection won't be success.
3. Lets create a 'Named credentials'. Go to setup --> enter 'Named' in the quick find and select the Named Credentials --> click 'New'. Enter the details as below.
Label: XeroDemo
Name: It will be auto populated as label. Leave it as it is.
URL: https://api.xero.com/
Identity Type: NamedPricipal
Authentication Protocol: OAuth 2.0
Authentication Provide: Select ‘XeroAuthProvider’ which you created in the previous step.
Scope: openid offline_access accounting.settings.read
Start Authentication Flow on Save: Check the checkbox.
Allow Merge Fields in HTTP Header: Check the checkbox.
Click 'Save', it will take you to the Xero login page(if you are not logged into xero). Once you entered the details you have the ability to select the xero organisation to be accessed from salesforce.
After the select click continue and you will be redirected to salesforce.
Note: Even the scope can be defined on the auth provider default scope.
Verify the connection:
If you run the below code in your developer console and if you get the status code as 200 then you are successfully connected the salesforce and xero.
Note: OAuth 1.0a will no longer be supported for any apps.
I am going to connect the salesforce and xero with 'OpenID Connect' authentication. If you want learn more about openID connect click here.
Create a app in Xero:
1. Open the below link and click 'New app' in right corner.
https://developer.xero.com/myapps/
2. Provide the details as mentioned below
App name: Demo (You can give any name)
OAuth 2.0 grant type: Auth code (Web app)
Company or application URL:
https://lweb-dev-ed.lightning.force.com/services/auth/oauth/XeroAuthProvider
<Salesforce domain URL>/services/auth/oauth/<name of the auth. provider which are going to create in the next step>
OAuth 2.0 redirect URI:
https://lweb-dev-ed.lightning.force.com/services/authcallback/XeroAuthProvider
<Salesforce domain URL>/services/authcallback/<name of the auth. provider which are going to create in the next step>
3. Agree the terms and condition and click 'Create app'. Now you are on the App detail screen. Click ‘Generate Secret’ button to create the secret key.
4. Copy both the Client id and Client Secret and keep it in a separate note pad. We need this for our next step.
Create a Auth. Provider and Named Credential in Salesforce:
1. In Salesforce go to Setup --> enter 'Auth' in the quick find and select the 'Auth. Providers'. Click 'New' and select 'Open ID Connect'. As I mentioned earlier I am going to connect open ID connect for integration.
2. Enter the details as mentioned below
Name: XeroAuthProvider
URL Suffix: This will be auto populated leave it as it is.
Consumer Key: Paste the client id which you copied on the step 4
Consumer Secret: Paste the client secret which you copied on the step 4.
Authorize Endpoint URL: https://login.xero.com/identity/connect/authorize
Token Endpoint URL: https://identity.xero.com/connect/token
Include Consumer Secret in API Responses: Uncheck this checkbox
Click Save. Now you are on the Auth. Provider detail page, on this page there is a section called 'Salesforce configuration' with 'OAuth-Only Initialization URL' and 'Callback URL'. Make sure this URL is same as in xero app which we create in the above steps. If this URL is not matching then connection won't be success.
3. Lets create a 'Named credentials'. Go to setup --> enter 'Named' in the quick find and select the Named Credentials --> click 'New'. Enter the details as below.
Label: XeroDemo
Name: It will be auto populated as label. Leave it as it is.
URL: https://api.xero.com/
Identity Type: NamedPricipal
Authentication Protocol: OAuth 2.0
Authentication Provide: Select ‘XeroAuthProvider’ which you created in the previous step.
Scope: openid offline_access accounting.settings.read
Start Authentication Flow on Save: Check the checkbox.
Allow Merge Fields in HTTP Header: Check the checkbox.
Click 'Save', it will take you to the Xero login page(if you are not logged into xero). Once you entered the details you have the ability to select the xero organisation to be accessed from salesforce.
After the select click continue and you will be redirected to salesforce.
Note: Even the scope can be defined on the auth provider default scope.
Verify the connection:
If you run the below code in your developer console and if you get the status code as 200 then you are successfully connected the salesforce and xero.
No comments:
Post a Comment