How to retrieve phone number?

I have recently setup a working example using the code displayed here samples-php/okta-hosted-login at develop · okta/samples-php · GitHub

I have added to a user, a phone number in the attributes.

How do I retrieve that phone number and display it on the screen ?

I am using php for the back end

You’ve got three main options:

  1. Request the ‘phone’ scope in the authorize call. The ‘phone_number’ claim will be returned in the ID token (or the userinfo endpoint, if you are requesting an id_token and a token in the same authorize request, details for that behavior here)
  2. Make a CORS request to /api/v1/users/me, which will return the authenticated user’s primaryPhone and other profile attributes. As long as the session cookie for Okta is set in the browser, this call will work without additional authentication (make sure cookies are sent in the request though!). Watch out for browsers that block 3rd party cookies!
  3. Make a backend call to /api/v1/users/{{userId}}, which will return the same information but will require that an api token be included in the request.
1 Like