Tech Forum Network

Programming, technical solutions and hot scripts
Home » TechQns » Authenticating requests from mobile (iPhone) app to ASP.Net Web API (Feedback requested on my design)

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

August 9, 2012 Posted by forumadmin under TechQns
Comments off

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

 

Asked By – Joe        Read Answers    

More Related Questions

  • Token while authentification in a web java application using web services i have a web service "authentification" which gives users acces to their accounts, after getting the login and the password. but i need to generate a token to use it instead of login & […]
  • How to use Google style token authentication in Web APIs I have an internal use web site that will be exposed over the Internet for ease of use on mobile devices. The web site is MVC 5 and will communicate with a Web API on a different server. […]
  • Salesforce rest api INVALID_SESSION_ID I'm trying to connect my asp.net REST api to salesforce. I'm succesfully going through authentification, but when I start to send POST requests, I'm getting an error […]
  • Can SSL and a key code alone be enough to keep a Web API secure? I have an ASP.Net Web API (v2) that will require SSL for all calls made to it, no exceptions. There is no login for the system, instead I plan on providing a user with a secret key key […]
  • Web site sign in, in an MVC + Web API project? When I create a new Web Application with both MVC and Web API, with individual user accounts, Visual Studio will give me a template which contains a lot of code used in authentication. I […]
  • How to transparently renew the Facebook access token while processing a service method which uses Facebook API calls? I have a WCF service which runs in IIS 7.5 and VS 2010. This service has some methods which internally use the Facebook C# SDK (version 4.1, not latest) in order to perform some GET and […]
  • ASP.NET Web API Authentication I'm really depressed by googling a lot on Web API authentication. I need to know how to authenticate a user from a client application while using ASP.NET Web API. I have seen all the […]
  • Web API 2 – Cross Site Authentication I am developing a standalone Web API 2/AngularJS module for a previously built ASP.NET 4.0 web forms application. The old web application already has a user object with its own […]
  • ASP.Net WebApi Authentication and Security I have been looking at the Thinktecture.IdentityModel.40 library as a way of handling the security of my Asp.Net WebApi. One point I don't understand is the following, and this is my […]
  • Using auth_token from request headers instead from POST/PUT parameters with Rails 3 / devise I need to use token based authentication in a Rails 3.1 API in conjunction with the most recent version of devise. No problem so far. Now I do not want to append my :auth_token to the […]
0
  
Email
Tags: asp.net-web-api, authentication, iphone, security, token

Comments are closed.

« How can I convert FBProfilePictureView to an UIImage?
Why does my Thinkpad brightness control skip steps? »
Tech Forum Network powered by WordPress and The Clear Line Theme