Logo

Authentication

The N3C API uses token-based authentication to ensure that only verified users and applications can access protected resources. Every request to a secured endpoint must include a valid access token issued by the authentication service.

Authentication is handled through a simple login process where users submit their credentials. If the credentials are valid, the system returns a JSON Web Token (JWT) that represents the authenticated session. This token must be included in the Authorization header of subsequent API calls.

Only endpoints designated as public can be accessed without a token. All other endpoints will return an authentication error if a valid token is not provided.


How Authentication Works

  1. The client sends a login request with a email and password.
  2. The server validates the credentials.
  3. If successful, the server returns an access token and user details.
  4. The client includes the token in the Authorization header for all protected requests.
  5. When the token expires, the client must request a new one.

Login

API Endpoint

POST /login

Headers

TypeValueRequire
Acceptapplication/jsonYes

Query Params

NameValue
emailuser@gmail.com
passwordyourpassword

Sample Request

curl --location \
      --request POST 'https://n3c-api.cidb.gov.my/login' \
      --header 'Accept: application/json' \
      --json '{
            "email": "user@gmail.com",
            "password": "yourpassword"
      }'

Sample Response

{
    "uuid": "f9ad2679-df49-4417-8a21-a4c852fcecaa",
    "name": "Your Name",
    "email": "user@gmail.com",
    "access_token": "3142|WwCUZjTFz7R31RBFfTVCSxeNwy9RLqHw8Zugtorma198531d",
    "token_type": "Bearer",
    "role": "Complimentary Subscriber",
    ...
}

The access_token value included in the response represents your authenticated session. This token must be sent with every request to any endpoint that requires authentication. To access protected resources, include the token in the Authorization header using the Authorization: Bearer <access_token> format. Requests made without a valid token will be denied, and the API will return an authentication error.


Logout

API Endpoint

POST /logout

Headers

TypeValueRequire
Acceptapplication/jsonYes
AuthorizationBearer {{access_token}}Yes

Sample Request

curl --location \
      --request POST 'https://n3c-api.cidb.gov.my/logout' \
      --header 'Accept: application/json' \
      --header 'Authorization: Bearer 3142|WwCUZjTFz7R31RBFfTVCSxeNwy9RLqHw8Zugtorma1980d61'

Sample Response

{
    "message": "Successfully logged out"
}