Authentication Object

Introduction

This section describes how you can use Ocugine to authorize users in your applications and games. Some of our APIs by default require user authorization (for example, a user entry in the leaderboard).

The authorization method in the Ocugine Control Panel and your final application is different. When working with the application, you should get a token to access user data. To do this, follow the instructions below.

Authorization in the Ocugine services is as follows:

  • You send a request for a link to authorize the user and redirect him there.
  • The user is authorized in his account Ocugine in a convenient way for him in the browser.
  • After the user returns to your application, you create a request to check the user's permissions.

Available Methods

Use following methods for authentication.

Object / Method URL Description
OAuth.get_link https://cp.ocugine.pro/api/oauth/get_link/ Use this method to get authentication link for your game users.
OAuth.login https://cp.ocugine.pro/oauth/login/ This is internal method. You need to redirect the user to the URL that was obtained using the get_link method.
OAuth.get_token https://cp.ocugine.pro/api/oauth/get_token/ Use this method after user close window with authentication link.
OAuth.logout https://cp.ocugine.pro/api/oauth/logout/ Use this method to remove user token from your application.

User Authentication

Before you start working with a user zone, you must authorize your clients. Authorization is done by redirecting your client to our gateway, or open it in the browser’s built-in application (you can also use the SDK so that you do not need to deploy your browsers or redirect users to the system).

Get Authentication Link

In order to get a link to authorize a user, you must send a POST request to:

https://cp.ocugine.pro/api/oauth/get_link/

The request parameters should include:

Name Type Desc
app_id double Your Application ID. You can see your Application ID here.
app_key string Your Application Client Key. You can see your Client Key here.
grants (Not necessary) array / string Array of parameters for access request, or "all" for requesting all rights.
lang (Not necessary) string The language in which the server response comes. The default is determined automatically.

Request Data Example

{
    "app_id": 1,
    "app_key": "example_key",
    "grants": ["profile", "achivements", "cloud_data"],
}

Response Example

{
    "complete": true,
    "auth_url": "https://cp.ocugine.pro/oauth/login/?key=AUTH_KEY",
    "auth_key": "AUTH_KEY"
}

Continuing authorization

After the user has logged in and has given all permissions for your application, you must receive an access token in order to send requests to personalized API methods. To do this, after the user has returned to your application from the login window, you need to get an access token using a POST request.

To obtain a token, send a POST request to the following URL:

https://cp.ocugine.pro/api/oauth/get_token/

The request parameters should include:

Name Type Desc
app_id double Your Application ID. You can see your Application ID here.
app_key string Your Application Client Key. You can see your Client Key here.
auth_key string Auth Key. Then you get your token - auth key will be removed
lang (Not necessary) string The language in which the server response comes. The default is determined automatically.

After that, you will receive the following response from the server:

{
    "complete": true,
    "access_token": "example_token",
    "grants": "all"
}

When you received an access token, you can use them, to get access for objects with requested grants. For example, if you are requested grant "profile" for your application, your users can find other players in your game.


Available Grants

When performing an authorization request, you need to send a parameter with access rights. You can get various flags in the list below.

Available Permissions:

Permission Usage Defaults
profile Access to profile information Requested
reports Access to user reports Requested
payments Access to user billing information Requested
promos Access to personal promotions user Requested
support_tickets Access to user tickets in support Not Requested
reviews Access to user reviews within the application Not Requested
apps Access to the list of user-installed applications Not Requested
leaderboards Access to user points on the leaderboard Not Requested
messages Access to user messages Not Requested
achivements Access to user achievements Not Requested
teams Access to user commands Not Requested
multiplayer Access to user information in multiplayer Not Requested
social Access to social user functions Not Requested
cloud_data Access to user cloud data Not Requested

If you want to request access to all data at once, use the "all" flag in the "string" format, instead of the "string" array of flags.


Registration with Ocugine

If the user has not previously been registered with the Ocugine services, he will be asked to create his account. End users of your product will be able to use their Ocugine account for other games using our services.


Logout

If you need to reset user authorization in the application, you can send a request to delete the token in the database. Use following method:

https://cp.ocugine.pro/api/oauth/logout/

You need to send access_token as POST-parameter to remove user authorization in your application.