Logo
  • Products
    • SecOps Studio
  • Solutions
    • Pega Stack Shifter
  • Services
    • Pega Enablement
    • Pega Modernization
  • About
  • Contact
  • Blog
Code Vault

OAuth 2.0 – Part 2 – Pega as OAuth Client – Client Credentials Grant Type

December 10, 2024 Code Vault Curators

This is the continuation of the previous blog article. In this article, we will see how Pega can act as an OAuth client using the Client credentials grant type.

The article was created using earlier Pega 8 version! but the core concept remains the same! Use this blog article to learn the concepts and you can try the entire tutorial in the latest versions as well.

For a better understanding please go through the below article first to cover the basics about OAuth 2.0.

OAuth 2.0 – Part 1 – Understanding

What is client credentials grant type?

This is often used when the protected resources are under the control of the client.

Say for example – ABC is a banking organization and they have their own X (formerly Twitter) account for customer servicing. Here twitter is the OAuth provider and the protected resource (tweets directed to the ABC Twitter handle) are indirectly under the control of ABC. Here trust is already maintained.

You don’t need to manually authorize your access. This is mainly used when the client is the application and not a user.

This is again a widely used OAuth grant type in Pega.

One additional piece of information is whenever you register any client with the resource, you will be provided with a client-ID and client-secret (this is not the same as login credentials). So, with these credentials, you can directly request the access token.

The flow for the client credentials varies a little from the standard OAuth flow.

(1) It starts with an access token request. It skips the authorization code step. The client credentials (ID and secret) are passed in the request)

(2) The authorization server validates the client ID and secret and sends the access token post successful validation

(3) & (4) With the access token, the client can access the resource.

In the last article, we have successfully configured an application in twitter. We will start using it in Pega!!

The below demo was created years before using X (Formerly Twitter). You can just go through the tutorial to understand the OAuth 2.0 Concept.

How to implement OAuth authentication in Pega connectors?

Mainly there are two rules involved to configure Pega as an OAuth client in connectors.

a) OAuth 2.0 providers

b) Authentication profile

What is an OAuth 2.0 provider instance?

– It is a data instance that represents an external application pega connects to. (the authorization server or the resource server) They provide the OAuth service to pega applications.

In our examples LinkedIn, Twitter are the OAuth 2.0 providers.

As usual pega ships with a lot of samples or templates for OAuth providers 😊

Records -> Security -> OAuth 2.0 providers

You will the connection details for a lot of social networking sites!

Click and open Twitter.

Let’s see some important fields in the OAuth 2.0 provider instance.

Grant types – Client credentials, Authorization code, Password credentials. You see 3 out of 4 grant types we saw in the introduction post is supported by Pega.

Note: It is a checkbox and so you can have more than one grant types configured in a single provider instance.

Access token endpoint – You know without an access token, OAuth is nothing, so it is obviously mandatory!

The providers (Twitter, LinkedIn) should be responsible for providing these endpoints.

Authorization code endpoint – This is necessary when you use the authorization code grant type.

On hitting this endpoint, you will get an authorization code after successful authentication.

Revoke token endpoint  – There is an option to revoke the issued access tokens.

Note: All the above three endpoints are usually provided by the OAuth providers in their API guide.

Client authentication scheme – This is applicable for client credentials grant type.

You can send the client ID and client secret (client credentials) in 2 ways

a) Basic – send as the authorization header

b) POST – Send in the body of the POST request.

This will vary based on the provider configurations.

Send access token as – We know that to access the OAuth protected resource, we need to send the access token along with the request.

You can send the access token in two ways.

a) Authentication header

b) Query string parameter.

Again, the decision will be based on the OAuth provider configurations.

Security settings

Some secure configuration that corresponds to SSL https settings.

I have a dedicated post on SSL topic. Please refer it for more details.

https://myknowtech.com/tag/ssl

You can click and open the OAuth provider instances for other providers and see how it vary.

It is not restricted to use only the shipped OAuth provider instances. We can create a new one OAuth provider and connect to them as well.

Records -> Security -> OAuth 2.0 provider -> create new.

You need all these configuration details from the provider system. For now, we will use the existing Twitter instance.

Authentication profile –

What is an authentication profile instance?

It is a data instance that identifies the authentication details that is necessary to connect to a secured application.

Tip: Always it is better to create an authentication profile instance for the connecting system, so that the same instance can be used across connectors accessing the connecting system. This make the maintenance easier. Also with OAuth, Authentication profile is mandatory!!!

In the coming tutorial we will just concentrate on the configuration points for OAuth authentication profile instance.

Now we are ready to consume the OAuth protected Twitter API.

I am going to check some users Twitter timeline. Below is the endpoint URL

https://api.twitter.com/1.1/statuses/user_timeline.json

Below is the API documentation for our requirement – https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline

You can find the request and sample response in the above link.

How to include OAuth authentication in connect-REST?

Let’s start with the wizard

Step 1: Designer studio -> Integration -> Connectors -> Create REST Integration – start the wizard

Step 2: provide the endpoint URL. You will see the resource path formed

Step 3: Specify the query string parameter. Based on the API documentation, I am using the screen_name query string to get the timeline for the usernames.

Step 4: Specify the authentication details

Click on Add authentication and select create new.

Follow the below configurations –

authentication scheme –  select OAuth 2.0

Now you know the choices of authentication profiles. We will concentrate only on OAuth.

OAuth provider – select the already created/defined provider. We will use Twitter.

Grant type – client credentials are predefined.

Client information –

Remember, in the last article, we registered a client application with Twitter developer account. Use the same client credentials.

Copy and paste in the client ID and secret fields.

Scope – this defines the permission level. For this API, scope is not a mandatory field, so leave it blank.

Redirect URI endpoint – This is used for the authorization code grant type to redirect back to pega with the authorization code. For client credentials grant type leave it blank.

Use refresh token, if available – First thing is every access token will have some expiry time. So, some providers provide an option to automatically refresh the tokens. For Twitter it is not supported so leave it empty.

Additional endpoint parameters – leave it empty.

Click next.

Step 5: Choose the GET method in the resource tab

Step 6: Provide the data model for response.

We have two options. First, we will try out ‘Add a REST response’ option.

Again, I am checking Virat Kohli timeline. Success response.

But you cannot use this option directly to generate the data model because of some delimited characters in the raw response.

I suggest using the sample response provided in the API documentation.

https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline#

Copy the entire content and paste it into the online JSON editor –  to verify the syntax.

http://jsoneditoronline.org/

Once done save it to your local disk.

In the following sample response, you may get parse error for link reference tag.

Just make the source field value empty.

Use the Add a File option and add the saved JSON file.

Step 7: Complete the wizard to generate the rule

Note: I just created all the layers and I didn’t follow standard naming conventions 😉

Let’s test the OAuth authentication.

Step 1: Open the newly created data page.

Step 2: Run the data page to test the connection

This time checking out on Iron man!!

We saw in the Understanding blog article, that there will be two calls to the service provider for client credentials grant type.  The first call to get the access token and then the second call is to get the protected resource (tweet timeline)

So, who performed the first call to get the access token?

Go to App explorer and click on the class instance – Data-Admin-Security-OAuth2-AccessToken.

You see there is an instance saved in Pega.

Click and open the instance and then check view XML.

You will not see any expiry date for this, because Twitter do not expire the access token explicitly.

Now we know access tokens are saved as a pega instance.

Do Pega have any OOTB connect REST rule to get the access token? Yes, but all are hidden inside engine API library.

Open the engine API window. You will see valuable Java classes corresponding to OAuth2.

So based on the grant type in the authentication profile rule, engine API will execute the necessary functions and retrieve the access token.

We will dive deep into the next blog article, we will use the authorization code grant type.

OAuth 2.0 – Part 3 – Pega as OAuth client – Authorization Code grant type

 

  • security
Code Vault Curators

A technical team dedicated to empowering the Pega ecosystem with in-depth knowledge, guided by Premkumar Ganesan's vision.

Post navigation

Previous
Next

Pega Courses

Pega courses can be accessed at https://myknowacademy.com

Search through the blog

Tags

activity authentication background-processing case-management data-model declarative-processing email-processing file-processing pega-core-concepts pega-integration process reporting security system-administration user-interface validation

Categories

  • Code Vault

Recent posts

  • Service REST – Usage and Configurations in Pega
  • Queue processor – Usage and Configurations
  • Data Pages Usage & Configurations in Pega
  • Requestor types in Pega
  • Case Locking Mechanism in Pega

Related Articles

Code Vault

SSL – Understanding and Terminologies

December 10, 2024 Code Vault Curators

This blog article is the first of the SSL series. In this blog article, we will see more in detail about the basics of SSL and end by hosting the pega personal edition using https. Let’s get started. If we see from the networking angle, systems can communicate with each other through host name and […]

Code Vault

One-way SSL – Implementation in Pega

December 10, 2024 Code Vault Curators

In this blog article, we will see how to implement one-way SSL and how Pega can make use of one-way to secure their web services using keystore instance. This is the continuation of my previous article on SSL basics.  Assume there are 2 applications (Java application ABC and Pega application XYZ) Pega application is hosting […]

Code Vault

Access Deny, Access When and Privilege in Pega

December 10, 2024 Code Vault Curators

This is the continuation of my another blog article on Authorization topic. I recommend you to visit from blog article on Access roles and ARO concepts. In this article we will talk about Access Deny, Privilege and Access when rules. This article was created using Pega ’24 version. First let’s start with Access Deny rules. […]

Code Vault

Access Roles and ARO in Pega

December 10, 2024 Code Vault Curators

In this blog article we are going to talk about Role based access configurations, specifically about the Access role and Access role to Object rule configurations. This article was created using Pega ’24 version. First let’s get some basics about Role based access. Take a simple example of Office building as you see in the […]

About

MyKnowTech was born with a mission to bridge the gap between technical expertise and business needs. We are a boutique firm specializing in Pega solutions, delivering them with a personal touch. At the heart of our philosophy is a commitment to putting clients first.

Company
  • About
  • Leadership
  • Career
  • Contact
Resources
  • Blog
  • Services
  • Solutions
  • Insights

©  MyKnowTech B.V. All Rights Reserved.

  • Sitemap
  • Terms & Conditions
  • Privacy Policy