asp.net-core-webapi

How to authenticate a user when consuming MassTransit messages in Asp.Net Core Web API?

孤街浪徒 提交于 2021-01-21 05:06:42
问题 I have several Asp.Net Core Web APIs that use Bearer authentication and IdentityServer4.AccessTokenValidation middleware to introspect tokens, authenticate the user and create claims. This works fine for HTTP requests. I am in the process of configuring these APIs to also be MassTransit endpoints (for both Publishing and Consuming messages) using RabbitMQ as transport. I followed the instructions here for adding MassTransit to the API and for setting up message consumers. A typical workflow

IActionResult vs ObjectResult vs JsonResult in ASP.NET Core API

两盒软妹~` 提交于 2021-01-18 04:10:48
问题 What's the best option to use in a Web API that will return both HTTP status codes and JSON results? I've always used IActionResult but it was always a Web App with a Web API. This time it's only Web API . I have the following simple method that's giving me an error that reads: Cannot implicitly convert type Microsoft.AspNetCore.Mvc.OkObjectResult to System.Threading.Tasks.Task Microsoft.AspNetCore.Mvc.IActionResult [HttpGet] public Task<IActionResult> Get() { return Ok(); } 回答1: Return the

What is the difference between File(), PhysicalFile(), PhysicalFileResult() in ASP.NET Core?

こ雲淡風輕ζ 提交于 2021-01-05 11:34:11
问题 I am trying to build a Web API endpoint using ASP.NET core 3.1 what would allow an application to send me an id, and the response would be with the corresponding file. Here is my method [HttpGet("get")] public IActionResult Get(Guid id) { FoundFileInfo file = PathFinder.Get(id); if(file == null || !System.IO.File.Exists(file.Fullname)) { return NotFound(); } return File(file.Fullname, "image/jpeg"); } using the same code, I can return File(file.VirtualName, "image/jpeg") , new

Sign in to ASP.Net Core Web Application -> API with Individual User Accounts using Azure AD B2C

泪湿孤枕 提交于 2021-01-01 10:04:18
问题 I have set up a Web Application with ASP.NET Razor Pages with -> Individual User Accounts -> Connect to an existing user store in the cloud (Azure AD B2C). This works really well and I could both sign up and sign in to the web application. However when I follow the guide for API I don't understand how to sign in. The example Controller /weatherforecast simply returns a HTTP 401 when the web application is started. Looking at the file structure I can't find any clues either but this could be

Bearer error=“invalid_token”, error_description=“The signature is invalid”

徘徊边缘 提交于 2020-12-30 05:55:10
问题 I have a angular application that request a token from azure. The login went well and I get a token. This token is now send from the angular app to a net core webapi application. Net core should verify this token but failed. I think the webapi should also contact azure to validate the token because it has no knowledge of the private and public key that is needed to verify the token. At the moment it is not clear why it is failing. Both angular app and the webapi are running local on my

Add claims in token from web api

柔情痞子 提交于 2020-12-30 03:46:58
问题 I'm working on a project using IdentityServer4 and Identity and an API. The API is protected with IDS4. The API and IDS4 are on the same project, so I have 3 projects in my solutions: - A MVC web project that contains the IdentityServer and the API - An implementation of Identity that use MongoDB as database provider - A console application that simulate the client My client authenticate with IDS4, get the access_token and then call the api with the token. This part is working fine. Now i'm

Add claims in token from web api

风格不统一 提交于 2020-12-30 03:46:06
问题 I'm working on a project using IdentityServer4 and Identity and an API. The API is protected with IDS4. The API and IDS4 are on the same project, so I have 3 projects in my solutions: - A MVC web project that contains the IdentityServer and the API - An implementation of Identity that use MongoDB as database provider - A console application that simulate the client My client authenticate with IDS4, get the access_token and then call the api with the token. This part is working fine. Now i'm

How to disable caching for all WebApi responses in order to avoid IE using (from cache) responses

雨燕双飞 提交于 2020-12-29 12:21:04
问题 I have a simple ASP.NET Core 2.2 Web Api controller: [ApiVersion("1.0")] [Route("api/[controller]")] [ApiController] public class TestScenariosController : Controller { [HttpGet("v2")] public ActionResult<List<TestScenarioItem>> GetAll() { var entities = _dbContext.TestScenarios.AsNoTracking().Select(e => new TestScenarioItem { Id = e.Id, Name = e.Name, Description = e.Description, }).ToList(); return entities; } } When I query this action from angular app using @angular/common/http : this

Password reset token provider in ASP.NET core - IUserTokenProvider not found

怎甘沉沦 提交于 2020-12-29 04:27:27
问题 Hello, I googled thoroughly but there is hundred examples from ASP.NET but nothing about ASP.NET Core. In order to getting password reset work I need to register an IUserTokenProvider instance into DI. Without it I get exception at following line: var result = await _userManager.ResetPasswordAsync(user, token, password); Exception "No IUserTokenProvider named 'PasswordResetTokenProvider' is registered." That makes sense so I tried to register it in the DI: services.AddSingleton

Password reset token provider in ASP.NET core - IUserTokenProvider not found

不问归期 提交于 2020-12-29 04:27:06
问题 Hello, I googled thoroughly but there is hundred examples from ASP.NET but nothing about ASP.NET Core. In order to getting password reset work I need to register an IUserTokenProvider instance into DI. Without it I get exception at following line: var result = await _userManager.ResetPasswordAsync(user, token, password); Exception "No IUserTokenProvider named 'PasswordResetTokenProvider' is registered." That makes sense so I tried to register it in the DI: services.AddSingleton