Question
· Dec 5

Creating an Operation to Connect to an OAuth 2.0 Server

I have created an OAuth Client and have created the credentials etc successfully.

I have tested using the curl command and have received the token back from the Server using the terminal.

I now need to create an Operation to use my client credentials to connect to the Server and receive the token back.

What adapter would I use as I am unable to link my client credentials and secret  - currently  I am using the EnsLib.HTTP.OutboundAdapter
 but I am not sure if this is the correct.

Product version: IRIS 2023.1
Discussion (2)2
Log in or sign up to continue

My approach would be to make use of the OAuth 2.0 Client configuration via the Management Portal.

You can configure the Issuer Endpoint here, as well as add the details of the Client, Secret, etc.

To then make use of this configuration within an Operation, you can then do something like this:

Method AuthoriseMe(Output AccessToken As %String) As %Status
{
 //Set basic parameters
 Set tSC = $$$OK
 Set myscopes = "profile"
 Set clientName = ..Client
 Set AccessToken = ""
 //Check to see if client is already authenticated
 Set isAuth=##class(%SYS.OAuth2.AccessToken).IsAuthorized(clientName,,myscopes,.accessToken,.idtoken,.responseProperties,.error)

 //If we're not authorised already, we need to authorise ourselves.
 If isAuth=0{
   //Not Authenticated - authenticate client
   //Quit on error is used here as, if we're unable to get the token 
   $$$QuitOnError(##class(%SYS.OAuth2.Authorization).GetAccessTokenClient(clientName,myscopes,,.error))
   $$$QuitOnError(##class(%SYS.OAuth2.AccessToken).IsAuthorized(clientName,,myscopes,.accessToken,.idtoken,.responseProperties,.error))
   }
 
 Set AccessToken = accessToken
 Quit tSC
}

Where ..Client is in the code snippet, the value of this will need to match the name of the client as configured in the management portal.