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.
- Log in to post comments
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)