asp.net-core-webapi

AspNet core web Api usage of ApiControllerAttribute

谁说我不能喝 提交于 2020-05-29 07:17:29
问题 When I create a new controller in the API project, it generates a controller class with [ApiController] attribute, like this: [ApiController] public class TestController : ControllerBase { //implementation } I've seen a few webapi projects where usage of this attribute is omitted. Microsoft documentation here says: Indicates that a type and all derived types are used to serve HTTP API responses. The presence of this attribute can be used to target conventions, filters and other behaviors

Secure swagger docs page with username and password Asp Net Core 2.1

谁都会走 提交于 2020-05-26 04:17:19
问题 I am using Asp.Net Core 2.1 Web Api with Swashbuckle.aspnetcore.swagger I want to secure api documentation page with username and password before granting access. Sample documention page To make sure its not accessible by the public 回答1: Copied from mguinness's answer on Github: In .NET Core you use middleware, instead of a DelegatingHandler: public class SwaggerAuthorizedMiddleware { private readonly RequestDelegate _next; public SwaggerAuthorizedMiddleware(RequestDelegate next) { _next =

Autorest error - swagger.json' is not a valid OpenAPI 2.0 definition (expected 'swagger: 2.0')

时光总嘲笑我的痴心妄想 提交于 2020-05-23 13:54:25
问题 My api is running net core 3.0 with Swashbuckle.AspNetCore 5.0.0-rc5 When I run autorest on my generated swagger.json file I get: swagger.json is not a valid OpenAPI 2.0 definition (expected 'swagger: 2.0') My swagger.json file does indeed say "openapi": "3.0.1". It used to be v2.0 but since I upgraded to net core 3.0 I had to upgrade Swashbuckle which now creates the json file with v3.0.1 I ran "choco install autorest" so I should be running the latest version If autorest doesn't support

How to send multipart/form-data to asp.net core web api?

一笑奈何 提交于 2020-05-17 04:46:28
问题 I'm trying to send a image and textfields to a api endpont but i'm reciving "Unsupported content type 'multipart/form-data; boundary=---------------------------81801171514357" This is a ASP.NET Core 2.1 Web api. I have this: [HttpPost("/api/account"), Authorize] public void SaveUser(UserModel info) And my model: [JsonProperty(PropertyName = "avatar")] [DataType(DataType.Upload)] public IFormFile Avatar { get; set; } [JsonProperty(PropertyName = "name")] [DataType(DataType.Text)] public string

Angular 9 throw error 'missing required parameter' on requesting token from Azure B2C

送分小仙女□ 提交于 2020-05-16 22:36:28
问题 I am working on Angular 9 application with .NET CORE Web API 3.1 application. I configure Angular client App to authenticate using Auth 2.0 Azure B2C and angular-oauth2-oidc in Angular. I am getting error on requesting token and CORS Policy in Browser. Screen shot at the end {"error":"invalid_request","error_description":"AADB2C90083: The request is missing required parameter: grant_type.\r\nCorrelation ID: xxxx5370-695b-4f09-b583-e67600000000\r\nTimestamp: 2020-05-07 15:23:06Z\r\n"} I

Calling an Azure AD secured Web API from Angular Frontend

雨燕双飞 提交于 2020-05-15 08:28:05
问题 I am currently developing an Angular Frontend, which uses MSAL to authenticate users. This Frontend should call a Web-API (also hosted in Azure), which is secured by Azure Active Directory. While I easily managed to work with Angular and MSAL, getting a Token and successfully calling Graph/me as test, I cannot get the API call to work, I'm always receiving 401's. I'm using the following setup: Angular frontend with MSAL I created an Application in AAD, gave it User.Read permissions for MS

How set up Ocelot Api Gateway with Azure Active Directory

孤街浪徒 提交于 2020-05-12 05:31:37
问题 I followed this tutorial and managed to use api with Azure Active Directory authentication & authorization. However I would like to consume the api from behind the Ocelot Api Gateway. I could use ocelot with custom basic authorization but could not accomplish to use with Azure Active Directory. I have added Ocelot api gateway url to my api redirect url list already. How should I set ReRoutes values in config.json and Ocelot Api Gateway project StartUp.cs ? Any help will be appreciated. 回答1:

How set up Ocelot Api Gateway with Azure Active Directory

 ̄綄美尐妖づ 提交于 2020-05-12 05:30:04
问题 I followed this tutorial and managed to use api with Azure Active Directory authentication & authorization. However I would like to consume the api from behind the Ocelot Api Gateway. I could use ocelot with custom basic authorization but could not accomplish to use with Azure Active Directory. I have added Ocelot api gateway url to my api redirect url list already. How should I set ReRoutes values in config.json and Ocelot Api Gateway project StartUp.cs ? Any help will be appreciated. 回答1:

async provider in .net core DI

亡梦爱人 提交于 2020-05-09 20:52:19
问题 I'm just wondering if it's possible to have async/await during DI. Doing the following, the DI fails to resolve my service. services.AddScoped(async provider => { var client = new MyClient(); await client.ConnectAsync(); return client; }); where as the following works perfectly fine. services.AddScoped(provider => { var client = new MyClient(); client.ConnectAsync().Wait(); return client; }); 回答1: Async/await doesn't make sense when resolving dependencies, because: Constructors can't be

Access token validation fails if scope is graph.microsoft.com

早过忘川 提交于 2020-04-30 07:17:47
问题 Received access token from AAD, using below url https://login.microsoftonline.com/gdfdddddd-87dd-497c-b894-xxxxxx/oauth2/v2.0/token grant_type :client_credentials client_id :xxxxx-1ff5-4615-8d71-yyyyyy client_secret:[7aCw]fdsfsfsfds.AC61Fg:cm33 scope : https://vault.azure.net/.default Validated the above received token using below code manually & it works fine IConfigurationManager<OpenIdConnectConfiguration> configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>("https:/