moc-oauth-client 1.0.6 → 1.0.7
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 +24 -17
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface ApiResponse<T> {
|
|
2
2
|
data: T | null;
|
|
3
|
-
error:
|
|
3
|
+
error: ApiErrorResponse["error"] | null;
|
|
4
4
|
}
|
|
5
|
-
interface
|
|
5
|
+
interface ApiErrorResponse {
|
|
6
6
|
status: number;
|
|
7
7
|
success: false;
|
|
8
8
|
error: {
|
|
@@ -10,25 +10,32 @@ interface OAuthError {
|
|
|
10
10
|
message: string;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
interface
|
|
13
|
+
interface LoginTokenResponse {
|
|
14
14
|
redirectUri: string;
|
|
15
15
|
}
|
|
16
|
-
interface
|
|
16
|
+
interface ValidateJwtResponse {
|
|
17
17
|
isValid: boolean;
|
|
18
|
+
payload: {
|
|
19
|
+
accessToken: string;
|
|
20
|
+
refreshToken: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface RefreshTokenResponse {
|
|
18
24
|
accessToken: string;
|
|
19
25
|
refreshToken: string;
|
|
20
26
|
}
|
|
21
|
-
interface
|
|
27
|
+
interface LookupUserProfileResponse {
|
|
28
|
+
id: number;
|
|
22
29
|
email: string;
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
username?: string;
|
|
31
|
+
isActive: boolean;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
interface MOCOAuthClientBase {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
refreshToken(refreshToken: string): Promise<
|
|
35
|
+
getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
|
|
36
|
+
validateJwtToken(accessToken: string): Promise<ApiResponse<ValidateJwtResponse>>;
|
|
37
|
+
lookupUserProfile(accessToken: string): Promise<ApiResponse<LookupUserProfileResponse>>;
|
|
38
|
+
refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* MOCOAuthClient is a client library for interacting with the MOC OAuth API.
|
|
@@ -42,7 +49,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
|
|
|
42
49
|
* The response data will contain the authorization URL for the client.
|
|
43
50
|
* @throws An error if the request to authorize the client fails.
|
|
44
51
|
*/
|
|
45
|
-
|
|
52
|
+
getLoginToken(): Promise<ApiResponse<LoginTokenResponse>>;
|
|
46
53
|
/**
|
|
47
54
|
* Validates a JWT token using the MOC OAuth API.
|
|
48
55
|
* @param accessToken The JWT token to validate.
|
|
@@ -51,7 +58,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
|
|
|
51
58
|
* an access token, and a refresh token.
|
|
52
59
|
* @throws An error if the request to validate the token fails.
|
|
53
60
|
*/
|
|
54
|
-
|
|
61
|
+
validateJwtToken(accessToken: string): Promise<ApiResponse<ValidateJwtResponse>>;
|
|
55
62
|
/**
|
|
56
63
|
* Retrieves the current user's information using the MOC OAuth API.
|
|
57
64
|
* @param accessToken The JWT token to use for authentication.
|
|
@@ -59,7 +66,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
|
|
|
59
66
|
* The response data will contain the current user's email, first name, and last name.
|
|
60
67
|
* @throws An error if the request to retrieve the user's information fails.
|
|
61
68
|
*/
|
|
62
|
-
|
|
69
|
+
lookupUserProfile(accessToken: string): Promise<ApiResponse<LookupUserProfileResponse>>;
|
|
63
70
|
/**
|
|
64
71
|
* Refreshes an access token using the MOC OAuth API.
|
|
65
72
|
* @param refreshToken The JWT token to use for authentication.
|
|
@@ -67,7 +74,7 @@ declare class MOCOAuthClient implements MOCOAuthClientBase {
|
|
|
67
74
|
* The response data will contain the new access token and refresh token.
|
|
68
75
|
* @throws An error if the request to refresh the access token fails.
|
|
69
76
|
*/
|
|
70
|
-
refreshToken(refreshToken: string): Promise<
|
|
77
|
+
refreshToken(refreshToken: string): Promise<ApiResponse<RefreshTokenResponse>>;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
export { type
|
|
80
|
+
export { type ApiErrorResponse, type ApiResponse, type LoginTokenResponse, type LookupUserProfileResponse, MOCOAuthClient, type RefreshTokenResponse, type ValidateJwtResponse };
|
package/dist/index.js
CHANGED
|
@@ -78,10 +78,10 @@ function handleError(error) {
|
|
|
78
78
|
|
|
79
79
|
// src/api-endpoint.ts
|
|
80
80
|
var API_ENDPOINTS = {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
GET_LOGIN_TOKEN: "/api/v1/service-account/login-token",
|
|
82
|
+
LOOKUP_USER_PROFILE: "/api/v1/service-account/lookup-user-profile",
|
|
83
83
|
REFRESH_TOKEN: "/api/v1/service-account/refresh-token",
|
|
84
|
-
|
|
84
|
+
VALIDATE_JWT_TOKEN: "/api/v1/service-account/validate-jwt-token"
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
// src/client.ts
|
|
@@ -92,9 +92,9 @@ var MOCOAuthClient = class {
|
|
|
92
92
|
* The response data will contain the authorization URL for the client.
|
|
93
93
|
* @throws An error if the request to authorize the client fails.
|
|
94
94
|
*/
|
|
95
|
-
async
|
|
95
|
+
async getLoginToken() {
|
|
96
96
|
try {
|
|
97
|
-
const res = await http.post(API_ENDPOINTS.
|
|
97
|
+
const res = await http.post(API_ENDPOINTS.GET_LOGIN_TOKEN, {
|
|
98
98
|
clientId: config.clientId,
|
|
99
99
|
clientSecret: config.clientSecret,
|
|
100
100
|
redirectUri: config.redirectUri
|
|
@@ -118,9 +118,9 @@ var MOCOAuthClient = class {
|
|
|
118
118
|
* an access token, and a refresh token.
|
|
119
119
|
* @throws An error if the request to validate the token fails.
|
|
120
120
|
*/
|
|
121
|
-
async
|
|
121
|
+
async validateJwtToken(accessToken) {
|
|
122
122
|
try {
|
|
123
|
-
const res = await http.post(API_ENDPOINTS.
|
|
123
|
+
const res = await http.post(API_ENDPOINTS.VALIDATE_JWT_TOKEN, {
|
|
124
124
|
accessToken
|
|
125
125
|
});
|
|
126
126
|
return {
|
|
@@ -141,9 +141,9 @@ var MOCOAuthClient = class {
|
|
|
141
141
|
* The response data will contain the current user's email, first name, and last name.
|
|
142
142
|
* @throws An error if the request to retrieve the user's information fails.
|
|
143
143
|
*/
|
|
144
|
-
async
|
|
144
|
+
async lookupUserProfile(accessToken) {
|
|
145
145
|
try {
|
|
146
|
-
const res = await http.get(API_ENDPOINTS.
|
|
146
|
+
const res = await http.get(API_ENDPOINTS.LOOKUP_USER_PROFILE, {
|
|
147
147
|
headers: {
|
|
148
148
|
Authorization: `Bearer ${accessToken}`
|
|
149
149
|
}
|