# API Authentication

**URL:** <https://discuss.openedx.org/t/api-authentication/7218>\
**Category:** Site Operators\
**Tags:** api, how-to, tutor\
**Created:** [May 12, 2022, 2:01pm UTC](https://discuss.openedx.org/t/api-authentication/7218 "2022-05-12T14:01:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShreehariVaasishta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/shreeharivaasishta/32/3544_2.png) [@ShreehariVaasishta](https://discuss.openedx.org/u/ShreehariVaasishta)\
**Post date:** [May 12, 2022, 2:01pm UTC](https://discuss.openedx.org/t/api-authentication/7218/1 "2022-05-12T14:01:18Z")

</div>

Hi, im trying to make a request using API to update profile information of a user.  
I tried using access tokens but it is returning the 403 forbidden error.  
I followed the process here to generate access tokens and use it. but its not helping - [edx-platform/0003-use-jwt-as-oauth-tokens-remove-openid-connect.rst at master · openedx/edx-platform · GitHub](https://github.com/openedx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/docs/decisions/0003-use-jwt-as-oauth-tokens-remove-openid-connect.rst).

The problem statement here is, i should be able to update full name, country, and other such account details for any user using the API.

Any help or guidance will be helpful.  
Thank you

---

<div class="post-metadata">

**Author:** ![feanil](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/feanil/32/37_2.png) [@feanil](https://discuss.openedx.org/u/feanil)\
**Post date:** [May 13, 2022, 12:14pm UTC](https://discuss.openedx.org/t/api-authentication/7218/2 "2022-05-13T12:14:37Z")

</div>

How did you get the access token @ShreehariVaasishta ? What endpoint or series of steps did you follow?

---

<div class="post-metadata">

**Author:** ![ShreehariVaasishta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/shreeharivaasishta/32/3544_2.png) [@ShreehariVaasishta](https://discuss.openedx.org/u/ShreehariVaasishta)\
**Post date:** [May 14, 2022, 6:14am UTC](https://discuss.openedx.org/t/api-authentication/7218/3 "2022-05-14T06:14:13Z")

</div>

Hi @feanil, i should have included a detailed info with respect to it, sorry for that.  
I created an application here [http://local.overhang.io/admin/oauth2\_provider/application/](http://local.overhang.io/admin/oauth2_provider/application/) through the Django admin panel. client\_id and client secret were prefilled so did not make any changes. i have set the user with superuser access. The below screenshot shows the info in that particular instance.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/3/32b33cddc6ac1f451ae8bb74fb37ede39ed17dbe.png)

After that i made a request to [http://local.overhang.io/oauth2/access\_token/](http://local.overhang.io/oauth2/access_token/) to get the access token.

```bash
curl -X POST -d "client_id=MLoAsrMoXYCfGe3lmerbKOJkZi89eHWbrgPk6JWr&client_secret=KkbfT1rXZbEaSEiq8MfyyXUzQjYijyZeDzkhmy3WQCxzgQau71rHGdKA7iMAnNlYREwl50hj7jdqdZnBQpG9b4sdIpo92klOPkdHbdBCuNe9mDKVAHTeF7ioJzUJGci1&grant_type=client_credentials" http://local.overhang.io/oauth2/access_token/

```

I then used the same access token in the below request to change the full name of a user.

```bash
curl 'http://local.overhang.io/api/user/v1/accounts/stefan@example.com' \
  -X PATCH -H 'Authorization: Bearer pFHqjG66aqyYlkOObSd4uaKXxDLzlb' \
  -H 'content-type: application/merge-patch+json' \
  --data-raw '{"name":"RandomFulll Name34"}'

```

---

<div class="post-metadata">

**Author:** ![ShreehariVaasishta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/shreeharivaasishta/32/3544_2.png) [@ShreehariVaasishta](https://discuss.openedx.org/u/ShreehariVaasishta)\
**Post date:** [May 14, 2022, 7:46am UTC](https://discuss.openedx.org/t/api-authentication/7218/4 "2022-05-14T07:46:22Z")

</div>

This is the particular error traceback.

```bash
lms_1 | 2022-05-14 07:43:51,946 WARNING 7 [openedx.core.djangoapps.user_api.helpers] [user 57] [ip 172.20.0.1] helpers.py:68 - A handled error occurred when calling 'update_account_settings' with arguments '(<User: api-user>, {'name': 'Hayssssssyyy'})' and keyword arguments '{'username': 'lipefa3301@angeleslid.com'}': UserNotAuthorized()

```

From my limted knowledge of edx codebase, i think the exception is raised in this line -

> <https://github.com/openedx/edx-platform/blob/6a2adde87c79e25a8bbcd1442273851a5bb2aecc/openedx/core/djangoapps/user_api/accounts/api.py#L129>

Is there any way to overcome this exception?

---

<div class="post-metadata">

**Author:** ![feanil](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/feanil/32/37_2.png) [@feanil](https://discuss.openedx.org/u/feanil)\
**Post date:** [May 16, 2022, 3:56pm UTC](https://discuss.openedx.org/t/api-authentication/7218/5 "2022-05-16T15:56:05Z")

</div>

So looking at that piece of code, the API only allows you to change your own usernames and not the user names of other users. I think because you’re trying to change the username of a different user, it’s not allowed.

> [@ShreehariVaasishta](#):
>
> The problem statement here is, i should be able to update full name, country, and other such account details for any user using the API.

To come back to your problem statement, I don’t think this API endpoint is built for that. I believe others have built extensions and plugins that can do what you want but it may not be there in the core platform.

I think [eox-core](https://github.com/eduNEXT/eox-core) can provide you a lot of user management capabilities so you may want to have a look at that.

---

<div class="post-metadata">

**Author:** ![ShreehariVaasishta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/shreeharivaasishta/32/3544_2.png) [@ShreehariVaasishta](https://discuss.openedx.org/u/ShreehariVaasishta)\
**Post date:** [May 16, 2022, 5:36pm UTC](https://discuss.openedx.org/t/api-authentication/7218/6 "2022-05-16T17:36:25Z")

</div>

Thanks a lot for clarifying it and sharing the resource @feanil.
