Skip to main content

Get Authorized in Swagger

Last updated on

Follow the steps below to get authorized in Swagger, so that you can test our API endpoints.

  1. In the Admin Portal, open the Platform Configurations menu in the top-right corner of the screen, and click OAuth Clients. Browse the list of clients to find the one you'd like to use to access the endpoints, and click View next to the client to open it. In the Client Details window, copy the Client ID. Make note of the namespace the client is located in as well; you'll need this information later.

  2. Open the Swagger page for the service you want to access. You can find a list of each of our Swagger pages on our API Endpoints page. When you've navigated to the desired Swagger page, click the green Authorize button in the top-right corner of the screen.

  3. The Available Authorizations window that appears contains two options: Authorization (APIKey) and Basic Authorization. Paste the Client ID from earlier into the Username box under Basic Authorization and click the Authorize button.

    Warning

    Make sure to type something into the Password field under Basic authorization and then delete it before pressing Authorize. Otherwise, Swagger will denote the password as undefined rather than an empty string, which will prevent logging in.

  4. Use the https://demo.accelbyte.io/iam/apidocs/#/OAuth/TokenGrant endpoint. Click Try Out Now and then do the following:

    • Select password as your grant_type
    • Input your username and password for the Admin Portal
    • Input the namespace that contains the client whose ID you used to authorize.

    When you're done, click Execute. Upon successful request, your access token will be returned in the server response.

  5. Copy the contents of the access_token field in the server response. This will be a very long string, as seen in the image above.

  6. Return to the Available Authorizations window by clicking the green Authorize icon in the top-right corner of the Swagger page. In the Authorization (APIKey) section, type the word “Bearer” (must be capitalized), followed by one space, then paste your access token. Then, click Authorize.

  7. Finally, click Logout in the Basic Authorization section. Now you can test the API endpoints in Swagger.

Get Authorized Using Curl

If you use curl, you can also get an access token for Swagger using the code below.

curl -X POST "<<base_url>>/iam/oauth/token" -H "accept: application/json" -H "authorization: Basic <<client_credentials>>" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=password&username=<<username>>&<<your password>>&namespace=<<namespace>>"
  1. Type the above code into command prompt:

    • Replace <<base_url>> with your base URL.
    • Replace <<client_credential>> with your OAuth Token in the format of client_id:client_secret, in base64 encoding.
    • Replace <<username>> with your username.
    • Replace <<password>> with your password.
    • Replace <<namespace>> with the namespace that you want to be authorized by, either your publisher or game namespace.

    Then click Enter.

Response

Here is an example response to a successful request:

{
"access_token": "string",
"bans": [],
"display_name": "string",
"expires_in": int,
"is_comply": bool,
"jflgs": int,
"namespace": "string",
"namespace_roles": [
{
"roleId": "string",
"namespace": "string"
},
...
],
"permissions": [],
"platform_id": "string",
"platform_user_id": "string",
"refresh_expires_in": int,
"refresh_token": "string",
"roles": [
"string",
...
],
"scope": "string",
"token_type": "Bearer",
"user_id": "string",
"xuid": "string"
}

You can copy the access_token value from the response and paste it into Swagger preceded by the word BEARER, as in step 6 of the Get Authorized in Swagger tutorial above.