Unicode C
Unicode 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 Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkHttpResponseW resp;
HCkJsonObjectW json;
const wchar_t *strVal;
const wchar_t *token_endpoint;
const wchar_t *jwks_uri;
const wchar_t *issuer;
BOOL request_uri_parameter_supported;
const wchar_t *userinfo_endpoint;
const wchar_t *authorization_endpoint;
const wchar_t *device_authorization_endpoint;
BOOL http_logout_supported;
BOOL frontchannel_logout_supported;
const wchar_t *end_session_endpoint;
const wchar_t *kerberos_endpoint;
const wchar_t *tenant_region_scope;
const wchar_t *cloud_instance_name;
const wchar_t *cloud_graph_host_name;
const wchar_t *msgraph_host;
const wchar_t *rbac_url;
int i;
int count_i;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
CkHttpW_putAccept(http,L"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 = CkHttpW_SetUrlVar(http,L"tenant",L"6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd");
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpNoBody(http,L"GET",L"https://login.microsoftonline.com/{$tenant}/v2.0/.well-known/openid-configuration",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
return;
}
wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp));
json = CkJsonObjectW_Create();
CkJsonObjectW_Load(json,CkHttpResponseW_bodyStr(resp));
CkJsonObjectW_putEmitCompact(json,FALSE);
wprintf(L"%s\n",CkJsonObjectW_emit(json));
if (CkHttpResponseW_getStatusCode(resp) != 200) {
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(json);
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.
token_endpoint = CkJsonObjectW_stringOf(json,L"token_endpoint");
jwks_uri = CkJsonObjectW_stringOf(json,L"jwks_uri");
issuer = CkJsonObjectW_stringOf(json,L"issuer");
request_uri_parameter_supported = CkJsonObjectW_BoolOf(json,L"request_uri_parameter_supported");
userinfo_endpoint = CkJsonObjectW_stringOf(json,L"userinfo_endpoint");
authorization_endpoint = CkJsonObjectW_stringOf(json,L"authorization_endpoint");
device_authorization_endpoint = CkJsonObjectW_stringOf(json,L"device_authorization_endpoint");
http_logout_supported = CkJsonObjectW_BoolOf(json,L"http_logout_supported");
frontchannel_logout_supported = CkJsonObjectW_BoolOf(json,L"frontchannel_logout_supported");
end_session_endpoint = CkJsonObjectW_stringOf(json,L"end_session_endpoint");
kerberos_endpoint = CkJsonObjectW_stringOf(json,L"kerberos_endpoint");
tenant_region_scope = CkJsonObjectW_stringOf(json,L"tenant_region_scope");
cloud_instance_name = CkJsonObjectW_stringOf(json,L"cloud_instance_name");
cloud_graph_host_name = CkJsonObjectW_stringOf(json,L"cloud_graph_host_name");
msgraph_host = CkJsonObjectW_stringOf(json,L"msgraph_host");
rbac_url = CkJsonObjectW_stringOf(json,L"rbac_url");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"token_endpoint_auth_methods_supported");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"token_endpoint_auth_methods_supported[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"response_modes_supported");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"response_modes_supported[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"subject_types_supported");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"subject_types_supported[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"id_token_signing_alg_values_supported");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"id_token_signing_alg_values_supported[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"response_types_supported");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"response_types_supported[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"scopes_supported");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"scopes_supported[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"claims_supported");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
strVal = CkJsonObjectW_stringOf(json,L"claims_supported[i]");
i = i + 1;
}
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(json);
}