How to implement email change with verification

On the end user settings page, users can edit their email address and/or their secondary email address. When they do this, an email verification is sent to the new address before the change goes through. I could not find any Okta APIs that support this feature. Do they exist? Or how can we achieve this same thing?

Thanks!

Did you take a look at this API call: POST /api/v1/users/me

I tried that using Postman with the interceptor turned on. It did not work, Iā€™m getting 403 Forbidden. When I change the request mode to GET, it goes through fine. But when I change it to POST, it shows 403 Forbidden. The request body contains a JSON profile object with my updates.

Hi cat!

Iā€™m jumping in here because your original question was one I had on my to-do list to verify (pun intended).

First to address your last thing, ā€œ/users/meā€ works if either the session cookie or the API access token is passed with the request (from the org authorization server, not a custom authorization server including default). So, if you capture cookies with the Postman interceptor and Postman sends the session cookie with the request it should work. I verified the API call over the weekend. I think maybe something is amiss in your interceptor configuration. Maybe youā€™re not hanging on to the session cookie?

Number two, just FYI developer accounts for me donā€™t seem to ever send an email to the secondEmail address now. This changed about a year ago. Production accounts still do. So if you are using a developer account for testing that could be an issue. @Andrea, any thoughts on that?

Number three: I want to refer Andrea back to the original question about generating a confirmation email. As I said earlier, this was on my list because when you change the email or secondEmail via ā€œmeā€ using POST it just changes them blindly. If there is a way to force a confirmation email Iā€™d love to know it because I too have not found that in the API. Maybe itā€™s a developer vs production tenant thing?

Number four: FYI, if you change the email address it changes the login too. If you donā€™t want that, you have to specify both ā€œemailā€ and ā€œloginā€ in the data to the POST call to ā€œmeā€. But Iā€™m guessing for your circumstances this is not an issue.

Joel

1 Like

Thanks Joel, that is all helpful information. As for Postman - itā€™s strange that the call works fine if I switch the request mode to GET. Itā€™s only the POST version that fails. If I wanted to use a API access token then would I need to make my test user an admin, log in with their account, create one for them, and then use it in the users/me request? Otherwise how would Okta know who ā€œmeā€ is in that context?

Without the API token (which, youā€™re right, can only be generated by Admins), the ā€˜meā€™ context is ascertained by the Okta session cookie (ā€˜sidā€™). If you log into Okta in the browser, youā€™ll be able to access the /users/me endpoint in another tab based on the presence of this cookie.

@jmussman I actually hadnā€™t seen that behavior difference between a dev and a production org. So youā€™re saying the production org behaves as desired?

@andrea how can we trigger the email-based flow to verify the new email set by the POST to /users/me?

@cat Just FYI to get the Postman to work (your second response in this thread) the Origin header has to be set to the same as the original application request that set the ā€œsidā€ (session) cookie. I donā€™t know of any documentation that states this. The GET request doesnā€™t require this so I suspected a header issue and and I isolated the Origin header in the POST request. I confirmed this is only an issue if the ā€œsidā€ cookie is relied on to provide authorization for users/me in the API. If you use a bearer access token Origin doesnā€™t matter.

I still donā€™t have an answer for your last question to Andrea which is the important one, I hope she finds one :slight_smile:

1 Like

@cat FYI I did a whole bunch of testing to verify some stuff, the concise results are:

  • My developer accounts have a secondEmail, but it doesnā€™t appear in the user interface (look at settings) and it isnā€™t used. Just FYI in case youā€™re trying it there.
  • If you change either the primary email or secondEmail through the API, it assumes it is verified (look at the users/me with GET), putting the burden of verification on the application. Tested in both developer and production tenants.
  • If an admin changes a user email the same thing happens, it is assumed to be verified.
  • Confirmation that if you change the primary email the username changes. Support says that you could separate them in the request and make them different, but in default tenants the user cannot change the username property so it is rejected with a 403. You can change the rights for the user in the profile editor.

So the behavior is the same in a production tenant for updating secondEmail; it just puts it in as verified. @andrea, that leaves us back at the original question: can we change the secondEmail and have it marked as unverified and get a verification email sent? Probably a support ticket needs to be opened about this @cat.

1 Like

yeah, I agree, a support case would likely be the best way to investigate @catā€™s issue further.

Thank you Joel for those details! It is very helpful and will help many others as well Iā€™m sure. Sounds good. I will open a support case. Iā€™ll post back here with any progress.

I reached out to support, and they said that the feature does not exist. If you are interested in this feature, please upvote the Okta Ideas post I made for it: https://ideas.okta.com/app/#/case/144087

1 Like

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