Erlang / OTP: Authorization / Authentication in RESTful Applications

I am developing an Erlang / OTP application that will provide its services (SOA) through the RESTful API.

Services that include the backend will be served by a database, pricing, etc.

Clients can be of different types: web client, mobile clients, Asterisk server client (which should look for user records in the database service), and even clients that I do not plan and do not know about yet. Clients will use the RESTful API in different ways: some of them will consume all services, some of them will use only some of the services (SOA path).

The main problem I am having is authentication / authorization.

RESTful web application

I cannot use Ruby on Rails built-in authentication / authorization because the web client is just one client out of many possible clients that will use the application through the RESTful API.

So my question is:

  • What is the general authentication / authorization concept for a typical RESTful web application that is expected to be used with many different clients?
  • What is the most practical authorization / authentication software development pattern in a RESTful web application?
  • What Erlang / OTP open source software libraries could you recommend for implementing authentication / authorization for such an application?
+4
source share
1 answer

Just check how others do it, for example in this article: Authentication on Facebook .

The whole idea is that there is a separate API call that the client calls to authenticate to the system. The system can accept any client or only from the list of registered clients. As soon as the system checks the client, it issues a special token, which the client uses in all API calls. In the Facebook documentation, this is called an access token. If the client tries to call the API without a valid token, the system reports this as an error and in certain conditions can block the client.

In REST, the token can be sent simply as another parameter in the URL, in POST, or as an additional field directly in JSON. Sending it as a POST or in JSON is probably best since it keeps the URL clean (and will not encounter any caching based on the URLs).

It is the merit of the idea, but there are, as usual, more things to consider. For example, a token should be hard to guess, so the client cannot recreate a valid token without authentication using the system. In addition, the system may need to expire the token if the API is not called within a certain period of time.

To answer the last part of your question, some libraries indicate:

  • erlang: phash2 or crypto library can be used to create unique tokens that are not easy to guess.
  • Webmachine as a great REST framework or toolkit, as they like to call it, to create Erlang REST interfaces
  • API call logic can be implemented in Erlang and served directly from a web server, for example. inets or yaws, or it can be implemented using a web structure such as Nitrogen or Chicago Boss. Check out this list of Erlang web frames .
+4
source

All Articles