Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authenticating requests from mobile (iPhone) app to ASP.Net Web API (Feedback requested on my design)

I'm designing a web site that will have a mobile companion (initally iPhone only). The web site will be an ASP.Net MVC 3 application. I'll also have an ASP.Net Web API site (MVC 4) to expose services to the iPhone application. The iPhone app will have its own form to capture username and password from the user and send that to the web API in JSON headers.

I want to consider security from the start rather than an after thought. I'm not a security expert by any means. I've done a good deal of research to see how other's are handling authentication of a mobile application client from a web service. I think I've come up with a decent solution that doesn't involve hooking into to third party oAuths.

I would greatly appreciate any and all opinions, advice, criticism and general WTFs that any of you can offer. :)

My biggest concerns are:

  1. Ensuring that calls made to the web API are authorized
  2. Minimizing the risk of replay attacks (hence timestamps in the calls below)

The iPhone app will be developed as such:
Two strings are hard-coded into the iPhone app (same values for every user):

  1. Application ID
    This is a string that is used to identify the type of client that is accessing the web API (iPhone, Android, Windows phone, etc).

  2. Application's Hashing Salt
    This is a string that is used to salt hashes for user-agnostic requests.

Two strings are stored in the iPhone app's local database (values unique to each user):

  1. API User Access Token
    This is a string (token) provided to the client by the web API upon successful authentication and allows the client to access the web API without sending the username and password in each request.
  2. User's Hashing Salt
    This is a string that is used to salt hashes for requests made against established user accounts.



The iPhone will make calls to the web API in the following manner:

API Method: Create Account
Client Sends:

  • New Account Data (Username, Password, First Name, Last Name, etc..)
  • Application ID
  • UTC Timestamp
  • Hash of UTC Timestamp + Application ID salted with Application's Hashing Salt

API Returns:

  • New User's Hashing Salt

    The idea here is that, when creating an account, I can use the application's hardcoded salt since it's not a huge security risk if that salt ever got out (through decompilation or some other means).

    But for methods that access and modify the user's data I'll use a salt that is owned only by that user so it can't be used by an attacker to impersonate others.


API Method: Get Account
(Used for getting user's hashing salt for accounts that were created on the web site but haven't yet been synced on the iPhone. This happens when a user tries to log in on the iPhone and iPhone detects that it has no record for that username.)

Client Sends:

  • Username
  • Password (hashed with Application's Hashing Salt)
  • Application ID
  • UTC Timestamp
  • Hash of UTC Timestamp + Application ID salted with Application's Hashing Salt

API Returns:

  • Existing User's Hashing Salt


API Method: Log In (Authenticate)
Client Sends:

  • Username
  • Password (hashed with User's Hashing Salt)
  • Application ID
  • UTC Timestamp
  • Hash of UTC Timestamp + Application ID salted with User's Hashing Salt

API Returns:

  • API User Access Token


API Method: Any Command (i.e. Create Post, Update Profile, Get Messages, etc...)
Client Sends:

  • Command Data
  • API User Access Token
  • Application ID
  • UTC Timestamp
  • Hash of UTC Timestamp + Application ID + API User Access Token salted with User's Hashing Salt
like image 833
Stoop Avatar asked Aug 09 '12 18:08

Stoop


People also ask

How do I authenticate and Authorize in Web API?

Web API assumes that authentication happens in the host. For web-hosting, the host is IIS, which uses HTTP modules for authentication. You can configure your project to use any of the authentication modules built in to IIS or ASP.NET, or write your own HTTP module to perform custom authentication.

What is authentication and authorization in asp net?

Authentication is the process of determining a user's identity. Authorization is the process of determining whether a user has access to a resource. In ASP.NET Core, authentication is handled by the authentication service, IAuthenticationService, which is used by authentication middleware.

What authentication does Web API use?

There are four ways to authenticate when calling a web API: API key authentication. Basic authentication. OAuth 2.0 Client Credentials Grant.

How do I use configure authentication in a sample web app?

To use this article with Configure authentication in a sample web app that calls a web API, replace the sample web app with your own web app. This article focuses on the web application project. For instructions on how to create the web API, see the ToDo list web API sample.

What is ASP NET authentication in web API?

Authentication In Web API. ASP.NET Authentication is used to protect our applications and websites from unauthorized access and also restrict users from accessing information from tools like postman and fiddler.

How does forms authentication work with mobile users?

When a user needs to be authenticated, Forms Authentication will redirect them to your desktop login page, regardless of whether they're a desktop or mobile user (because it only has a concept of one login URL).

What is an API and how does it help your mobile app?

RESTful APIs can help make your mobile app more reliable, portable, simplified, and visible. Mobile APIs can enhance the core features of an app, like GPS data and databases. This will improve the experience on each mobile device of end users.


1 Answers

I did it using asp.net mvc 4.0/web api basic membership. you may find it helpful.

Yeah, Use SSL for sure

https://github.com/aamir-poswal/Mobile-Apps-Authentication-Authorization-ASP.NET-WEB-MVC-4.0

like image 114
aamir sajjad Avatar answered Oct 05 '22 16:10

aamir sajjad