# How to enable changing password/email by user in iOS Client

**URL:** <https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579>\
**Category:** Get Help\
**Tags:** email, users, change-password, management-api, ios\
**Created:** [June 25, 2018, 9:19pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579 "2018-06-25T21:19:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![witek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/witek/32/5170_2.png) [@witek](https://community.auth0.com/u/witek)\
**Post date:** [June 25, 2018, 9:19pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/1 "2018-06-25T21:19:56Z")

</div>

Hi, I have been struggling with the Management API on iOS. I have an app that uses Auth0 for authentication in pair with graphcool. I have implemented a client for my app that handles Auth and have added a method that wraps up Auth0s own patch function like so:

```
Auth0
    .users(token: accessToken)
    .patch(userInfo.sub, attributes: attributes)
    .start { 
    // ...
    }
}

```

The problem is that I am getting an error all the time. I am not sure which token should I use either.

I get the following response when using `access-token`:

> Failed with unknown error [“errorCode”: Bearer, “statusCode”: 400, “message”: Bad HTTP authentication header format, “error”: Bad Request]

… and with `id-token`:

> Failed with unknown error [“attributes”: { error = “Invalid token”; }, “statusCode”: 401, “message”: Invalid token, “error”: Unauthorized]

I am really desperate at the moment and have wasted a lot of time with no success.  
Maybe you guys know what am i doing wrong?

I am using RS256 for token encoding with OIDC enabled.

Thanks!

---

<div class="post-metadata">

**Author:** ![sgmeyer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgmeyer/32/3387_2.png) [@sgmeyer](https://community.auth0.com/u/sgmeyer)\
**Post date:** [June 26, 2018, 10:33am UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/2 "2018-06-26T10:33:39Z")

</div>

@witek you should be using the `access_token` when talking to the Management API (or any API) . The error message you about bad format is interesting. When you are sending in the JWT are you using this header format?

`Authorization: Bearer xxx.yyy.zzz`

You are receiving a bad request, because Auth0 thinks you are not sending in the JWT properly. The SDKL should do this for you, but it is worth double checking.

Also, can you make sure the access\_token is a valid JWT (meaning it is a JWT and not a 32 character opaque string). Also, how are you fetching the access token (e.g. what scopes and audience is set)? Can you provide the body of the JWT?

---

<div class="post-metadata">

**Author:** ![witek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/witek/32/5170_2.png) [@witek](https://community.auth0.com/u/witek)\
**Post date:** [June 26, 2018, 1:29pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/3 "2018-06-26T13:29:53Z")

</div>

Hi! thank you for your response. Well it seems my refresh token is in wrong format.

Some `refresh_token` from new account i just created: `Odep0npX4rqJ3vdAyRKyM1qGBnZ4yw9y`

the scope is: `openid profile email offline_access access_token update:users update:current_user_metadata`

the audience is: `myapp.auth0.com`

---

<div class="post-metadata">

**Author:** ![sgmeyer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgmeyer/32/3387_2.png) [@sgmeyer](https://community.auth0.com/u/sgmeyer)\
**Post date:** [June 26, 2018, 1:45pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/4 "2018-06-26T13:45:22Z")

</div>

@witek the `refresh_token` format should not be of a concern. That token is used to get a new `access_token` after the `access_token` expires. In the token response you should see `access_token` which is a JWT. Since you are trying to get a token for the Management API I would expect the audience to be something like this:

https://{tenant-name}.auth0.com/api/v2/

---

<div class="post-metadata">

**Author:** ![witek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/witek/32/5170_2.png) [@witek](https://community.auth0.com/u/witek)\
**Post date:** [June 26, 2018, 2:09pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/5 "2018-06-26T14:09:10Z")

</div>

ah! of course I meant access\_token. my mistake. After updating my audience as suggested I received following error:

`["statusCode": 404, "message": Not Found, "error": Not Found]`

---

<div class="post-metadata">

**Author:** ![sgmeyer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgmeyer/32/3387_2.png) [@sgmeyer](https://community.auth0.com/u/sgmeyer)\
**Post date:** [June 26, 2018, 3:35pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/6 "2018-06-26T15:35:22Z")

</div>

@witek changing the audience shouldn’t return a 404. Are you changing the audience or did you change the domain of your configuration?

---

<div class="post-metadata">

**Author:** ![witek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/witek/32/5170_2.png) [@witek](https://community.auth0.com/u/witek)\
**Post date:** [June 26, 2018, 3:40pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/7 "2018-06-26T15:40:44Z")

</div>

I have change domain in the `Auth0.plist`. What should I change then? I am not making the api calls directly, I am using Auth0 iOS library as shown above in the first post.

---

<div class="post-metadata">

**Author:** ![witek](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/witek/32/5170_2.png) [@witek](https://community.auth0.com/u/witek)\
**Post date:** [June 27, 2018, 7:55pm UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/8 "2018-06-27T19:55:29Z")

</div>

@sgmeyer, This is the documentation of the method I am using:

/\*\*  
Auth0 Management Users API v2 that allows CRUD operations with the users endpoint.

```auto
Auth0.users(token: token)

```

Currently you can only perform the following operations:

- Get an user by id
- Update an user, e.g. by adding `user_metadata`
- Link users
- Unlink users

Auth0 domain is loaded from the file `Auth0.plist` in your main bundle with the following content:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>ClientId</key>
   <string>{YOUR_CLIENT_ID}</string>
   <key>Domain</key>
   <string>{YOUR_DOMAIN}</string>
</dict>
</plist>

```

- parameter token: token of Management API v2 with the correct allowed scopes to perform the desired action

- parameter session: instance of NSURLSession used for networking. By default it will use the shared NSURLSession

- parameter bundle: bundle used to locate the `Auth0.plist` file. By default is the main bundle

- returns: Auth0 Management API v2

- important: Calling this method without a valid `Auth0.plist` will crash your application  
\*/

```swift
public func users(token: String, session: URLSession = .shared, bundle: Bundle = .main) -> Users {
    let values = plistValues(bundle: bundle)!
    return users(token: token, domain: values.domain, session: session)
}

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 26, 2019, 7:06am UTC](https://community.auth0.com/t/how-to-enable-changing-password-email-by-user-in-ios-client/12579/9 "2019-07-26T07:06:16Z")

</div>


