# Creating a login endpoint for asp.net api

**URL:** <https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444>\
**Category:** JWT.io\
**Tags:** jwt, api, auth0\
**Created:** [June 20, 2018, 4:38am UTC](https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444 "2018-06-20T04:38:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shehan.f](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@shehan.f](https://community.auth0.com/u/shehan.f)\
**Post date:** [June 20, 2018, 4:38am UTC](https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444/1 "2018-06-20T04:38:04Z")

</div>

Hi all,  
I’v been stuck with a process of authenticating a user from a web API. Here is my scenario, I have a web API where i need to get user credentials and authenticate that user against auth0 and send that incoming access token to user for further usage inside the application. But to do that i need to add some custom claims to my access token when i receive that from auth0 side. Such as user roles. So in order to do that i haven’t found a custom way to add claims to the access token directly so i came up with a solution where i have to recreate the JWT token with custom claims that im getting from auth0. For that i need a secrete key i think but im not sure where to find that. Can you provide me a way of finding that ? or point me in a direction where i can do this the proper way.  
The we api is a .net web api. And i have configured it according to the sample documentation that has given in auth0 site.  
and the endpoint im using to authenticate user is “oauth/token”.

If there is anything there to resolve this issue please let me know. Any help would be grateful.  
Thank you.

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [June 20, 2018, 2:37pm UTC](https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444/3 "2018-06-20T14:37:30Z")

</div>

👋 @shehan.f we can add claims to the access token using [Rules](https://auth0.com/docs/rules/current).

An example of a Rule in Auth looks something like the following:

```auto
function (user, context, callback) {
  var namespace = 'https://example.com/';
  context.accessToken[namespace + 'username'] = user.name;
  context.idToken[namespace + 'favorite_color'] = user.favorite_color;
  callback(null, user, context);
}

```

and then your API will verify the scopes present in the access token.

Some relevant documentation that may be helpful for you or others:

> **[Scopes](https://auth0.com/docs/get-started/apis/scopes)**
>
> Understand the principle of scopes and explore general examples of their use.

> **[Validate Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens)**
>
> Describes how to validate an access token.

This should be a good start. Let me know if this helps and if any other issues come up!

---

<div class="post-metadata">

**Author:** ![shehan.f](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@shehan.f](https://community.auth0.com/u/shehan.f)\
**Post date:** [June 21, 2018, 11:26am UTC](https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444/4 "2018-06-21T11:26:15Z")

</div>

Hi Kim,  
I actually came across this. but as far as i found this rule applies from auth0 side yeah? and the values such as user name and favourit color can be found on user meta data ?  
But what i want to do is add custom claims from my local database. And right now i kinda found a way by using a custom AuthorizeAttribute.

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [July 17, 2018, 7:37pm UTC](https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444/5 "2018-07-17T19:37:44Z")

</div>

👋 @shehan.f I apologize for the delayed follow up, were you able to solve your issue with custom claims? Please let me know if you still require assistance.

---

<div class="post-metadata">

**Author:** ![shehan.f](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@shehan.f](https://community.auth0.com/u/shehan.f)\
**Post date:** [July 18, 2018, 4:09am UTC](https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444/6 "2018-07-18T04:09:58Z")

</div>

Hey @kimcodes, yeah actually as i said i did it using a custom authorize attribute.

---

<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:** [December 17, 2018, 10:57am UTC](https://community.auth0.com/t/creating-a-login-endpoint-for-asp-net-api/12444/7 "2018-12-17T10:57:46Z")

</div>


