Salesforce

Steps to generate an access token using OAuth2 Authentication

« Go Back

Information

 
TitleSteps to generate an access token using OAuth2 Authentication
URL Namesteps-to-generate-an-access-token-using-oauth2-authentication
Article Number000119826
EnvironmentProduct: DataDirect Hybrid Data Pipeline
Version: 4.4
OS: All supported platforms
Database: All supported platforms
Application: OAuth 2.0
Question/Problem Description
Does HDP support OAuth 2.0 Authentication?
How to generate an OAuth access token with HDP?
 
Steps to Reproduce
Clarifying Information
Error Message
Defect NumberDefect HDP-2365
Enhancement Number
Cause

To generate the proper OAuth2 token, you need to pass the payload as "application/x-www-form-urlencoded". 
Also, Authorization should be set to No Auth before posting the payload.

Resolution
Below is a comprehensive step by step process to generate an access token using OAuth2 Authentication.

1. Register an application in Hybrid Data Pipeline for OAuth 2.0 Authorization.
To do that, Open Postman and send a POST REQUEST as shown below [Auth type : Basic Authentication]
{
  "name": "Application_Name",
  "description": "Application_description",
  "redirectUrls": [
    "https://domainname/landingpage.html"
  ]
}



NOTE: Auth type : Basic Authentication and provide the HDP credentials that you have supplied during installation and to access the HDP UI.

If your application is already registered you'll get the following result. In which case you can go to Step 2.
 
{
  "error": {
    "code": 222206626,
    "message": {
      "lang": "en-US",
      "value": "OAuth Client Application with name 'Application_Name' already exists. "
    }
  }
}




2. If your application is already registered you could, Get Registered applications for the current user.
Open Postman and send a GET REQUEST as shown below
http://domain:port/api/mgmt/oauth/client/applications [Auth type : Basic Authentication]

This will retrieve a list of applications as shown below. You should NOTE the application ID.
{
  "applications": [
    {
      "id": 1,
      "name": "SalesforceAuth",
      "description": "Salesforce Lightning Connect via OData",
      "redirectUrls": [
        "https://xxxxxxxxxxxxx/views/oauthredirect.html"
      ]
    },
    {
      "id": 2,
      "name": "SalesforceAuth2",
      "description": "Salesforce Lightning Connect via OData",
      "redirectUrls": [
        "dummy.callback.url"
      ]
    },
    {
      "id": 3,
      "name": "PowerBIAuth",
      "description": "Connect to Power BI via OAuth2",
      "redirectUrls": [
        "https://xxxxxxxxxxxxxxxx/views/oauthredirect.html"
      ]
    }
  ]
}

3. To Get Client Code and Secret using the Application ID. [Auth type : Basic Authentication]
http://domain:port/api/mgmt/oauth/client/applications/<numeric_id>?user=<username>
Example: http://domain:port/api/mgmt/oauth/client/applications/3?user=xxadmin

This will return the Client and the Secret code as follows
{
  "id": 3,
  "name": "PowerBIAuth",
  "description": "Connect to Power BI via OAuth2",
  "redirectUrls": [
    "https://xxxxxxxxxxxxxxxxx/views/oauthredirect.html"
  ],
  "clientId": "d65cfcd1-87axxxxxxxxxxxxxxxxcdce753",
  "clientSecret": "ef2b058a-0xxxxxxxxxxxxx0-b3beea3283a8"
}



4. Use the Client and the Secret Code to get the Token.
Open Postman and send a POST REQUEST as shown below
http://domain:port/oauth2/token [Auth type : No Auth]

You need to pass the payload as "application/x-www-form-urlencoded"
Example Payload:
grant_type:password
scope:api.access.odata
username:d2cadmin
password:d2cadmin
client_id: d65cfcd1xxxxxxxxxxb-6a834cdce753
client_secret:d65cfcxxxxxxxxxxxxx99b-6a834cdce753

A successful post should return the result as follows.
{
  "access_token": "f20d5696aa67a19a1ea83088xxxxxxxxxxxxxxxcaeb9c896aecb3ffd5",
  "refresh_token": "1b47521b220078b58f05800xxxxxxxxxxxx86c82e172ad94bc63c159e91dc",
  "expires_in": 3599
}
Workaround
Notes
Keyword Phrase
Last Modified Date4/24/2019 2:38 PM

Powered by