Skip to main content

Authentication

Gojek uses standard OAuth2.0 authentication for integration with all of our partners. To complete the authentication process, the client must authorize itself to Gojek OAuth2 server.

Oauth2 credentials contain two parameters

  • client_id

  • client_secret

This identification of the client is done through client credentials issued by Gojek.

Pre-Requisite

Oauth2 credentials can be obtained via GoBiz Developer Portal. For detailed step by step please consult this section

How to get token?

We have 2 methods of getting token

Integration TypeMethod to Get TokenWhen to Use?
Direct Integration ModelClient Credential
grant_type=client_credentials
You’re a GoBiz merchant, and you want to access Gojek features directly from your own system.
Facilitator ModelAuthorization Code
grant_type=authorization_code
You’re a facilitator, either you a POS provider or an online order aggregator, and you want to link your Gojek merchants or access auth-code specific APIs.
Facilitator ModelClient Credential
grant_type=client_credentials
You’re a facilitator and you have linked your merchants, and you want to enable Gojek features to your merchants.

Client Credential

Client Credential Flow

You need to send a request to get access token. Token can be reused until it expired. Token lifespan is 3600 seconds by default. The required authentication parameters must be included in the request header at the time of the request.

Endpoint = {OAuth base URL}/oauth2/token

Request Body Parameters

ParametersTypeRequiredDescription
client_idstringYesUnique identifier issued to the client by Gojek.
client_secretstringYesSecret issued to client by Gojek.
grant_typestringYesMethod to gain the access token. It must be client_credentials.
scopestringYesScope of access to be associated with the resulting access token.

Sample Request

Sample Request
curl -X "POST" "https://accounts.go-jek.com/oauth2/token" \
--header 'Content-Type: application/x-www-form-urlencoded' \
--user 'myclientid:myclientsecret' \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "scope=gofood:catalog:read gofood:catalog:write gofood:order:read"

Sample Response

Sample Response (200)
{
"access_token": "{access_token_to_access_biz_env}",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "gofood:catalog:read gofood:catalog:write gofood:order:read"
}

Response Body Parameters

ParametersDescription
access_tokenThe token to access GoBiz endpoints.
scopeSpace-separated authorized scopes.
expires_inThe approximate access_token's remaining lifetime in seconds since it was issued.
token_typeThe type of the token. Always bearer.

See detailed flow and error response on API Reference

Authorization Code

Authorization Code Flow

Gojek is using terminology defined in RFC 6749: Section 1.1 - Roles and OpenID Connect Core 1.0 incorporating errata set 1.

TermsDescription
Resource OwnerGoBiz
Resource ServerGoBiz APIs
ClientAny web-app trying to access end-user’s information from GoBiz
Authorization ServerGojek
IntegratorOrganization integrating the client with GoBiz
User AgentInterface used to redirect the user to Gojek and back. (i.e., browser)
Authorization Endpoint{OAUTH_URL}/oauth2/auth
Token Endpoint{OAUTH_URL}/oauth2/token
Access TokenToken required to access GoBiz APIs
ID TokenA JSON Web Token containing information about the user

Gojek requires integrator to provide redirection URIs (Refer RFC 6749: Section 3.1.2) which will be used for redirecting the user after authorization steps.

note

Refer OAuth 2.0: Section 2.3.1 - Client Password for more information on client credentials.

OAuth 2.0 and OpenID Connect are complex specifications with a lot of security considerations and implications. We recommend you use a pre-written, battle-tested client library suitable for the language/framework you are using for developing the client application. You can find a listing of such libraries at Code — OAuth (Not maintained by Gojek).

note

We strongly encourage you to refer OAuth 2.0 Threat Model and Security Considerations to ensure secure integration.

Create anti forgery state token

A state parameter is required for preventing request forgery attacks (Refer RFC 6749: Section 10.12). The state parameter is a unique session token that holds state between the client and the user agent (i.e., Browser). When the user is finally redirected back to the client after successful authentication & consent, client should cross verify this token to ensure the request is coming from legitimate user-agent and not a malicious attacker.

  • state must be at-least 8 characters long
  • state must be URL-safe encoded

Process authorization callback

Once the user successfully authenticates with Gojek and authorizes the client to access information, Gojek will generate an authorization code and redirect the user to redirect_uri with the code and the state that was originally sent by the client. On receiving this callback, client should verify the state parameter and ensure the value is same as the one sent by the client in previous step.

Exchange code for Access & ID tokens

The code returned in the previous step is one-time use only and is short-lived (Not more than 2 minutes after receiving the redirection). Client should exchange this code with Gojek to receive an access token and id token containing information about the user. A POST request should be sent to /oauth2/token endpoint with following parameters in the request body:

Endpoint = POST {OAuth base URL}/oauth2/token

Request Header

  • Content-Type: application/x-www-form-urlencoded

Request Body Parameters

ParametersTypeRequiredDescription
client_idstringYesClient identifier issued by GoJek and must be same as the one sent during /oauth2/auth.
client_secretstringYesClient Secret issued by GoJek for the client_id.
grant_typestringYesMethod to gain the access token. It must be authorization_code.
codestringYesValue received as part of redirection to redirect_uri.
redirect_uristringYesRedirection URI used during the /oauth2/auth call.

Sample Request

Sample Request
curl -X "POST" "https://accounts.go-jek.com/oauth2/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=partner-client-id" \
--data-urlencode "client_secret=partner-client-secret" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=value-from-oauth-callback-queryparams" \
--data-urlencode "redirect_uri=partner-redirect-uri"

Sample Response (200)

Sample Response
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
"access_token": "{access_token_to_access_biz_env}",
"expires_in": 3600,
"id_token": "{id_token}",
"scope": "offline email openid gofood:catalog:read gofood:catalog:write",
"token_type": "bearer"
}

Response Body Parameters

ParametersDescription
access_tokenThe token to access Biz endpoints
scopeSpace-separated authorized scopes
expires_inThe approximate access_token's remaining lifetime in seconds since it was issued
token_typeThe type of the token. Always bearer
id_tokenID token
refresh_tokenThe refresh token, used to refresh the access token when expired.

Refreshing Access Token

When the access token expired, partner can request for new access token, given the refresh token available.

Endpoint = POST {OAuth base URL}/oauth2/token

Request Header

  • Content-Type: application/x-www-form-urlencoded

Request Body Parameters

ParametersTypeRequiredDescription
client_idstringYesClient identifier issued by GoJek and must be same as the one sent during /oauth2/auth.
client_secretstringYesClient Secret issued by GoJek for the client_id.
grant_typestringYesMethod to gain the access token. It must be refresh_token.
refresh_tokenstringYesToken to refresh the expired access token.

Sample Request

Sample Request
curl -X "POST" "https://accounts.go-jek.com/oauth2/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=partner-client-id" \
--data-urlencode "client_secret=partner-client-secret" \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "refresh_token=refresh-token"

Sample Response

Sample Response (200)
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8


{
"access_token": "{access_token_to_access_biz_env}",
"expires_in": 3600,
"id_token": "{id_token}",
"scope": "offline email openid gofood:catalog:read gofood:catalog:write",
"token_type": "bearer"
}

Response Body Parameters

ParametersDescription
access_tokenThe token to access Biz endpoints
scopeSpace-separated authorized scopes
expires_inThe approximate access_token's remaining lifetime in seconds since it was issued
token_typeThe type of the token. Always bearer
id_tokenID token
refresh_tokenThe refresh token, used to refresh the access token when expired.