ASP.NET Membership Provider and Web Services - c#

I'm working on a web-app using ASP.NET Membership Provieder to implement authentication and roles for each user.
Now I need to create a web service to provide some asynchronous functionalities and I need to call web-methods from several pages in my application. But I've noticed that Web Service is accessible also from non-authenticated users setting the url in the address bar of the browser.
Is there a way to apply Membership Provieder rules also to web-methods, or do I have to implement authentication system for every method?

You should probably not be exposing the web service to the public. It should reside inside your internal network. If you need to expose it to the public then you need to secure it the same way you do with your web application. You could also use Forms Authentication in your web service methods. Depending on the technology you used to implement your service with there might be various ways to achieve that. Basically all your web method calls would require a valid forms authentication cookie to be sent along with each request in order to authenticate the user.

Related

web api - Hold piece of data on subsequent request

I am using web api with angualrjs and asp.net identity for authentication .
When using asp.net mvc, We will use session to hold some data for the subsequent request. Say for example, user account id.
In web api, how so I implement this? I don't want to implement session in web api. I need and alternate solution for this one.
Need to consider security aspect too.
You should use claims-based authorization. For example, you can integrate OAuth2 using OWIN-based packages in your solution.

Is it possible to pass logged in user credentials to WCF services?

I currently have a service layer which is exposed via WCF. The service layer includes private endpoints that are to be accessed internally using the TCP protocol but also includes public endpoints (API) for some services to be accessed publicly via HTTP. So far so good... My problem is I don't know how to implement authentication and authorization correctly.
Question 1: If I have an asp.net application that uses asp.net Identity for authentication (Forms Based Authentication) and authorization. Is it possible to pass in those credentials to the WCF service automatically i.e. so that I can perform role based authorization on each service within my service layer? If this is indeed possible can someone provide me with some sample code or point me in the right direction for further reading? If it is not possible? Is there an alternative solution?
Question 2: Do I need two separate databases? i.e. one database for the web application that contains all the users, roles etc and then another database for my service layer that contains all the business data of the application?

Authentication and Authorization through a Web API Service Layer accessed by an ASP.NET web application and an iOS mobile app

I am about to start working on a new ASP.NET MVC web application that I intend to build an iOS mobile version of as well.
I am planning on using MVC 4 Web API as a service layer that will sit in front of the business layer and be accessed by both the web application and the mobile application.
I am a little confused however about how I will implement authentication and authorization in this architecture.
Normally in an MVC application, once a user submits proper credentials, I would make a call to
FormsAuthentication.SetAuthCookie(username, false);
Which will create a cookie that will then be passed back and forth from one request to another to maintain a user's session in the application.
I'm confused as to how this will function through a service layer when accessed from the web application. Or how it will function when the service is called from the mobile application.
You could design your Web API in such a manner that it would require the forms authentication cookie should be sent on each request. You would then use this cookie to extract the username of the currently authenticated user from it.
But when designing an API it is usually better to use some other means of authentication than cookies. For example you could use the Authorization HTTP header where the client will be required to send the encrypted value of a forms authentication ticket.
You might also take a look at the following article about token based security.

ssl channel wcf web api?

I'm currently developing a web api, with WCF web api, which allows me to write restful apis. One concern I have is security. For this reason I decided to protect my api with the OAuth protocol which works very good. However, the team got to the conclusion that our own applications shouldn't be authorized by oauth, instead they sould be authorized by http basic, meaning that the client application should send username and password.
So I have 2 questions:
How can I set up WCF Web Api to work with SSL, I'm using Web Api preview 6, and the project is a MVC3 application?
I have an operation handler which takes care of the creation of IPrincipal from the client access token, and then injects it into the operation parameters, so I can access the user's info. I would like to have in the same operation handler a condition where I could check if the authorization scheme is OAuth or http basic, and then in the case of http basic extract the user's credentials and authenticate that specific user against my data base, if authentication is successful create an IPrincipal and inject it to the operation parameters. However, as I see it, everytime an application using http basic requests something to the api, I would have to go to the data base and authenticate. So my question is: Am I in the right path, or this could be accomplished in some other way?
Any answers would be appreciate it. Thank you in advanced!
You setup SSL for WCF Web API just like you would any other WCF service exposed over HTTPS. If you are hosted in IIS, then you need to configure a site binding for HTTPS. If you are self hosted, then the configuration is bit more involved. See http://msdn.microsoft.com/en-us/library/ms733768.aspx for all of the details.
To handle basic auth against a custom identity provider you would typically use a custom authz module when hosted in IIS. See [http://custombasicauth.codeplex.com/] for an example of how to do this. If you are self hosted then you can use a custom username passworld validator. See http://msdn.microsoft.com/en-us/library/aa702565.aspx for details.
Yes, I believe you are correct that every request will require authentication unless you establish some sort of session-like semantics.
Hope this helps.

Securing Web Services approach valid?

Currently I am looking at securing our web services. At the moment we are not using WCF so this is not an option. One approach I have seen and implemented locally fairly easily was the approach described in article:
http://www.codeproject.com/KB/aspnet/wsFormsAuthentication.aspx
Which describes adding a HttpModule which prompts for user credentials if the user browses to any pages (web services) which are contained in a services folder. Does anyone see any way that this security could fall down and could be bypassed etc. I'm really just trying to decide whether this is a valid approach to take or not?
thanks
Seems a bit clumsy to have a person browse to a page in order to use a web service, which is typically done programmatically.
You can simply hide your web services behind formsauthentication, and have an authentication endpoint that sets the forms ticket.
The service client would then just hang on to the CookieContainer and use it for subsequent requests.
Whatever you do, you must ensure that any pipe that has credentials going through it is secured via SSL.

Categories

Resources