Back

"User(role:guests) missing scope" when creating JWT

  • 0
  • Accounts
  • Web
Husnain_bashir
26 Mar, 2023, 14:54

Need help. I am trying to create JWT token on rest api (Client) with post request but I am getting this response {"message":"User(role:guests) missing scope (account)","code":401,"type":"general_unauthorized_scope"......... . I have created email session but still getting this response.

TL;DR
The user is trying to create a JWT token using the REST API, but is receiving a "User(role:guests) missing scope" error. They have already created an email session but are still encountering the issue. The solution mentioned is to make sure to log in first before creating the JWT token.
Drake
26 Mar, 2023, 16:17

"User(role:guests) missing scope" when creating JWT

Drake
26 Mar, 2023, 16:17

role:guests indicates you don't have a valid session. You need to log in first

Husnain_bashir
27 Mar, 2023, 00:49

Noted, but Sir I have created an email session using rest API and after I got user credentials then I posted a JWT request.

Drake
27 Mar, 2023, 00:51

Sure, but the session you created wasn't used when making the create JWT API call

Drake
27 Mar, 2023, 00:51

Can you tell me more about your tech stack?

Husnain_bashir
27 Mar, 2023, 00:52

Docker

Drake
27 Mar, 2023, 00:53

I meant for your front end app

Husnain_bashir
27 Mar, 2023, 00:54

Sir, I am making call from Android using client rest API. Wanted to use Android sdks but they are in aar instead of Jar, and App inventor only allow Jar files. So, using rest API.

Drake
27 Mar, 2023, 00:56

I see. So you may have to manually manage the session by making sure the cookie is used in the subsequent requests. See https://appwrite.io/docs/rest#client-auth

Husnain_bashir
27 Mar, 2023, 00:56

Is there a way, I pass user id or session I'd from user credentials in rest request for JWT to make JWT request.

Husnain_bashir
27 Mar, 2023, 01:00

I am able to create user successfully and then able to log them in using rest. Also able to get all documents with rules(any) but when I try to change rules to only logged in, not getting any data despite I have logged in user in previous request. So thought that my might pass user JWT to get data. That's the reason of creating a JWT for me.

Drake
27 Mar, 2023, 01:00

Did you read what I linked?

Husnain_bashir
27 Mar, 2023, 01:05

Sir, I created session the response I am getting is below (example response) but their is no cookie in response. { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", "userId": "5e5bb8c16897e", "expire": "2020-10-15T06:38:00.000+00:00", "provider": "email", "providerUid": "user@example.com", "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", "ip": "127.0.0.1", "osCode": "Mac", "osName": "Mac", "osVersion": "Mac", "clientType": "browser", "clientCode": "CM", "clientName": "Chrome Mobile iOS", "clientVersion": "84.0", "clientEngine": "WebKit", "clientEngineVersion": "605.1.15", "deviceName": "smartphone", "deviceBrand": "Google", "deviceModel": "Nexus 5", "countryCode": "US", "countryName": "United States", "current": true }

Drake
27 Mar, 2023, 01:05

Cookies are always sent in the header

Husnain_bashir
27 Mar, 2023, 01:10

So, When I create a session using email, I will get body response in above format and I also get cookie in header of response.

Husnain_bashir
27 Mar, 2023, 01:11

Will try, thaks

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more