Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Azure Fetch OpenID Connect metadata document

See more OIDC Examples

Downloads the OpenID Connect self-discovery document for an Azure OIDC enabled app.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oJson
LOCAL cStrVal
LOCAL cToken_endpoint
LOCAL cJwks_uri
LOCAL cIssuer
LOCAL nRequest_uri_parameter_supported
LOCAL cUserinfo_endpoint
LOCAL cAuthorization_endpoint
LOCAL cDevice_authorization_endpoint
LOCAL nHttp_logout_supported
LOCAL nFrontchannel_logout_supported
LOCAL cEnd_session_endpoint
LOCAL cKerberos_endpoint
LOCAL cTenant_region_scope
LOCAL cCloud_instance_name
LOCAL cCloud_graph_host_name
LOCAL cMsgraph_host
LOCAL cRbac_url
LOCAL i
LOCAL nCount_i

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

oHttp:Accept := "application/json"

//  See the Microsoft Azure OIDC documentation at https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-protocols-oidc
//  The "tenant" can take one of four values described in the documentation at the link above.

nSuccess := oHttp:SetUrlVar("tenant", "6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd")
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("GET", "https://login.microsoftonline.com/{$tenant}/v2.0/.well-known/openid-configuration", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Response Status Code: " + Str(oResp:StatusCode)

oJson := CreateObject("Chilkat.JsonObject")
oJson:Load(oResp:BodyStr)
oJson:EmitCompact := 0
? oJson:Emit()

IF (oResp:StatusCode != 200)
    ? "Failed."
    oHttp:destroy()
    oResp:destroy()
    oJson:destroy()
    RETURN
ENDIF

//  Sample output...
//  (See the parsing code below..)
//  
//  Use the this online tool to generate parsing code from sample JSON: 
//  Generate Parsing Code from JSON

//  {
//    "token_endpoint": "https://login.microsoftonline.com/6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd/oauth2/v2.0/token",
//    "token_endpoint_auth_methods_supported": [
//      "client_secret_post",
//      "private_key_jwt",
//      "client_secret_basic"
//    ],
//    "jwks_uri": "https://login.microsoftonline.com/6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd/discovery/v2.0/keys",
//    "response_modes_supported": [
//      "query",
//      "fragment",
//      "form_post"
//    ],
//    "subject_types_supported": [
//      "pairwise"
//    ],
//    "id_token_signing_alg_values_supported": [
//      "RS256"
//    ],
//    "response_types_supported": [
//      "code",
//      "id_token",
//      "code id_token",
//      "id_token token"
//    ],
//    "scopes_supported": [
//      "openid",
//      "profile",
//      "email",
//      "offline_access"
//    ],
//    "issuer": "https://login.microsoftonline.com/6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd/v2.0",
//    "request_uri_parameter_supported": false,
//    "userinfo_endpoint": "https://graph.microsoft.com/oidc/userinfo",
//    "authorization_endpoint": "https://login.microsoftonline.com/6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd/oauth2/v2.0/authorize",
//    "device_authorization_endpoint": "https://login.microsoftonline.com/6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd/oauth2/v2.0/devicecode",
//    "http_logout_supported": true,
//    "frontchannel_logout_supported": true,
//    "end_session_endpoint": "https://login.microsoftonline.com/6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd/oauth2/v2.0/logout",
//    "claims_supported": [
//      "sub",
//      "iss",
//      "cloud_instance_name",
//      "cloud_instance_host_name",
//      "cloud_graph_host_name",
//      "msgraph_host",
//      "aud",
//      "exp",
//      "iat",
//      "auth_time",
//      "acr",
//      "nonce",
//      "preferred_username",
//      "name",
//      "tid",
//      "ver",
//      "at_hash",
//      "c_hash",
//      "email"
//    ],
//    "kerberos_endpoint": "https://login.microsoftonline.com/6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd/kerberos",
//    "tenant_region_scope": "NA",
//    "cloud_instance_name": "microsoftonline.com",
//    "cloud_graph_host_name": "graph.windows.net",
//    "msgraph_host": "graph.microsoft.com",
//    "rbac_url": "https://pas.windows.net"
//  }

cToken_endpoint := oJson:StringOf("token_endpoint")
cJwks_uri := oJson:StringOf("jwks_uri")
cIssuer := oJson:StringOf("issuer")
nRequest_uri_parameter_supported := oJson:BoolOf("request_uri_parameter_supported")
cUserinfo_endpoint := oJson:StringOf("userinfo_endpoint")
cAuthorization_endpoint := oJson:StringOf("authorization_endpoint")
cDevice_authorization_endpoint := oJson:StringOf("device_authorization_endpoint")
nHttp_logout_supported := oJson:BoolOf("http_logout_supported")
nFrontchannel_logout_supported := oJson:BoolOf("frontchannel_logout_supported")
cEnd_session_endpoint := oJson:StringOf("end_session_endpoint")
cKerberos_endpoint := oJson:StringOf("kerberos_endpoint")
cTenant_region_scope := oJson:StringOf("tenant_region_scope")
cCloud_instance_name := oJson:StringOf("cloud_instance_name")
cCloud_graph_host_name := oJson:StringOf("cloud_graph_host_name")
cMsgraph_host := oJson:StringOf("msgraph_host")
cRbac_url := oJson:StringOf("rbac_url")
i := 0
nCount_i := oJson:SizeOfArray("token_endpoint_auth_methods_supported")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("token_endpoint_auth_methods_supported[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("response_modes_supported")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("response_modes_supported[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("subject_types_supported")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("subject_types_supported[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("id_token_signing_alg_values_supported")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("id_token_signing_alg_values_supported[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("response_types_supported")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("response_types_supported[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("scopes_supported")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("scopes_supported[i]")
    i := i + 1
ENDDO
i := 0
nCount_i := oJson:SizeOfArray("claims_supported")
DO WHILE i < nCount_i
    oJson:I := i
    cStrVal := oJson:StringOf("claims_supported[i]")
    i := i + 1
ENDDO

oHttp:destroy()
oResp:destroy()
oJson:destroy()