Kelvin Yeo
Kelvin Yeo

Reputation: 112

Get user name from Azure authenticated AD in .Net Web API

I have a web API that is authenticated by Azure's AD. Within the API codes, what is the code to retrieve the username of the authenticated user?

Upvotes: 4

Views: 6377

Answers (1)

JCollerton
JCollerton

Reputation: 3307

Using System.Web.HttpContext.Current.User.Identity.Name will retrieve the email address that they have used to log in with.

As a side note, I am using this to control what the user has access to on the site. Because of how I am implementing it, it is more convenient for me to maintain a database of the usernames and their roles. However, if you are doing the same thing, it is also worth looking into [Authorize] and maintaining site access that way.

Upvotes: 5

Related Questions