Layar Developer Documentation

Back to

User Authentication

Feature Introduction

If your AR content is only available for certain group of people and you want to add some restrictions as what kind of content people can see, you can implement authentication mechanism in your layer.

The Layar Reality Browser (including Layar Player) behaves like a normal web browser, honoring sending/storing of cookies in the central cookie store of the device. Developers can make use of cookies to identify valid users.

Key Steps to Implement

Configure the "additional settings" tab on the publishing site

The following settings can be used to manage the user authentication flow. They are available under the "additional settings" tab of the layer editing page on the publishing site.

Key Value Example Explanation
valid cookie required (optional) boolean false (by default) Indicates whether authentication is required prior to launching the layer. If it is checked (true), the layar client will firstly check whether there is a cookie, if not, it will redirect the user to the login page defined in "URL for layer settings page". By default it is unchecked(false), it means the layer can be launched without authentication.
URL for layer settings page(required when 'Enable additional settings' is checked) URL The URL to call for the webview to authenticate the user. Usually https. NOTE that this URL needs to be on the same domain as the poiURL (it's just a cookie we're using, so all normal browser cookie rules apply), different sub domains are allowed.
Description for button (required when 'Enable additional settings' is checked) string User Authentication A description is shown on top of the button which explains what this button is about.
Button label(required when 'Enable additional settings' is checked) string login The text that is displayed on the button itself.
Replace filters(optional) boolean false (by default) Indicates whether the web page launched by 'URL for layer settings page' will replace the entire filter settings defined under "Filters" tab. If it is checked (true), the 'URL for layer settings page' will appear under the filter settings button in the AR view. By default, it is unchecked (false).
Parameters added in request string A group of preset parameters that can be added to the request when the button is clicked. The possible multiple values are "latitude", "longitude", "country code", "accuracy", "language", "API version".

Special Error Code in getPOIs Response

Key Value Example Explanation
errorCode Integer
"errorCode": 30
The errorCode for the response. - 30: Indicating that this layer requires authentication. When this error code is returned in getPOI response, the client should open the webview at the 'URL for layer settings page' defined by the layer.
errorString String
"errorString": "auth required"
The corresponding errorString will not be displayed to the user.

Cookie Management in Layar 

The Layar Reality Browser (including Layar Player) behaves like a normal web browser, honoring sending/storing of cookies in the central cookie store of the device:

Please NOTE that if a cookie is set from outside of Layar reality browser (or the app which implements the layar Player), it will NOT be sent to the Layar client (or layar Player) in the getPOI request. For instance, a user is authenticated in an android app which implements a layar intent to launch a particular layer in Layar Reality browser, the cookie set will not be sent to the layar client.

On the Layar server side, for each layer, "poiDomainURL" parameter is used for knowing what domain the getPOI request/response belongs to for sending/receiving cookies.

The layar client complies to the following requirements:

  1. When there is a cookie in the general cookie store for the poiDomainURL, that cookie gets sent in EVERY getPOI request for that layer.
  2. For every HTTP request other than requests to Layar server (i.e. directly to external parties), the client checks if there are cookies stored for the corresponding domain and if so, send the cookie, if valid. Explicitly this includes: requests in any WebView inside the app (the layer additional settings page, any webview coming from a layer action or POI action) and async or text/plain HTTP requests coming from layer or POI actions.
  3. If a cookie is received in the getPOI response, it is stored as belonging to the poiDomainURL. That way it will get sent in subsequent getPOI requests for that layer and any other direct HTTP request to that domain.
  4. If a cookie is received in any response to a direct HTTP request to a 3rd party domain, it is stored in the general cookie store.
  5. If authRequired is true in the layer details, then the client redirects the user to authURL web page if no valid cookie is available for the poiDomainURL.
  6. The cookies will be sent/stored by the layar clients regardless whether the layer has 'additional settings' enabled(regardless whether authURL set or not).

General Interactive Flow

As mentioned above, Layers may have a new field 'URL for layer settings page' in the definition to indicate support for authentication. This is the login URL where the Layar client should direct the webview for authentication. This has to be in the same domain as the layer provider's getPOI url(defined under API endpoint URL). The layer provider should set a cookie that applies to layer provider's getPOI url.

Please NOTE the following situation:

If 'show filter before loading layer' defined under the Filters tab is true (checked) and the 'URL for layer settings page' is used for user authentication:

  1. The Login url ('URL for layer settings page') is opened in an embedded browser. This page(s) authenticates the user (any mechanism can be used, like self hosted authentication/OAuth etc.) and can take him to a 'home page' that can have more (dynamic) settings to choose for the layer. Any no. of html pages can be used with flows between them.
  2. The user is returned to the Layar view he was in when the embedded browser is redirected to a layar intent (layar://thelayer/?action=refresh). Visiting this layar intent means that the authentication (and possibly configuration) of layer is complete and user can return to Layar app. The provider needs to set cookies that apply to the provider's getPOI url before visiting this layar intent.
  3. When the layar intent is called, all cookies that apply to getPOI url (only) are stored in the layer( cookie expiry is to be handled by Layar app, according to cookie spec). The cookie might replace previous cookies that were set, e.g. the user was asked to log in again because a cookie that was sent was not valid. This is the example above for errorCode 30. User-Agent and Cookies are sent in the HTTP headers as for all other Layar requests. 
  4. The stored cookies are sent to the layarservice app for all future getPOI requests. The layarservice getPOI handler forwards all cookies it receives to the layer provider's getPOI url so that the request can be identified with a particular user session.  NOTE that redirects are not allowed on the getPOI request as subsequent requests will not pass the cookie for security reasons. The GetPOI URL needs to be on the same domain as the  'URL for layer settings page'.

The following diagram shows the user authentication flow when "valid cookie required" is true and no cookie is set when the layer is launched.  The "Authentication" refers to the "URL for layer settings page" and should be managed by third party developers, for instance it can be implemented as a part of the POI server. Please NOTE that the Layar server is managing the communication between the Layar Client and third party POI server in real life. It is not mentioned in the diagram below for simplicity.

Under the following two situations, layar client directly sends the getPOI request to the POI URL (POI server) without visiting the authentication page firstly. The POI server needs to check whether there is a valid cookie or not and provide the appropriate response accordingly.

Please NOTE that the client app has full support for https (layer provider can choose to use this for additional security). If the getPOI url of layer provider is https, the client app to layar service getPOIs call will also be over https. The Layar server will forward the call also over https.

Create custom filter settings page

Besides user authentication, developers can use 'URL for layer settings page' under "Additional settings" tab for other purposes, such as a custom filter settings page. The mechanism mentioned above applies to this use case. Basically, developers need to store all the filter settings in cookies so that they will be passed in subsequent getPOIs requests. In the script which returns POI response can use these filters to determine which POIs should be returned.

On the "Additional settings" page, normally "Replace filters" is checked to replace filters provided by Layar. If "Valid cookie required" is true, the custom filter page is shown first when no valid cookie is available. This can be used when you want users to configure the filter settings first.

The following diagram shows the flow of using custom filters when "valid cookie required" is false and "Replace filters" is true.  The "Custom Filters" refers to the "URL for layer settings page".