Unable to get Access Token using Certificate
- New
- Advice
-
Kevin Bell
- PowerServer
- Tuesday, 23 December 2025 03:21 PM UTC
PB2025 64bit
We are using EntraID and replacing the client secret with using a certificate. We are currently able to get a token when using clientsecret. The certificate is installed on my machine.
Certificate:

Issuer:

Serial Number:

Code: The following code is for development purposes only and certificate data is real, however, it will not be the certificate used for distribution. The code fails to get an access token due to the certificate. The same code using client secret instead of certificate works without issue.
NOTE: In powershell we are able to get an access token from Entra using the certificate and NO clientsecret with the same settings.
OAuthClient loac_Client
TokenRequest ltr_Request
TokenResponse ltr_Response
string ls_certSN, ls_certIssue, ls_url
string ls_TokenType, ls_AccessToken
string ls_type, ls_description, ls_state, ls_uri
integer li_return, li_rtn, li_response_code
li_rtn = -1
ls_url = 'https://login.microsoftonline.com/75864cfe-f26d-419c-b69d-c638695b5533/oauth2/v2.0/token'
ltr_Request.tokenlocation = ls_url
ltr_Request.Method = "POST"
ltr_Request.clientid = "905197f6-354d-4145-a40b-8e0d890a4b9c"
ltr_Request.granttype = "client_credentials"
ltr_Request.Scope = "api://905197f6-354d-4145-a40b-8e0d890a4b9c/.default"
ls_certSN = '5600268da6dcd91b59f717e232000100268da6'
ls_certIssue = 'CN = Fluor Intranet Issuing CA 3~r~nOU = Security~r~nO = Fluor Corporation~r~nL = Aliso Viejo~r~nS = California~r~nC = US'
ltr_Request.SetClientCert('MY', ls_certIssue, ls_certSN)
loac_client = create OAuthClient
li_Return = loac_client.AccessToken(ltr_request, ltr_response)
if li_Return = 1 and ltr_response.GetStatusCode() = 200 then
ls_TokenType = ltr_response.GetTokenType()
ls_AccessToken = ltr_response.GetAccessToken()
li_rtn = Getapplication().SetHttpRequestHeader("Authorization", ls_TokenType + " " + ls_AccessToken, true)
//Set Global Variables
gl_Expiresin = ltr_Response.GetExpiresIn()
li_rtn = 1
else
li_rtn = ltr_Response.GetTokenError(ls_type, ls_description, ls_uri, ls_state)
li_response_code = ltr_response.GetStatusCode()
li_rtn = MessageBox("Acquiring AccessToken Falied", "Return: " + string(li_Return) + "~r~nDescription: " + ls_description + '~r~nResponse Code: ' &
+ string(li_response_code) + "~r~nType: " + ls_type + "~r~nURL: " + ls_url + "~r~nState: " + ls_state)
end if
if IsValid(loac_Client) then destroy loac_Client
return li_rtn
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.