Authenticate from IOS Swift app? RRS feed

  • Question

  • User2058588433 posted

    Hello all:

    I have an MVC web site hosted on Azure, using “standard” authentication, in the DB there are tables AspNetUsers, AspNetRoles, etc.. I need to access and be able to authenticate from an IOS app written in Swift. 

    Can anyone offer any advice on how to do this?

    Thanks for any and all input.


    Thursday, January 31, 2019 11:07 AM

All replies

  • User-474980206 posted
    Standard security uses an authorization cookie that contains a cookie. Your iOS app can post to the login page and get the cookie, that it uses on requests. Your IOS code should pass a header, so that the login pages knows it’s mobile app. You want to return a JSON message on failure, you also should have the not authenticated page send a JSON response when the header exists so the app can detect cookie timeout, and perform re-login.

    There is some difficulty in sharing the cookie between NSURLSession and WebView, unless it’s a current version of the iOS sdk. Google for work arounds.

    Another common approach is to allow jwt tokens for calling your web API. In this case you create a new login method in web API that return the token. The token is passed as a header on requests. You just add a jwt support to the authentication provider. Google for examples of mvc and jwt tokens. You can use both cookie and jwt if you want, so web page Ajax uses cookies and mobile apps use jwt tokens.

    It’s easy to make json calls in swift. Google for lots of examples.
    Thursday, January 31, 2019 3:30 PM