Advertisement

Authentication (OAuth 2.0)

Table of contents

Introduction

RouteYou uses OAuth 2.0 for authentication to our APIs. With OAuth an external application can request access (authorization) to a user's data while keeping the user's authentication details safe. You can find more information on how OAuth works here.

Before you can start developing, it is necessary to register your application. To register your application, you need to pass the following information to your RouteYou contact person. If you don't have a contact person yet, please contact sales[at-r.].

When your application is registered, a client ID and client secret will be assigned. The secret is used for authentication and should never be shared. The secret should never be used when the client can't keep it safe (browser based/native app).

Which OAuth 2.0 grant to implement

For more information see https://oauth2.thephpleague.com/authorization-server/which-grant/

Requesting an access token for server side calls without user permission (Client Credentials Grant)

Perform a POST request to https://api.routeyou.com/2.0/rest/oauth/token

Request parameters:

Response: JSON containing the following values

Example:

curl -X POST https://api.routeyou.com/2.0/rest/oauth/token \
  -d grant_type=client_credentials \
  -d client_id=<client ID> \
  -d client_secret=<client secret>

Requesting an access token for user access (Authorization Code Grant)

Step 1

Redirect the user to https://www.routeyou.com/oauth/authorize (login flow) or https://www.routeyou.com/oauth/authorize/register (registration flow)

URL parameters:

Example URL:

https://www.routeyou.com/oauth/authorize?response_type=code&client_id=<client ID>&redirect_uri=<redirect URI>&scope=account:basic+content:read&state=abc123

Response:

RouteYou will redirect the user agent to the redirect_uri that is provided, with added URL parameters. When access is denied, error=access_denied will be included in the query string. When access is accepted, the code and state will be returned in the query string. You must match the returned state parameter to the state parameter you provided for security. The code parameter contains the authorization code needed to complete the authentication process in step 2.

PKCE (Proof Key for Code Exchange)

The code_challenge and code_challenge_method are required when it is not possible to keep your client secret safe.

Step 2

Perform a POST request to https://api.routeyou.com/2.0/rest/oauth/token to exchange the authorization code from step 1 for an access token and a refresh token.

Request parameters:

Response: JSON containing the following values

Example:

curl -X POST https://api.routeyou.com/2.0/rest/oauth/token \
  -d grant_type=authorization_code \
  -d client_id=<client ID> \
  -d client_secret=<client secret> \
  -d code=<authorization code> \
  -d redirect_uri=<redirect URI>

Refreshing an expired access token (Refresh Token Grant)

Perform a POST request to https://api.routeyou.com/2.0/rest/oauth/token to refresh an expired access token.

Request parameters:

Response: JSON containing the following values

Example:

curl -X POST https://api.routeyou.com/2.0/rest/oauth/token \
  -d grant_type=refresh_token \
  -d client_id=<client ID> \
  -d client_secret=<client secret> \
  -d refresh_token=<refresh token>

Accessing the APIs using an access token

See JSON-RPC, but omit the token in the URL and add an Authorization header instead.

For information on how to construct a JSON-RPC request, see the Wikipedia article about JSON-RPC.

Send requests to the following URL:

https://api.routeyou.com/%service-version%/json/%service-name%

The parts between % should be replaced with the following:

Include the access token by adding the Authorization: Bearer <access token> header.

Example:

curl -X POST https://api.routeyou.com/2.0/json/Route \
  -H "Authorization: Bearer <access token>" \
  -d '{"jsonrpc":"2.0","id":1,"method":"get","params":[44]}'

Back to RouteYou

© 2006-2024 RouteYou - www.routeyou.com