moc-oauth-client 2.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,7 +66,7 @@ console.log(result);
66
66
  ✅ Validate Access Token
67
67
 
68
68
  ```typescript
69
- const result = await oauth.validateToken(accessToken);
69
+ const result = await oauth.validateAuthorizationCode(code);
70
70
 
71
71
  console.log(result);
72
72
  ```
@@ -78,7 +78,12 @@ console.log(result);
78
78
  "data": {
79
79
  "isValid": true,
80
80
  "accessToken": "...",
81
- "refreshToken": "..."
81
+ "refreshToken": "...",
82
+ "domain": "...",
83
+ "id": "...",
84
+ "email": "...",
85
+ "username": "...",
86
+ "isActive": "..."
82
87
  },
83
88
  "error": null
84
89
  }
@@ -144,7 +149,7 @@ Example handling:
144
149
 
145
150
  ```typescript
146
151
  try {
147
- await oauth.validateToken(token);
152
+ await oauth.validateAuthorizationCode(code);
148
153
  } catch (error) {
149
154
  console.error(error.error.message);
150
155
  }
package/dist/index.d.ts CHANGED
@@ -19,18 +19,18 @@ interface LookupUserProfileResponse {
19
19
  interface LoginTokenResponse {
20
20
  redirectUri: string;
21
21
  }
22
- interface ValidateJwtPayloadResponse {
23
- accessToken: string;
24
- refreshToken: string;
25
- domain: string;
22
+ interface ValidateAuthorizationCodePayloadResponse {
26
23
  id: number;
27
24
  email: string;
28
25
  username?: string;
29
26
  isActive: boolean;
27
+ accessToken: string;
28
+ refreshToken: string;
29
+ domain: string;
30
30
  }
31
- interface ValidateJwtResponse {
31
+ interface ValidateAuthorizationCodeResponse {
32
32
  isValid: boolean;
33
- payload: ValidateJwtPayloadResponse | null;
33
+ payload: ValidateAuthorizationCodePayloadResponse | null;
34
34
  }
35
35
  interface RefreshTokenResponse {
36
36
  accessToken: string;
@@ -39,7 +39,7 @@ interface RefreshTokenResponse {
39
39
 
40
40
  interface MOCOAuthClientBase {
41
41
  getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
42
- validateJwt(jwt: string): Promise<ApiResponse<ValidateJwtResponse>>;
42
+ validateAuthorizationCode(code: string): Promise<ApiResponse<ValidateAuthorizationCodeResponse>>;
43
43
  lookupUserProfile(accessToken: string): Promise<ApiResponse<LookupUserProfileResponse>>;
44
44
  refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
45
45
  }
@@ -57,15 +57,14 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
57
57
  */
58
58
  getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
59
59
  /**
60
- * Validates a JWT token using the MOC OAuth API.
61
- * @param jwt The JWT token to validate.
60
+ * Validates an authorization code using the MOC OAuth API.
61
+ * @param code The authorization code to validate.
62
62
  * @returns A promise resolving to an object containing the response data.
63
- * The response data will contain the validation result of the JWT token.
64
- * If the JWT token is valid, the response data will contain the payload of the JWT token.
65
- * If the JWT token is invalid, the response data will contain an error.
66
- * @throws An error if the request to validate the JWT token fails.
63
+ * The response data will contain information about whether the authorization code is valid,
64
+ * and an access token and refresh token if it is.
65
+ * @throws An error if the request to validate the authorization code fails.
67
66
  */
68
- validateJwt(jwt: string): Promise<ApiResponse<ValidateJwtResponse>>;
67
+ validateAuthorizationCode(code: string): Promise<ApiResponse<ValidateAuthorizationCodeResponse>>;
69
68
  /**
70
69
  * Retrieves the current user's information using the MOC OAuth API.
71
70
  * @param accessToken The JWT token to use for authentication.
@@ -84,4 +83,4 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
84
83
  refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
85
84
  }
86
85
 
87
- export { type ApiErrorResponse, type ApiResponse, type LoginTokenResponse, type LookupUserProfileResponse, MOCOAuthClient, type RefreshTokenResponse, type ValidateJwtPayloadResponse, type ValidateJwtResponse };
86
+ export { type ApiErrorResponse, type ApiResponse, type LoginTokenResponse, type LookupUserProfileResponse, MOCOAuthClient, type RefreshTokenResponse, type ValidateAuthorizationCodePayloadResponse, type ValidateAuthorizationCodeResponse };
package/dist/index.js CHANGED
@@ -57,7 +57,8 @@ var http = import_axios.default.create({
57
57
  baseURL: config.baseUrl,
58
58
  headers: {
59
59
  "Content-Type": "application/json",
60
- "x-client-id": config.clientId
60
+ "x-client-id": config.clientId,
61
+ "x-client-secret": config.clientSecret
61
62
  }
62
63
  });
63
64
 
@@ -81,7 +82,7 @@ var API_ENDPOINTS = {
81
82
  GET_LOGIN_TOKEN: "/api/v1/service-account/login-token",
82
83
  LOOKUP_USER_PROFILE: "/api/v1/service-account/lookup-user-profile",
83
84
  REFRESH_TOKEN: "/api/v1/service-account/refresh-token",
84
- VALIDATE_JWT: "/api/v1/service-account/validate-jwt"
85
+ VALIDATE_AUTHORIZATION_CODE: "/api/v1/service-account/validate-authorization-code"
85
86
  };
86
87
 
87
88
  // src/client.ts
@@ -111,18 +112,17 @@ var MOCOAuthClient = class {
111
112
  }
112
113
  }
113
114
  /**
114
- * Validates a JWT token using the MOC OAuth API.
115
- * @param jwt The JWT token to validate.
115
+ * Validates an authorization code using the MOC OAuth API.
116
+ * @param code The authorization code to validate.
116
117
  * @returns A promise resolving to an object containing the response data.
117
- * The response data will contain the validation result of the JWT token.
118
- * If the JWT token is valid, the response data will contain the payload of the JWT token.
119
- * If the JWT token is invalid, the response data will contain an error.
120
- * @throws An error if the request to validate the JWT token fails.
118
+ * The response data will contain information about whether the authorization code is valid,
119
+ * and an access token and refresh token if it is.
120
+ * @throws An error if the request to validate the authorization code fails.
121
121
  */
122
- async validateJwt(jwt) {
122
+ async validateAuthorizationCode(code) {
123
123
  try {
124
- const res = await http.post(API_ENDPOINTS.VALIDATE_JWT, {
125
- jwt
124
+ const res = await http.post(API_ENDPOINTS.VALIDATE_AUTHORIZATION_CODE, {
125
+ code
126
126
  });
127
127
  return {
128
128
  data: res.data.data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moc-oauth-client",
3
- "version": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "OAuth client for Ministry of Commerce, Cambodia",
5
5
  "author": "Ministry of Commerce, Cambodia",
6
6
  "license": "MIT",