TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Naruto Reddy
NA
123
38.8k
Azure AD with Bearer token authentication for Web API not working
Jul 25 2020 6:20 AM
I have developed Azure Ad authentication for a Web APi using the example from Git site [https://github.com/Azure-Samples/ms-identity-aspnet-webapi-onbehalfof/tree/master/TodoListService] I have been facing an issue with Azure Ad authentication. Please find the code below.
Action method from Controller1 class.
[RoutePrefix(
"api/hospitals"
)]
public
class
HospitalsController : ApiController
{
[Route(
"GetAll"
)]
[HttpGet]
[PmAuthorize(Constants.Roles.Admin,Constants.Roles.Doctor)]
public
async Task<IEnumerable> GetAll()
{
//return data;....
}
}
My startup.auth.cs file
public
partial
class
Startup
{
string
clientId = System.Configuration.ConfigurationManager.AppSettings[
"ClientId"
];
string
redirectUri = System.Configuration.ConfigurationManager.AppSettings[
"RedirectUri"
];
static
string
tenant = System.Configuration.ConfigurationManager.AppSettings[
"Tenant"
];
string
authority = String.Format(System.Globalization.CultureInfo.InvariantCulture,
System.Configuration.ConfigurationManager.AppSettings[
"Authority"
],
tenant);
public
void
ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = tenant, TokenValidationParameters =
new
TokenValidationParameters
{
SaveSigninToken =
true
, ValidAudience = clientid }
});
}
}
WebApiConfig.cs
public
static
class
WebApiConfig
{
public
static
void
Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(name:
"DefaultApi"
,routeTemplate:
"api/{controller}/{id}"
,
defaults:
new
{ id = RouteParameter.Optional } );
config.Filters.Add(
new
ExceptionHandlingAttribute());'
} }
When ever i am calling a action method/api method call from hospital controller by passing token getting the error as "Authorization has been denied for this request."
Can some one help me here ?.
Please add any comments if any addition info required ?
Thanks in advance.
Reply
Answers (
1
)
How to get the name from AD
What is Azure Active Directory and how it is used