AzureAD / microsoft-authentication-library-for-objc

Microsoft Authentication Library (MSAL) for iOS and macOS
http://aka.ms/aadv2
MIT License
260 stars 142 forks source link

Is certificate based authentication possible with this library? #2214

Closed dalemyers closed 2 months ago

dalemyers commented 3 months ago

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!

swasti29 commented 3 months ago

@dalemyers We do not support Certificated based Authentications for confidential clients. We do support for public clients. For more information on public clients and confidential clients, please refer: https://learn.microsoft.com/en-us/entra/identity-platform/msal-client-applications.