Sample code for 30+ languages & platforms
C++

Azure Fetch OpenID Connect metadata document

See more OIDC Examples

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

Chilkat C++ Downloads

C++
#include <CkHttp.h>
#include <CkHttpResponse.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttp http;

    http.put_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.

    success = http.SetUrlVar("tenant","6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd");
    CkHttpResponse resp;
    success = http.HttpNoBody("GET","https://login.microsoftonline.com/{$tenant}/v2.0/.well-known/openid-configuration",resp);
    if (success == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "Response Status Code: " << resp.get_StatusCode() << "\r\n";

    CkJsonObject json;
    json.Load(resp.bodyStr());
    json.put_EmitCompact(false);
    std::cout << json.emit() << "\r\n";

    if (resp.get_StatusCode() != 200) {
        std::cout << "Failed." << "\r\n";
        return;
    }

    //  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"
    //  }

    //  Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    //  See this example explaining how this memory should be used: const char * functions.

    const char *strVal = 0;

    const char *token_endpoint = json.stringOf("token_endpoint");
    const char *jwks_uri = json.stringOf("jwks_uri");
    const char *issuer = json.stringOf("issuer");
    bool request_uri_parameter_supported = json.BoolOf("request_uri_parameter_supported");
    const char *userinfo_endpoint = json.stringOf("userinfo_endpoint");
    const char *authorization_endpoint = json.stringOf("authorization_endpoint");
    const char *device_authorization_endpoint = json.stringOf("device_authorization_endpoint");
    bool http_logout_supported = json.BoolOf("http_logout_supported");
    bool frontchannel_logout_supported = json.BoolOf("frontchannel_logout_supported");
    const char *end_session_endpoint = json.stringOf("end_session_endpoint");
    const char *kerberos_endpoint = json.stringOf("kerberos_endpoint");
    const char *tenant_region_scope = json.stringOf("tenant_region_scope");
    const char *cloud_instance_name = json.stringOf("cloud_instance_name");
    const char *cloud_graph_host_name = json.stringOf("cloud_graph_host_name");
    const char *msgraph_host = json.stringOf("msgraph_host");
    const char *rbac_url = json.stringOf("rbac_url");
    int i = 0;
    int count_i = json.SizeOfArray("token_endpoint_auth_methods_supported");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("token_endpoint_auth_methods_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("response_modes_supported");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("response_modes_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("subject_types_supported");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("subject_types_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("id_token_signing_alg_values_supported");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("id_token_signing_alg_values_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("response_types_supported");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("response_types_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("scopes_supported");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("scopes_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("claims_supported");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("claims_supported[i]");
        i = i + 1;
    }
    }