Sample code for 30+ languages & platforms
Swift

Azure Fetch OpenID Connect metadata document

See more OIDC Examples

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

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let http = CkoHttp()!

    http.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(name: "tenant", value: "6d8ddd66-68d1-44b0-af5c-e31b4b7ee5cd")
    let resp = CkoHttpResponse()!
    success = http.httpNoBody(verb: "GET", url: "https://login.microsoftonline.com/{$tenant}/v2.0/.well-known/openid-configuration", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("Response Status Code: \(resp.statusCode.intValue)")

    let json = CkoJsonObject()!
    json.load(json: resp.bodyStr)
    json.emitCompact = false
    print("\(json.emit()!)")

    if resp.statusCode.intValue != 200 {
        print("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"
    // }

    var strVal: String?

    var token_endpoint: String? = json.string(of: "token_endpoint")
    var jwks_uri: String? = json.string(of: "jwks_uri")
    var issuer: String? = json.string(of: "issuer")
    var request_uri_parameter_supported: Bool = json.bool(of: "request_uri_parameter_supported")
    var userinfo_endpoint: String? = json.string(of: "userinfo_endpoint")
    var authorization_endpoint: String? = json.string(of: "authorization_endpoint")
    var device_authorization_endpoint: String? = json.string(of: "device_authorization_endpoint")
    var http_logout_supported: Bool = json.bool(of: "http_logout_supported")
    var frontchannel_logout_supported: Bool = json.bool(of: "frontchannel_logout_supported")
    var end_session_endpoint: String? = json.string(of: "end_session_endpoint")
    var kerberos_endpoint: String? = json.string(of: "kerberos_endpoint")
    var tenant_region_scope: String? = json.string(of: "tenant_region_scope")
    var cloud_instance_name: String? = json.string(of: "cloud_instance_name")
    var cloud_graph_host_name: String? = json.string(of: "cloud_graph_host_name")
    var msgraph_host: String? = json.string(of: "msgraph_host")
    var rbac_url: String? = json.string(of: "rbac_url")
    var i: Int = 0
    var count_i: Int = json.size(ofArray: "token_endpoint_auth_methods_supported").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "token_endpoint_auth_methods_supported[i]")
        i = i + 1
    }

    i = 0
    count_i = json.size(ofArray: "response_modes_supported").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "response_modes_supported[i]")
        i = i + 1
    }

    i = 0
    count_i = json.size(ofArray: "subject_types_supported").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "subject_types_supported[i]")
        i = i + 1
    }

    i = 0
    count_i = json.size(ofArray: "id_token_signing_alg_values_supported").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "id_token_signing_alg_values_supported[i]")
        i = i + 1
    }

    i = 0
    count_i = json.size(ofArray: "response_types_supported").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "response_types_supported[i]")
        i = i + 1
    }

    i = 0
    count_i = json.size(ofArray: "scopes_supported").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "scopes_supported[i]")
        i = i + 1
    }

    i = 0
    count_i = json.size(ofArray: "claims_supported").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "claims_supported[i]")
        i = i + 1
    }


}