Sample code for 30+ languages & platforms
Zig

OneLogin OIDC - Get Discovery Document (OpenID Connect)

See more OneLogin OIDC Examples

Downloads the OpenID Connect self-discovery document for a OneLogin OIDC enabled app.

Chilkat Zig Downloads

Zig
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");

    const resp = try chilkat.HttpResponse.init();
    defer resp.deinit();
    http.httpNoBody("GET", "https://<account>.onelogin.com/oidc/.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_response = try chilkat.JsonObject.init();
    defer json_response.deinit();
    json_response.load(try resp.getBodyStr(alloc)) catch {};
    json_response.setEmitCompact(false);
    std.debug.print("{s}\n", .{try json_response.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

    // {
    //   "acr_values_supported": [
    //     "onelogin:nist:level:1:re-auth"
    //   ],
    //   "authorization_endpoint": "https://chilkat-dev.onelogin.com/oidc/auth",
    //   "claims_parameter_supported": true,
    //   "claims_supported": [
    //     "acr",
    //     "auth_time",
    //     "company",
    //     "custom_fields",
    //     "department",
    //     "email",
    //     "family_name",
    //     "given_name",
    //     "groups",
    //     "iss",
    //     "locale_code",
    //     "name",
    //     "params",
    //     "phone_number",
    //     "preferred_username",
    //     "sid",
    //     "sub",
    //     "title",
    //     "updated_at"
    //   ],
    //   "grant_types_supported": [
    //     "authorization_code",
    //     "implicit",
    //     "refresh_token",
    //     "client_credentials",
    //     "password"
    //   ],
    //   "id_token_signing_alg_values_supported": [
    //     "RS256"
    //   ],
    //   "issuer": "https://openid-connect.onelogin.com/oidc",
    //   "jwks_uri": "https://chilkat-dev.onelogin.com/oidc/certs",
    //   "request_parameter_supported": false,
    //   "request_uri_parameter_supported": false,
    //   "response_modes_supported": [
    //     "form_post",
    //     "fragment",
    //     "query"
    //   ],
    //   "response_types_supported": [
    //     "code",
    //     "id_token token",
    //     "id_token"
    //   ],
    //   "scopes_supported": [
    //     "openid",
    //     "name",
    //     "profile",
    //     "groups",
    //     "email",
    //     "params",
    //     "phone"
    //   ],
    //   "subject_types_supported": [
    //     "public"
    //   ],
    //   "token_endpoint": "https://chilkat-dev.onelogin.com/oidc/token",
    //   "token_endpoint_auth_methods_supported": [
    //     "client_secret_basic",
    //     "client_secret_post",
    //     "none"
    //   ],
    //   "userinfo_endpoint": "https://chilkat-dev.onelogin.com/oidc/me",
    //   "userinfo_signing_alg_values_supported": [
    //   ],
    //   "code_challenge_methods_supported": [
    //     "S256"
    //   ],
    //   "introspection_endpoint": "https://chilkat-dev.onelogin.com/oidc/token/introspection",
    //   "introspection_endpoint_auth_methods_supported": [
    //     "client_secret_basic",
    //     "client_secret_post",
    //     "none"
    //   ],
    //   "revocation_endpoint": "https://chilkat-dev.onelogin.com/oidc/token/revocation",
    //   "revocation_endpoint_auth_methods_supported": [
    //     "client_secret_basic",
    //     "client_secret_post",
    //     "none"
    //   ],
    //   "claim_types_supported": [
    //     "normal"
    //   ]
    // }
    //

    var i: i32 = 0;
    var count_i: i32 = 0;
    var str_val: [:0]const u8 = "";

    _ = try json_response.stringOf(alloc, "authorization_endpoint");
    _ = json_response.boolOf("claims_parameter_supported");
    _ = try json_response.stringOf(alloc, "issuer");
    _ = try json_response.stringOf(alloc, "jwks_uri");
    _ = json_response.boolOf("request_parameter_supported");
    _ = json_response.boolOf("request_uri_parameter_supported");
    _ = try json_response.stringOf(alloc, "token_endpoint");
    _ = try json_response.stringOf(alloc, "userinfo_endpoint");
    _ = try json_response.stringOf(alloc, "introspection_endpoint");
    _ = try json_response.stringOf(alloc, "revocation_endpoint");
    i = 0;
    count_i = json_response.sizeOfArray("acr_values_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "acr_values_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("claims_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "claims_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("grant_types_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "grant_types_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("id_token_signing_alg_values_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "id_token_signing_alg_values_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("response_modes_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "response_modes_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("response_types_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "response_types_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("scopes_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "scopes_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("subject_types_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "subject_types_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("token_endpoint_auth_methods_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "token_endpoint_auth_methods_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("userinfo_signing_alg_values_supported");
    while (i < count_i) {
        json_response.setI(i);
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("code_challenge_methods_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "code_challenge_methods_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("introspection_endpoint_auth_methods_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "introspection_endpoint_auth_methods_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("revocation_endpoint_auth_methods_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "revocation_endpoint_auth_methods_supported[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json_response.sizeOfArray("claim_types_supported");
    while (i < count_i) {
        json_response.setI(i);
        str_val = try json_response.stringOf(alloc, "claim_types_supported[i]");
        i = i + 1;
    }
}