Sample code for 30+ languages & platforms
Rust 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 Rust Downloads

Rust

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

let http = chilkat::Http::new();

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

let _ = http.set_url_var("tenant", "6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd").is_ok();
let resp = chilkat::HttpResponse::new();
if http.http_no_body("GET", "https://login.microsoftonline.com/{$tenant}/v2.0/.well-known/openid-configuration", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

println!("Response Status Code: {}", resp.status_code());

let json = chilkat::JsonObject::new();
let _ = json.load(&resp.body_str());
json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());

if resp.status_code() != 200 {
    println!("Failed.");
    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"
// }

let token_endpoint = json.string_of("token_endpoint").unwrap_or_default();
let jwks_uri = json.string_of("jwks_uri").unwrap_or_default();
let issuer = json.string_of("issuer").unwrap_or_default();
let request_uri_parameter_supported = json.bool_of("request_uri_parameter_supported");
let userinfo_endpoint = json.string_of("userinfo_endpoint").unwrap_or_default();
let authorization_endpoint = json.string_of("authorization_endpoint").unwrap_or_default();
let device_authorization_endpoint = json.string_of("device_authorization_endpoint").unwrap_or_default();
let http_logout_supported = json.bool_of("http_logout_supported");
let frontchannel_logout_supported = json.bool_of("frontchannel_logout_supported");
let end_session_endpoint = json.string_of("end_session_endpoint").unwrap_or_default();
let kerberos_endpoint = json.string_of("kerberos_endpoint").unwrap_or_default();
let tenant_region_scope = json.string_of("tenant_region_scope").unwrap_or_default();
let cloud_instance_name = json.string_of("cloud_instance_name").unwrap_or_default();
let cloud_graph_host_name = json.string_of("cloud_graph_host_name").unwrap_or_default();
let msgraph_host = json.string_of("msgraph_host").unwrap_or_default();
let rbac_url = json.string_of("rbac_url").unwrap_or_default();
let mut i = 0;
let mut count_i = json.size_of_array("token_endpoint_auth_methods_supported");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("token_endpoint_auth_methods_supported[i]").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("response_modes_supported");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("response_modes_supported[i]").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("subject_types_supported");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("subject_types_supported[i]").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("id_token_signing_alg_values_supported");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("id_token_signing_alg_values_supported[i]").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("response_types_supported");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("response_types_supported[i]").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("scopes_supported");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("scopes_supported[i]").unwrap_or_default();
    i = i + 1;
}

i = 0;
count_i = json.size_of_array("claims_supported");
while i < count_i {
    json.set_i(i);
    let _ = json.string_of("claims_supported[i]").unwrap_or_default();
    i = i + 1;
}