PowerBuilder
PowerBuilder
Retrieve the Okta JSON Web Keys (JWK)
See more Okta OAuth/OIDC Examples
Demonstrates how to get the Okta web keys (JWK) that will be needed to locally validate an access token. This example is for the case where Okta is the identity platform for your App or API. (See https://developer.okta.com/docs/reference/api/oidc/#composing-your-base-url)Note: This example uses the URL
https://dev-765951.okta.com/oauth2/${authServerId}/v1/authorize
If you have a developer account, you can use the default authorization server that was created along with your account, in which case the full URL looks like this:
https://dev-765951.okta.com/oauth2/default/v1/authorize
Also: You'll need to change "dev-765951" to use your own Okta domain.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Kty
string ls_Alg
string ls_Kid
string ls_Use
string e
string n
integer i
integer li_Count_i
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Implements the following CURL command:
// curl -X GET \
// https://dev-765951.okta.com/oauth2/${authServerId}/v1/keys?client_id=$my_client_id
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Http.QuickGetSb("https://dev-765951.okta.com/oauth2/${authServerId}/v1/keys?client_id=$my_client_id",loo_SbResponseBody)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_SbResponseBody
return
end if
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Http.LastHeader
Write-Debug "Failed."
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "keys": [
// {
// "kty": "RSA",
// "alg": "RS256",
// "kid": "anSaRDPfWGOSCVNZEIZB9quCbNsdsvl5uWGBzxbudWQ",
// "use": "sig",
// "e": "AQAB",
// "n": "jT8uAgd5wF7d3aiCjdxbVXk7EDio2ScqAjWCL2LXbY3bpj6RV4dswZTqBg0-vuIh1SBqjoufDV3fHAJcewv2dfEdfUKawBxTIcLgeSu_NoUsZ6zmHqYKC9U0awgP3s5_Yqcr7YMxurrPRNRdKNsFFF2lhCDJ-4gCO4CWiCUdptlmMfI7_pBxx9bgh1F-ulVKt_RUo-4A7tXwwJhBhWaECKoye04BACccSNkth8flGSvjXNIVKcAMHYQ3oDfB6U5zXcFuDVEBJI__hzA9920QRXrloIv_G0QmYgbaf4iRpd-3B6-PQ4-VK-FGm3t9eTwoFv6CARpyXrjaOeuLB1HaVw"
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
i = 0
li_Count_i = loo_JResp.SizeOfArray("keys")
do while i < li_Count_i
loo_JResp.I = i
ls_Kty = loo_JResp.StringOf("keys[i].kty")
ls_Alg = loo_JResp.StringOf("keys[i].alg")
ls_Kid = loo_JResp.StringOf("keys[i].kid")
ls_Use = loo_JResp.StringOf("keys[i].use")
e = loo_JResp.StringOf("keys[i].e")
n = loo_JResp.StringOf("keys[i].n")
i = i + 1
loop
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp