okta-react-native icon indicating copy to clipboard operation
okta-react-native copied to clipboard

How to update user profile with accessToken?

Open 0x000111 opened this issue 2 years ago • 0 comments

Describe the bug?

Hi Team, I'm integrating this SDK to my react native application and using browser-sign-in to get the accessToken. I need update some attribute of user profile. My OKTA api scope as below:

okta.myAccount.profile.manage
okta.myAccount.profile.read
okta.users.manage
okta.users.manage.self
okta.users.read
okta.users.read.self

And code likes below:

import {
  getAuthClient,
} from '@okta/okta-react-native'

async function updateProfile(accessToken: string) {
    const oktaAuth = getAuthClient()
    oktaAuth.myaccount.updateProfile(oktaAuth, {
            payload: {
              profile: {
                deviceID: 'alert(12345)', // my custom attribute
              },
            },
            accessToken: 'Bearer ' + accessToken,
          }).then((res: any) => {
            console.log(res)
          })
          .catch((err: any) => {
            console.log(err)
          })
}

// after login with browser-sign-in...
updateProfile('my_access_token')
// .....

Then getting below error in console:

[AuthSdkError: AccessToken is required to request MyAccount API endpoints.]

I don't know why get this error and how i fix this problem?

What is expected to happen?

update profile success

What is the actual behavior?

getting error:

[AuthSdkError: AccessToken is required to request MyAccount API endpoints.]

Reproduction Steps?

code as above.

Additional Information?

No response

SDK Version

"@okta/okta-react-native": "^2.9.1", "okta-auth-js": "7.3.0"

Build Information

No response

0x000111 avatar Dec 19 '23 07:12 0x000111