moc-oauth-client 1.0.7 → 2.0.0

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/dist/index.d.ts CHANGED
@@ -10,30 +10,36 @@ interface ApiErrorResponse {
10
10
  message: string;
11
11
  };
12
12
  }
13
+ interface LookupUserProfileResponse {
14
+ id: number;
15
+ email: string;
16
+ username?: string;
17
+ isActive: boolean;
18
+ }
13
19
  interface LoginTokenResponse {
14
20
  redirectUri: string;
15
21
  }
16
- interface ValidateJwtResponse {
17
- isValid: boolean;
18
- payload: {
19
- accessToken: string;
20
- refreshToken: string;
21
- };
22
- }
23
- interface RefreshTokenResponse {
22
+ interface ValidateJwtPayloadResponse {
24
23
  accessToken: string;
25
24
  refreshToken: string;
26
- }
27
- interface LookupUserProfileResponse {
25
+ domain: string;
28
26
  id: number;
29
27
  email: string;
30
28
  username?: string;
31
29
  isActive: boolean;
32
30
  }
31
+ interface ValidateJwtResponse {
32
+ isValid: boolean;
33
+ payload: ValidateJwtPayloadResponse | null;
34
+ }
35
+ interface RefreshTokenResponse {
36
+ accessToken: string;
37
+ refreshToken: string;
38
+ }
33
39
 
34
40
  interface MOCOAuthClientBase {
35
41
  getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
36
- validateJwtToken(accessToken: string): Promise<ApiResponse<ValidateJwtResponse>>;
42
+ validateJwt(jwt: string): Promise<ApiResponse<ValidateJwtResponse>>;
37
43
  lookupUserProfile(accessToken: string): Promise<ApiResponse<LookupUserProfileResponse>>;
38
44
  refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
39
45
  }
@@ -52,13 +58,14 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
52
58
  getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
53
59
  /**
54
60
  * Validates a JWT token using the MOC OAuth API.
55
- * @param accessToken The JWT token to validate.
61
+ * @param jwt The JWT token to validate.
56
62
  * @returns A promise resolving to an object containing the response data.
57
- * The response data will contain a boolean indicating whether the token is valid or not,
58
- * an access token, and a refresh token.
59
- * @throws An error if the request to validate the token fails.
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.
60
67
  */
61
- validateJwtToken(accessToken: string): Promise<ApiResponse<ValidateJwtResponse>>;
68
+ validateJwt(jwt: string): Promise<ApiResponse<ValidateJwtResponse>>;
62
69
  /**
63
70
  * Retrieves the current user's information using the MOC OAuth API.
64
71
  * @param accessToken The JWT token to use for authentication.
@@ -77,4 +84,4 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
77
84
  refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
78
85
  }
79
86
 
80
- export { type ApiErrorResponse, type ApiResponse, type LoginTokenResponse, type LookupUserProfileResponse, MOCOAuthClient, type RefreshTokenResponse, type ValidateJwtResponse };
87
+ export { type ApiErrorResponse, type ApiResponse, type LoginTokenResponse, type LookupUserProfileResponse, MOCOAuthClient, type RefreshTokenResponse, type ValidateJwtPayloadResponse, type ValidateJwtResponse };
package/dist/index.js CHANGED
@@ -81,7 +81,7 @@ var API_ENDPOINTS = {
81
81
  GET_LOGIN_TOKEN: "/api/v1/service-account/login-token",
82
82
  LOOKUP_USER_PROFILE: "/api/v1/service-account/lookup-user-profile",
83
83
  REFRESH_TOKEN: "/api/v1/service-account/refresh-token",
84
- VALIDATE_JWT_TOKEN: "/api/v1/service-account/validate-jwt-token"
84
+ VALIDATE_JWT: "/api/v1/service-account/validate-jwt"
85
85
  };
86
86
 
87
87
  // src/client.ts
@@ -112,16 +112,17 @@ var MOCOAuthClient = class {
112
112
  }
113
113
  /**
114
114
  * Validates a JWT token using the MOC OAuth API.
115
- * @param accessToken The JWT token to validate.
115
+ * @param jwt The JWT token to validate.
116
116
  * @returns A promise resolving to an object containing the response data.
117
- * The response data will contain a boolean indicating whether the token is valid or not,
118
- * an access token, and a refresh token.
119
- * @throws An error if the request to validate the token fails.
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.
120
121
  */
121
- async validateJwtToken(accessToken) {
122
+ async validateJwt(jwt) {
122
123
  try {
123
- const res = await http.post(API_ENDPOINTS.VALIDATE_JWT_TOKEN, {
124
- accessToken
124
+ const res = await http.post(API_ENDPOINTS.VALIDATE_JWT, {
125
+ jwt
125
126
  });
126
127
  return {
127
128
  data: res.data.data,
@@ -143,10 +144,8 @@ var MOCOAuthClient = class {
143
144
  */
144
145
  async lookupUserProfile(accessToken) {
145
146
  try {
146
- const res = await http.get(API_ENDPOINTS.LOOKUP_USER_PROFILE, {
147
- headers: {
148
- Authorization: `Bearer ${accessToken}`
149
- }
147
+ const res = await http.post(API_ENDPOINTS.LOOKUP_USER_PROFILE, {
148
+ accessToken
150
149
  });
151
150
  return {
152
151
  data: res.data.data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moc-oauth-client",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
4
  "description": "OAuth client for Ministry of Commerce, Cambodia",
5
5
  "author": "Ministry of Commerce, Cambodia",
6
6
  "license": "MIT",