moc-oauth-client 3.0.0 → 3.0.2
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 +8 -3
- package/dist/index.d.ts +9 -0
- package/dist/index.js +27 -2
- package/package.json +1 -1
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.
|
|
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.
|
|
152
|
+
await oauth.validateAuthorizationCode(code);
|
|
148
153
|
} catch (error) {
|
|
149
154
|
console.error(error.error.message);
|
|
150
155
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ interface MOCOAuthClientBase {
|
|
|
42
42
|
validateAuthorizationCode(code: string): Promise<ApiResponse<ValidateAuthorizationCodeResponse>>;
|
|
43
43
|
lookupUserProfile(accessToken: string): Promise<ApiResponse<LookupUserProfileResponse>>;
|
|
44
44
|
refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
|
|
45
|
+
logout(refreshToken: string): Promise<ApiResponse<boolean>>;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* MOCOAuthClient is a client library for interacting with the MOC OAuth API.
|
|
@@ -81,6 +82,14 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
|
|
|
81
82
|
* @throws An error if the request to refresh the access token fails.
|
|
82
83
|
*/
|
|
83
84
|
refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
|
|
85
|
+
/**
|
|
86
|
+
* Logs out the current user's session using the MOC OAuth API.
|
|
87
|
+
* @param refreshToken The JWT token to use for authentication.
|
|
88
|
+
* @returns A promise resolving to an object containing the response data.
|
|
89
|
+
* The response data will contain a boolean indicating whether the logout was successful or not.
|
|
90
|
+
* @throws An error if the request to log out the current user's session fails.
|
|
91
|
+
*/
|
|
92
|
+
logout(refreshToken: string): Promise<ApiResponse<boolean>>;
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
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,8 @@ 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_AUTHORIZATION_CODE: "/api/v1/service-account/validate-authorization-code"
|
|
85
|
+
VALIDATE_AUTHORIZATION_CODE: "/api/v1/service-account/validate-authorization-code",
|
|
86
|
+
LOGOUT: "/api/v1/service-account/logout"
|
|
85
87
|
};
|
|
86
88
|
|
|
87
89
|
// src/client.ts
|
|
@@ -180,6 +182,29 @@ var MOCOAuthClient = class {
|
|
|
180
182
|
};
|
|
181
183
|
}
|
|
182
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Logs out the current user's session using the MOC OAuth API.
|
|
187
|
+
* @param refreshToken The JWT token to use for authentication.
|
|
188
|
+
* @returns A promise resolving to an object containing the response data.
|
|
189
|
+
* The response data will contain a boolean indicating whether the logout was successful or not.
|
|
190
|
+
* @throws An error if the request to log out the current user's session fails.
|
|
191
|
+
*/
|
|
192
|
+
async logout(refreshToken) {
|
|
193
|
+
try {
|
|
194
|
+
const res = await http.post(API_ENDPOINTS.LOGOUT, {
|
|
195
|
+
refreshToken
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
data: res.data.data,
|
|
199
|
+
error: null
|
|
200
|
+
};
|
|
201
|
+
} catch (e) {
|
|
202
|
+
return {
|
|
203
|
+
data: null,
|
|
204
|
+
error: handleError(e)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
183
208
|
};
|
|
184
209
|
// Annotate the CommonJS export names for ESM import in node:
|
|
185
210
|
0 && (module.exports = {
|