FORK_backend_docs

Authorization API

Table of Contents


POST : Log-in

URL

/api/auth/login

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission O O X X

Request Format

Location Field Name Data Type Required Description
body userId string O account id of the user
body password string O password of the user

Response Format

Key Description
status success
message "login successful"
data object containing keys { token, refreshToken, user }
data.token the Bearer-format authorization token. Is in format "Bearer {MY_TOKEN}"
data.refreshToken the refresh token. This is not in Bearer format, just regular token
data.user object containing the logged-in user info with keys { id, accountId, userType } The client should store this data, especially id to make future API requests

Example Response

{
  "status": "success",
  "data": {
    "token": "Bearer {ACCESS_TOKEN}",
    "refreshToken": "{REFRESH_TOKEN}",
    "user": {
      "id": 1,
      "accountId": "cwwojin",
      "userType": 1
    }
  },
  "message": "login successful"
}

POST : Register New User

URL

/api/auth/register

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission O O X X

Request Format

Location Field Name Data Type Required Description
body userId string O account id of the registering user
body password string O password of the registering user
body userType int O allowed types are 1=KAIST, 2=facility
body email string O the email of the registering user KAIST user’s should have a valid KAIST email @kaist.ac.kr

Response Format

Key Description
status success
data object containing registering user’s information
data.type either 1=KAIST, 2=facility
data.user In case of Facility user, the inserted object user. In case of KAIST user, the id (id in pending_kaist_user table), account_id(same as input)

Notes


POST : Re-send verification mail

URL

/api/auth/resend-verification-mail

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission O O X X

Request Format

Location Field Name Data Type Required Description
body userId string O the account id of the registering KAIST user

Response Format

Key Description
status success
message "verification code sent to ${EMAIL_ADDRESS}"

Notes


POST : Verify KAIST user & complete registration

URL

/api/auth/verify-kaist

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission O O X X

Request Format

Location Field Name Data Type Required Description
body userId string O the account id of the registering KAIST user
body code string O the 6-digit verification code

Response Format

Key Description
status success
data the created user object

POST : Sign-out - Remove user account from the system

URL

/api/auth/sign-out

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission X O O O

Request Format

Location Field Name Data Type Required Description
. . . . .

Response Format

Key Description
status success
data the deleted user object

Notes


POST : Reset password & send new password via email

URL

/api/auth/reset-password

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission O O X X

Request Format

Location Field Name Data Type Required Description
body userId string O the account-ID of the user whose password would be reset

Response Format

Key Description
status success
message "Password reset mail sent"

Notes


POST : Refresh client’s Access-Token using Refresh-Token

URL

/api/auth/refresh

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission X O O O

Prerequisites

Request Format

Location Field Name Data Type Required Description
header Authorization string O user’s access token in Bearer format. This is the same header as for ALL other requests. However in this case, the client will send their expired token.
header Refresh string O user’s refresh token. This header must be included, and it is for this request only.

Example Request

{
  "headers" :{
    "Authorization": "Bearer {ACCESS_TOKEN}",
    "Refresh": "{REFRESH_TOKEN}",
  }
}

Response Format

Key Description
status success
message "access token renewed successfully"
data object containing keys { token, refreshToken, user }
data.token the NEW access token. It is in format "Bearer {MY_TOKEN}"
data.refreshToken the CURRENT refresh token. This is not in Bearer format, just regular token. This is the same value as the one client sent in the header.
data.user object containing the logged-in user info with keys { id, accountId, userType }

Example Response

{
  "status": "success",
  "data": {
    "token": "Bearer {ACCESS_TOKEN}",
    "refreshToken": "{REFRESH_TOKEN}",
    "user": {
      "id": 1,
      "accountId": "cwwojin",
      "userType": 1
    }
  },
  "message": "access token renewed successfully"
}

Response Format - Token Refresh Error / Failure

Key Description
status error
message "refresh token validation failed. Please login again"
data the error object

Example Response - Token Refresh Error / Failure

{
  "status": "error",
  "message": "refresh token validation failed. Please login again",
  "data": {
    "status": 401,
    "message": "refresh token validation failed. Please login again"
  }
}

Notes


POST : Log-out - Destroy User Refresh Token stored in DB

URL

/api/auth/logout

Permissions

userType Guest 0 (Admin) 1 (KAIST) 2 (Facility)
Permission X O O O

Request Format

Location Field Name Data Type Required Description
. . . . .

Response Format

Key Description
status success
message "logout successful"

Notes