microsoft-authentication-library-for-objc icon indicating copy to clipboard operation
microsoft-authentication-library-for-objc copied to clipboard

Is certificate based authentication possible with this library?

Open dalemyers opened this issue 8 months ago • 1 comments

I'm trying to port some code from an Android app to an iOS app and I can't figure out how to perform certificate based authentication. Here's what we are using on Android (some details omitted and others simplified):


fun getTokenFromCertificate(context: Context): String {
    val cf = CertificateFactory.getInstance("X.509")
    val cert = cf.generateCertificate(FileInputStream("/path/to/cert.pfx"))
    val key = loadPrivateKey() as PrivateKey

    val clientCertificate: IClientCertificate = ClientCredentialFactory.createFromCertificate(key, cert as X509Certificate)
    val app: ConfidentialClientApplication =
        ConfidentialClientApplication.builder(applicationID, clientCertificate)
            .authority(torusAuthorityUrl)
            .build()

    val scope = setOf("$myAudienceId/.default")

    var result: IAuthenticationResult = app.acquireToken(ClientCredentialParameters.builder(scope).build()).get()

    return result.accessToken()
}

However, I can't get anywhere with this for iOS. As far as I can tell, this library doesn't support certificate based authentication at all. Searching for certificate only reveals two hits, neither of which are relevant.

How can I perform cert based auth with this library?

Thanks!

dalemyers avatar Jun 18 '24 14:06 dalemyers