Unable to access claims in idToken in iOS app

I’m unable to access claims in my iOS app. I’m able to see a list of enum cases (no claim values) by running this code:

        if let token = Credential.default?.token.idToken {
            for claim in token.claims {
                print(claim)
            }
        }

If I run this code taken from here, I get an error on the third line: “Generic parameter ‘T’ could not be inferred”:

        if let token = Credential.default?.token.idToken {
            for claim in token.claims {
                let value = token[claim]
            }
        }

When I try the other examples on that page:

if let email = token[.email] {
    // Do something with the token's email address
}

if let customValue = token["customClaim"] {
    // Use the custom value
}

I get the error “Generic parameter ‘T’ could not be inferred” for each one. How do I access the values in my claims using Swift for iOS?

I’m not sure if this is the correct way to access it, but using
value = token.payload["email"]
seems to work.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.