Retrieve current user email

Hi everyone,

I couldn’t find a way to retrieve the current user’s email address. Does anyone know how to do that?

Thanks for your help!

Platform: iOS 11.0 | Xcode 9.3.1 | Swift 4.1

Hey @berty, can you give us some more details about what you are building? Are you using our iOS AppAuth SDK?

Hi @nate.barbettini,

Thanks for your reply! I’m indeed using the AppAuth SDK for iOS.

Basically, I would like to save and then retrieve the email address of the current user after he/she has logged in. Is that possible?

It is! See this part of the documentation: Get UserInfo
You should be able to do something like:

OktaAuth.login().start(view: self)
.then { _ in
    OktaAuth.userinfo() { response, error in
        if error == nil {
            let email = response!["email"]
        } else {
.catch { error in
    // Error

I haven’t compiled that, but it should be close. :slight_smile:

Thanks @nate.barbettini for your help!!!

Side note: the user info dictionary doesn’t contain an email key. You need to access the value associated with the key preferred_username to get the user’s email address.