# Add scopes to bearer token

**URL:** <https://community.auth0.com/t/add-scopes-to-bearer-token/70308>\
**Category:** Get Help\
**Created:** [September 27, 2021, 1:14pm UTC](https://community.auth0.com/t/add-scopes-to-bearer-token/70308 "2021-09-27T13:14:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evert](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evert/32/30553_2.png) [@evert](https://community.auth0.com/u/evert)\
**Post date:** [September 27, 2021, 1:14pm UTC](https://community.auth0.com/t/add-scopes-to-bearer-token/70308/1 "2021-09-27T13:14:03Z")

</div>

I have successfully created an Angular SPA which communicates with a REST backed. For this backend, I created Permission (aka Scopes) like “read:persons”, “edit:persons” ect.

I also created a small C# program for which I like to do some testing with the REST backend. So I copied code from the auth0 ‘Test’ tab of my API application to get a token. This generates the following code for me:

```auto
var client = new RestClient("https://dev-<my auth0-url>.com/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"client_id\":\"<my-auth0-id>\",\"client_secret\":\"<my-auth-secret>\",\"audience\":\"<my-auth0-audience>\",\"grant_type\":\"client_credentials\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

```

Now, when I embed this code into my console application the scopes are missing from this token. It is not clear how to add these to the token, I tried adding something like:

```auto
 \"scope\":\"read:persons\" 

```

but this fails.

How can I add the scope?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 27, 2021, 9:04pm UTC](https://community.auth0.com/t/add-scopes-to-bearer-token/70308/3 "2021-09-27T21:04:56Z")

</div>

Hi @evert,

Have you [granted API access and assigned scopes](https://auth0.com/docs/architecture-scenarios/server-api/part-2#configure-application-s-access-to-the-api) to your C# application in the dashboard?

---

<div class="post-metadata">

**Author:** ![evert](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/evert/32/30553_2.png) [@evert](https://community.auth0.com/u/evert)\
**Post date:** [September 29, 2021, 7:07am UTC](https://community.auth0.com/t/add-scopes-to-bearer-token/70308/4 "2021-09-29T07:07:35Z")

</div>

Ah, I now see, it does not work this way, copying the generated C# code from the ‘Test’ tab. I started over and created a small test Windows UWP application and this works. I only needed to supply the scopes on creation in and the audience when logging in. Here is the code of the UWP view, maybe it helps others because the documentation is not obvious on this point (or I cannot find it):

```auto
Constructor:
public YourConstructor
{
  _client = new Auth0Client(new Auth0ClientOptions
  {
         Domain = "<your domain>",
         ClientId = "<your client id>",
         Scope = "openid email profile read:persons edit:persons <etcetera>" 
  });
}

Signin Button:
private async void SignIn_Click(object sender, RoutedEventArgs e)
{
    LoginResult loginResult = await _client.LoginAsync(new
    {
          audience = "https://<your audience>" //This is the identifier of your REST API
    }); 
    if (loginResult.IsError) return;

}

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 29, 2021, 10:20pm UTC](https://community.auth0.com/t/add-scopes-to-bearer-token/70308/5 "2021-09-29T22:20:45Z")

</div>

Thanks for providing your solution!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 14, 2021, 10:20pm UTC](https://community.auth0.com/t/add-scopes-to-bearer-token/70308/6 "2021-10-14T22:20:59Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
