asp.net-web-api2

How to extend IdentityServer4 workflow to run custom code

百般思念 提交于 2019-12-07 13:55:38
问题 I have a basic Identityserver4 implementation based on the quick start sample. In my startup I have the following: public void ConfigureServices(IServiceCollection services) { // configure identity server with in-memory stores, keys, clients and scopes services.AddIdentityServer() .AddTemporarySigningCredential() .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients()); } public void Configure(IApplicationBuilder app) { ... app.UseIdentityServer(); } I want

Set cookie from Web Api 2 IAuthenticationFilter AuthenticateAsync method

孤者浪人 提交于 2019-12-07 13:49:35
问题 Using Web Api 2.2, I have a custom IAuthenticationFilter that I use for authenticating client requests with a custom scheme. Basically, when a client is not authenticated and wants to access a protected resource, he sends an Authorization header: Authorization: MyCustomScheme XXXXXXX alongside the request. The filter then validates the credentials, authenticates the user and generates a stateless authentication token for further access (similar to a JWT). I would like to store the resulting

Angular 2 - Post File to Web API

懵懂的女人 提交于 2019-12-07 13:02:44
问题 I am attempting to pass a file to Web API from an Angular 2 app, and the actual file data does not get sent. Here is my angular 2 service code: var headers = new Headers(); headers.append('Content-Type', 'multipart/form-data'); var formData = new FormData(); formData.append("file", file); return this.http.post('http://myapiurl.com/files/upload', formData, { headers: headers }).map(res => res.json()); In the angular 2 docs, the POST method signature is as follows: post(url: string, body:

Api Controller has a parameterless public constructor error

拥有回忆 提交于 2019-12-07 11:33:32
问题 I am using Unity to do my DI and I have encountered the following error:- "An error occurred when trying to create a controller of type 'UploadController'. Make sure that the controller has a parameterless public constructor." I have the following UnityResolver:- public class UnityResolver : IDependencyResolver, IDependencyScope, System.Web.Http.Dependencies.IDependencyResolver { protected IUnityContainer container; public UnityResolver(IUnityContainer container) { if (container == null) {

Calling service/repository methods in ASP.Net Core middleware

独自空忆成欢 提交于 2019-12-07 11:22:25
问题 ASP.Net Core noob here...I am using an ASP.Net Core WebAPI core project using DNX451 with EF 6. I have a requirement to implement API Key auth in our service. To do this I have created middleware that gets information from the request and proceeds with authentication. It is SUPPOSED to go to the database, get the key to match, and then return and do the validation. Here is the middleware implemented to look at the context and get the APIKey AuthenticationHandler public class

Complex JSON Web Token Array in webapi with OWIN

≯℡__Kan透↙ 提交于 2019-12-07 08:24:02
问题 I'm in process of trying to learn JWT and ouath. I have came across form of JWT which would help me in development of my authorization server. The format I came across is following : { iat: 1416929061, jti: "802057ff9b5b4eb7fbb8856b6eb2cc5b", scopes: { users: { actions: ['read', 'create'] }, users_app_metadata: { actions: ['read', 'create'] } } } However since in adding claims we can only add simple string how something like this can be achieved ? The only way I have seen till now was to use

Roles vs Claims Authorization Asp.net web api-2 with WIF and OWIN Middleware

此生再无相见时 提交于 2019-12-07 06:30:17
问题 I am trying to secure asp.net web-api 2.0 with Windows Identity Foundation 2. The choice I have to make is between role based authorization and claims based authorization. As a practice, I added a users in DbInitializer and assigned him two roles (Admin and Manager). When I log in with that user, I see that ClaimsPrincipal in debug mode, it already has those roles (Admin and Manager) associated as claims. So here are the questions: If roles are also treated as claims, what is the difference b

Web API 2 project and MVC 5 Website project in same domain

纵饮孤独 提交于 2019-12-07 05:35:52
问题 Technologies used: BreezeJS OData Web API 2 MVC 5 IDE: Visual Studio 2013 I've been wrestling with the idea of having a Web API project and a separate web site project in a single solution. My Web API 2 project opens up as: localhost:2020/ExampleProject.API My MVC 5 WebSite project opens up as: localhost:5050/ExampleProject.WebSite Now by default web api doesn't allow cross origin policies. So I played around with enabling CORS in my Web API 2, although I was able to get it to work, it only

Get custom validation error message from Web Api request to HttpClient

久未见 提交于 2019-12-07 05:31:35
I have the following model for my ASP.NET Web Api 2 service: public class Message { public int Id { get; set; } [Required] [StringLength(10, ErrorMessage = "Message is too long; 10 characters max.")] public string Text { get; set; } } I am making the request from my WinForms app: using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var messageOverTenCharacters = new Message { Text = "OverTenCharacters" } var response =

Azure Mobile Services Custom API Getting Bad Request on Client

我们两清 提交于 2019-12-07 05:02:28
问题 So I'm using azure mobile services backend to try and make a custom API. However I can't seem to connect to even the template table from the client. When you make a new Azure Mobile Service using the template they provide you with this values API controller that resembles this format [MobileAppController] public class ValuesController : ApiController { // GET api/values [Route("api/values")] public string Get() { return "test"; } } From the client I'm trying to invoke this endpoint like this