Zig Requires Chilkat v11.0.0+
Zig
Azure Fetch OpenID Connect metadata document
See more OIDC Examples
Downloads the OpenID Connect self-discovery document for an Azure OIDC enabled app.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
http.setAccept("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.
try http.setUrlVar("tenant", "6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("GET", "https://login.microsoftonline.com/{$tenant}/v2.0/.well-known/openid-configuration", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response Status Code: {d}\n", .{resp.getStatusCode()});
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.load(try resp.getBodyStr(alloc)) catch {};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.emit(alloc)});
if (resp.getStatusCode() != 200) {
std.debug.print("Failed.\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"
// }
var str_val: [:0]const u8 = "";
_ = try json.stringOf(alloc, "token_endpoint");
_ = try json.stringOf(alloc, "jwks_uri");
_ = try json.stringOf(alloc, "issuer");
_ = json.boolOf("request_uri_parameter_supported");
_ = try json.stringOf(alloc, "userinfo_endpoint");
_ = try json.stringOf(alloc, "authorization_endpoint");
_ = try json.stringOf(alloc, "device_authorization_endpoint");
_ = json.boolOf("http_logout_supported");
_ = json.boolOf("frontchannel_logout_supported");
_ = try json.stringOf(alloc, "end_session_endpoint");
_ = try json.stringOf(alloc, "kerberos_endpoint");
_ = try json.stringOf(alloc, "tenant_region_scope");
_ = try json.stringOf(alloc, "cloud_instance_name");
_ = try json.stringOf(alloc, "cloud_graph_host_name");
_ = try json.stringOf(alloc, "msgraph_host");
_ = try json.stringOf(alloc, "rbac_url");
var i: i32 = 0;
var count_i: i32 = json.sizeOfArray("token_endpoint_auth_methods_supported");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "token_endpoint_auth_methods_supported[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("response_modes_supported");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "response_modes_supported[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("subject_types_supported");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "subject_types_supported[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("id_token_signing_alg_values_supported");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "id_token_signing_alg_values_supported[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("response_types_supported");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "response_types_supported[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("scopes_supported");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "scopes_supported[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("claims_supported");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "claims_supported[i]");
i = i + 1;
}
}