@meistrari/auth-core 1.13.3 → 1.14.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.mts +103 -2
- package/dist/index.d.ts +103 -2
- package/dist/index.mjs +144 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3324,6 +3324,61 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
|
|
|
3324
3324
|
data: StartAuthorizationFlowResponse;
|
|
3325
3325
|
error: null;
|
|
3326
3326
|
}>;
|
|
3327
|
+
startDeviceAuthorizationFlow: (requesterApplicationId: string, targetApplicationId: string) => Promise<{
|
|
3328
|
+
data: null;
|
|
3329
|
+
error: {
|
|
3330
|
+
message?: string | undefined;
|
|
3331
|
+
status: number;
|
|
3332
|
+
statusText: string;
|
|
3333
|
+
};
|
|
3334
|
+
} | {
|
|
3335
|
+
data: DeviceAuthorizationResponse;
|
|
3336
|
+
error: null;
|
|
3337
|
+
}>;
|
|
3338
|
+
getDeviceAuthorizationContext: (userCode: string) => Promise<{
|
|
3339
|
+
data: null;
|
|
3340
|
+
error: {
|
|
3341
|
+
message?: string | undefined;
|
|
3342
|
+
status: number;
|
|
3343
|
+
statusText: string;
|
|
3344
|
+
};
|
|
3345
|
+
} | {
|
|
3346
|
+
data: DeviceAuthorizationContextResponse;
|
|
3347
|
+
error: null;
|
|
3348
|
+
}>;
|
|
3349
|
+
approveDeviceAuthorizationFlow: (userCode: string, organizationId: string) => Promise<{
|
|
3350
|
+
data: null;
|
|
3351
|
+
error: {
|
|
3352
|
+
message?: string | undefined;
|
|
3353
|
+
status: number;
|
|
3354
|
+
statusText: string;
|
|
3355
|
+
};
|
|
3356
|
+
} | {
|
|
3357
|
+
data: DeviceAuthorizationActionResponse;
|
|
3358
|
+
error: null;
|
|
3359
|
+
}>;
|
|
3360
|
+
denyDeviceAuthorizationFlow: (userCode: string) => Promise<{
|
|
3361
|
+
data: null;
|
|
3362
|
+
error: {
|
|
3363
|
+
message?: string | undefined;
|
|
3364
|
+
status: number;
|
|
3365
|
+
statusText: string;
|
|
3366
|
+
};
|
|
3367
|
+
} | {
|
|
3368
|
+
data: DeviceAuthorizationActionResponse;
|
|
3369
|
+
error: null;
|
|
3370
|
+
}>;
|
|
3371
|
+
exchangeDeviceCodeForTokens: (deviceCode: string) => Promise<{
|
|
3372
|
+
data: null;
|
|
3373
|
+
error: {
|
|
3374
|
+
message?: string | undefined;
|
|
3375
|
+
status: number;
|
|
3376
|
+
statusText: string;
|
|
3377
|
+
};
|
|
3378
|
+
} | {
|
|
3379
|
+
data: CompleteAuthorizationFlowResponse;
|
|
3380
|
+
error: null;
|
|
3381
|
+
}>;
|
|
3327
3382
|
completeAuthorizationFlow: (code: string, codeVerifier: string) => Promise<{
|
|
3328
3383
|
data: null;
|
|
3329
3384
|
error: {
|
|
@@ -4360,6 +4415,32 @@ type WhoAmIResponse = {
|
|
|
4360
4415
|
user: User;
|
|
4361
4416
|
organization: FullOrganization;
|
|
4362
4417
|
};
|
|
4418
|
+
type DeviceAuthorizationResponse = {
|
|
4419
|
+
device_code: string;
|
|
4420
|
+
user_code: string;
|
|
4421
|
+
verification_uri: string;
|
|
4422
|
+
verification_uri_complete: string;
|
|
4423
|
+
expires_in: number;
|
|
4424
|
+
interval: number;
|
|
4425
|
+
};
|
|
4426
|
+
type DeviceContextApplication = {
|
|
4427
|
+
id: string;
|
|
4428
|
+
name: string;
|
|
4429
|
+
description: string | null;
|
|
4430
|
+
};
|
|
4431
|
+
type DeviceAuthorizationContextResponse = {
|
|
4432
|
+
requester: DeviceContextApplication & {
|
|
4433
|
+
isVerified: boolean;
|
|
4434
|
+
};
|
|
4435
|
+
target: DeviceContextApplication;
|
|
4436
|
+
organizations: FullOrganization[];
|
|
4437
|
+
preselectedOrganizationId: string | null;
|
|
4438
|
+
status: 'pending' | 'approved' | 'denied';
|
|
4439
|
+
expiresIn: number;
|
|
4440
|
+
};
|
|
4441
|
+
type DeviceAuthorizationActionResponse = {
|
|
4442
|
+
success: boolean;
|
|
4443
|
+
};
|
|
4363
4444
|
|
|
4364
4445
|
declare class BaseError extends Error {
|
|
4365
4446
|
code: string;
|
|
@@ -4378,6 +4459,21 @@ declare class AuthorizationFlowError extends ApplicationError {
|
|
|
4378
4459
|
declare class UserNotLoggedInError extends ApplicationError {
|
|
4379
4460
|
constructor(message: string, options?: ErrorOptions);
|
|
4380
4461
|
}
|
|
4462
|
+
declare class DeviceAuthorizationPendingError extends ApplicationError {
|
|
4463
|
+
constructor(options?: ErrorOptions);
|
|
4464
|
+
}
|
|
4465
|
+
declare class DeviceAuthorizationSlowDownError extends ApplicationError {
|
|
4466
|
+
constructor(options?: ErrorOptions);
|
|
4467
|
+
}
|
|
4468
|
+
declare class DeviceAccessDeniedError extends ApplicationError {
|
|
4469
|
+
constructor(options?: ErrorOptions);
|
|
4470
|
+
}
|
|
4471
|
+
declare class DeviceCodeExpiredError extends ApplicationError {
|
|
4472
|
+
constructor(options?: ErrorOptions);
|
|
4473
|
+
}
|
|
4474
|
+
declare class DeviceTransientServerError extends ApplicationError {
|
|
4475
|
+
constructor(options?: ErrorOptions);
|
|
4476
|
+
}
|
|
4381
4477
|
|
|
4382
4478
|
/**
|
|
4383
4479
|
* Service for managing applications and their candidate organizations.
|
|
@@ -4418,6 +4514,11 @@ declare class ApplicationService {
|
|
|
4418
4514
|
* @param organizationId - The organization ID to start the authorization flow for
|
|
4419
4515
|
*/
|
|
4420
4516
|
startAuthorizationFlow(applicationId: string, redirectUri: string, codeChallenge: string, organizationId: string): Promise<StartAuthorizationFlowResponse>;
|
|
4517
|
+
startDeviceAuthorizationFlow(requesterApplicationId: string, targetApplicationId: string): Promise<DeviceAuthorizationResponse>;
|
|
4518
|
+
getDeviceAuthorizationContext(userCode: string): Promise<DeviceAuthorizationContextResponse>;
|
|
4519
|
+
approveDeviceAuthorizationFlow(userCode: string, organizationId: string): Promise<DeviceAuthorizationActionResponse>;
|
|
4520
|
+
denyDeviceAuthorizationFlow(userCode: string): Promise<DeviceAuthorizationActionResponse>;
|
|
4521
|
+
exchangeDeviceCodeForTokens(deviceCode: string): Promise<CompleteAuthorizationFlowResponse>;
|
|
4421
4522
|
/**
|
|
4422
4523
|
* Completes an authorization flow for a specific application.
|
|
4423
4524
|
*
|
|
@@ -5083,5 +5184,5 @@ declare function validateToken(token: string, apiUrl: string): Promise<boolean>;
|
|
|
5083
5184
|
*/
|
|
5084
5185
|
declare function extractTokenPayload(token: string): JWTPayload;
|
|
5085
5186
|
|
|
5086
|
-
export { ApplicationError, AuthClient, AuthorizationFlowError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, createAPIClient, extractTokenPayload, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
|
|
5087
|
-
export type { APIClient, ApiKey, ApiKeyMetadata, ApiKeyWithoutSecret, Application, CompleteAuthorizationFlowResponse, CreateApiKeyPayload, CreateTeamPayload, FullOrganization, Invitation, InviteUserToOrganizationOptions, ListCandidateOrganizationsResponse, ListMembersOptions, Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, WhoAmIResponse };
|
|
5187
|
+
export { ApplicationError, AuthClient, AuthorizationFlowError, DeviceAccessDeniedError, DeviceAuthorizationPendingError, DeviceAuthorizationSlowDownError, DeviceCodeExpiredError, DeviceTransientServerError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, createAPIClient, extractTokenPayload, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
|
|
5188
|
+
export type { APIClient, ApiKey, ApiKeyMetadata, ApiKeyWithoutSecret, Application, CompleteAuthorizationFlowResponse, CreateApiKeyPayload, CreateTeamPayload, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, FullOrganization, Invitation, InviteUserToOrganizationOptions, ListCandidateOrganizationsResponse, ListMembersOptions, Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, WhoAmIResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -3324,6 +3324,61 @@ declare function createAPIClient(apiUrl: string, fetchOptions?: BetterFetchOptio
|
|
|
3324
3324
|
data: StartAuthorizationFlowResponse;
|
|
3325
3325
|
error: null;
|
|
3326
3326
|
}>;
|
|
3327
|
+
startDeviceAuthorizationFlow: (requesterApplicationId: string, targetApplicationId: string) => Promise<{
|
|
3328
|
+
data: null;
|
|
3329
|
+
error: {
|
|
3330
|
+
message?: string | undefined;
|
|
3331
|
+
status: number;
|
|
3332
|
+
statusText: string;
|
|
3333
|
+
};
|
|
3334
|
+
} | {
|
|
3335
|
+
data: DeviceAuthorizationResponse;
|
|
3336
|
+
error: null;
|
|
3337
|
+
}>;
|
|
3338
|
+
getDeviceAuthorizationContext: (userCode: string) => Promise<{
|
|
3339
|
+
data: null;
|
|
3340
|
+
error: {
|
|
3341
|
+
message?: string | undefined;
|
|
3342
|
+
status: number;
|
|
3343
|
+
statusText: string;
|
|
3344
|
+
};
|
|
3345
|
+
} | {
|
|
3346
|
+
data: DeviceAuthorizationContextResponse;
|
|
3347
|
+
error: null;
|
|
3348
|
+
}>;
|
|
3349
|
+
approveDeviceAuthorizationFlow: (userCode: string, organizationId: string) => Promise<{
|
|
3350
|
+
data: null;
|
|
3351
|
+
error: {
|
|
3352
|
+
message?: string | undefined;
|
|
3353
|
+
status: number;
|
|
3354
|
+
statusText: string;
|
|
3355
|
+
};
|
|
3356
|
+
} | {
|
|
3357
|
+
data: DeviceAuthorizationActionResponse;
|
|
3358
|
+
error: null;
|
|
3359
|
+
}>;
|
|
3360
|
+
denyDeviceAuthorizationFlow: (userCode: string) => Promise<{
|
|
3361
|
+
data: null;
|
|
3362
|
+
error: {
|
|
3363
|
+
message?: string | undefined;
|
|
3364
|
+
status: number;
|
|
3365
|
+
statusText: string;
|
|
3366
|
+
};
|
|
3367
|
+
} | {
|
|
3368
|
+
data: DeviceAuthorizationActionResponse;
|
|
3369
|
+
error: null;
|
|
3370
|
+
}>;
|
|
3371
|
+
exchangeDeviceCodeForTokens: (deviceCode: string) => Promise<{
|
|
3372
|
+
data: null;
|
|
3373
|
+
error: {
|
|
3374
|
+
message?: string | undefined;
|
|
3375
|
+
status: number;
|
|
3376
|
+
statusText: string;
|
|
3377
|
+
};
|
|
3378
|
+
} | {
|
|
3379
|
+
data: CompleteAuthorizationFlowResponse;
|
|
3380
|
+
error: null;
|
|
3381
|
+
}>;
|
|
3327
3382
|
completeAuthorizationFlow: (code: string, codeVerifier: string) => Promise<{
|
|
3328
3383
|
data: null;
|
|
3329
3384
|
error: {
|
|
@@ -4360,6 +4415,32 @@ type WhoAmIResponse = {
|
|
|
4360
4415
|
user: User;
|
|
4361
4416
|
organization: FullOrganization;
|
|
4362
4417
|
};
|
|
4418
|
+
type DeviceAuthorizationResponse = {
|
|
4419
|
+
device_code: string;
|
|
4420
|
+
user_code: string;
|
|
4421
|
+
verification_uri: string;
|
|
4422
|
+
verification_uri_complete: string;
|
|
4423
|
+
expires_in: number;
|
|
4424
|
+
interval: number;
|
|
4425
|
+
};
|
|
4426
|
+
type DeviceContextApplication = {
|
|
4427
|
+
id: string;
|
|
4428
|
+
name: string;
|
|
4429
|
+
description: string | null;
|
|
4430
|
+
};
|
|
4431
|
+
type DeviceAuthorizationContextResponse = {
|
|
4432
|
+
requester: DeviceContextApplication & {
|
|
4433
|
+
isVerified: boolean;
|
|
4434
|
+
};
|
|
4435
|
+
target: DeviceContextApplication;
|
|
4436
|
+
organizations: FullOrganization[];
|
|
4437
|
+
preselectedOrganizationId: string | null;
|
|
4438
|
+
status: 'pending' | 'approved' | 'denied';
|
|
4439
|
+
expiresIn: number;
|
|
4440
|
+
};
|
|
4441
|
+
type DeviceAuthorizationActionResponse = {
|
|
4442
|
+
success: boolean;
|
|
4443
|
+
};
|
|
4363
4444
|
|
|
4364
4445
|
declare class BaseError extends Error {
|
|
4365
4446
|
code: string;
|
|
@@ -4378,6 +4459,21 @@ declare class AuthorizationFlowError extends ApplicationError {
|
|
|
4378
4459
|
declare class UserNotLoggedInError extends ApplicationError {
|
|
4379
4460
|
constructor(message: string, options?: ErrorOptions);
|
|
4380
4461
|
}
|
|
4462
|
+
declare class DeviceAuthorizationPendingError extends ApplicationError {
|
|
4463
|
+
constructor(options?: ErrorOptions);
|
|
4464
|
+
}
|
|
4465
|
+
declare class DeviceAuthorizationSlowDownError extends ApplicationError {
|
|
4466
|
+
constructor(options?: ErrorOptions);
|
|
4467
|
+
}
|
|
4468
|
+
declare class DeviceAccessDeniedError extends ApplicationError {
|
|
4469
|
+
constructor(options?: ErrorOptions);
|
|
4470
|
+
}
|
|
4471
|
+
declare class DeviceCodeExpiredError extends ApplicationError {
|
|
4472
|
+
constructor(options?: ErrorOptions);
|
|
4473
|
+
}
|
|
4474
|
+
declare class DeviceTransientServerError extends ApplicationError {
|
|
4475
|
+
constructor(options?: ErrorOptions);
|
|
4476
|
+
}
|
|
4381
4477
|
|
|
4382
4478
|
/**
|
|
4383
4479
|
* Service for managing applications and their candidate organizations.
|
|
@@ -4418,6 +4514,11 @@ declare class ApplicationService {
|
|
|
4418
4514
|
* @param organizationId - The organization ID to start the authorization flow for
|
|
4419
4515
|
*/
|
|
4420
4516
|
startAuthorizationFlow(applicationId: string, redirectUri: string, codeChallenge: string, organizationId: string): Promise<StartAuthorizationFlowResponse>;
|
|
4517
|
+
startDeviceAuthorizationFlow(requesterApplicationId: string, targetApplicationId: string): Promise<DeviceAuthorizationResponse>;
|
|
4518
|
+
getDeviceAuthorizationContext(userCode: string): Promise<DeviceAuthorizationContextResponse>;
|
|
4519
|
+
approveDeviceAuthorizationFlow(userCode: string, organizationId: string): Promise<DeviceAuthorizationActionResponse>;
|
|
4520
|
+
denyDeviceAuthorizationFlow(userCode: string): Promise<DeviceAuthorizationActionResponse>;
|
|
4521
|
+
exchangeDeviceCodeForTokens(deviceCode: string): Promise<CompleteAuthorizationFlowResponse>;
|
|
4421
4522
|
/**
|
|
4422
4523
|
* Completes an authorization flow for a specific application.
|
|
4423
4524
|
*
|
|
@@ -5083,5 +5184,5 @@ declare function validateToken(token: string, apiUrl: string): Promise<boolean>;
|
|
|
5083
5184
|
*/
|
|
5084
5185
|
declare function extractTokenPayload(token: string): JWTPayload;
|
|
5085
5186
|
|
|
5086
|
-
export { ApplicationError, AuthClient, AuthorizationFlowError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, createAPIClient, extractTokenPayload, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
|
|
5087
|
-
export type { APIClient, ApiKey, ApiKeyMetadata, ApiKeyWithoutSecret, Application, CompleteAuthorizationFlowResponse, CreateApiKeyPayload, CreateTeamPayload, FullOrganization, Invitation, InviteUserToOrganizationOptions, ListCandidateOrganizationsResponse, ListMembersOptions, Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, WhoAmIResponse };
|
|
5187
|
+
export { ApplicationError, AuthClient, AuthorizationFlowError, DeviceAccessDeniedError, DeviceAuthorizationPendingError, DeviceAuthorizationSlowDownError, DeviceCodeExpiredError, DeviceTransientServerError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, createAPIClient, extractTokenPayload, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
|
|
5188
|
+
export type { APIClient, ApiKey, ApiKeyMetadata, ApiKeyWithoutSecret, Application, CompleteAuthorizationFlowResponse, CreateApiKeyPayload, CreateTeamPayload, DeviceAuthorizationActionResponse, DeviceAuthorizationContextResponse, DeviceAuthorizationResponse, FullOrganization, Invitation, InviteUserToOrganizationOptions, ListCandidateOrganizationsResponse, ListMembersOptions, Member, ExtendedOrganization as Organization, RemoveUserFromOrganizationOptions, Role, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, StartAuthorizationFlowResponse, Team, TeamMember, UpdateApiKeyPayload, UpdateMemberRoleOptions, UpdateOrganizationPayload, UpdateTeamPayload, User, WhoAmIResponse };
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { defaultStatements } from 'better-auth/plugins/organization/access';
|
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
export { APIError } from 'better-auth';
|
|
10
10
|
|
|
11
|
-
const version = "1.
|
|
11
|
+
const version = "1.14.0";
|
|
12
12
|
|
|
13
13
|
const statements = {
|
|
14
14
|
...defaultStatements,
|
|
@@ -78,6 +78,7 @@ const JWTPayload = z.object({
|
|
|
78
78
|
sessionKey: z.string()
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
+
const DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
81
82
|
function applicationsPluginClient() {
|
|
82
83
|
return {
|
|
83
84
|
id: "applications",
|
|
@@ -110,6 +111,49 @@ function applicationsPluginClient() {
|
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
113
|
},
|
|
114
|
+
startDeviceAuthorizationFlow: async (requesterApplicationId, targetApplicationId) => {
|
|
115
|
+
return await $fetch("/applications/device/authorize", {
|
|
116
|
+
method: "POST",
|
|
117
|
+
body: {
|
|
118
|
+
requesterApplicationId,
|
|
119
|
+
targetApplicationId
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
getDeviceAuthorizationContext: async (userCode) => {
|
|
124
|
+
return await $fetch("/applications/device/context", {
|
|
125
|
+
method: "GET",
|
|
126
|
+
query: {
|
|
127
|
+
userCode
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
approveDeviceAuthorizationFlow: async (userCode, organizationId) => {
|
|
132
|
+
return await $fetch("/applications/device/approve", {
|
|
133
|
+
method: "POST",
|
|
134
|
+
body: {
|
|
135
|
+
userCode,
|
|
136
|
+
organizationId
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
denyDeviceAuthorizationFlow: async (userCode) => {
|
|
141
|
+
return await $fetch("/applications/device/deny", {
|
|
142
|
+
method: "POST",
|
|
143
|
+
body: {
|
|
144
|
+
userCode
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
exchangeDeviceCodeForTokens: async (deviceCode) => {
|
|
149
|
+
return await $fetch("/applications/token", {
|
|
150
|
+
method: "POST",
|
|
151
|
+
body: {
|
|
152
|
+
grantType: DEVICE_CODE_GRANT,
|
|
153
|
+
deviceCode
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
},
|
|
113
157
|
completeAuthorizationFlow: async (code, codeVerifier) => {
|
|
114
158
|
return await $fetch("/applications/token", {
|
|
115
159
|
method: "POST",
|
|
@@ -241,7 +285,70 @@ class UserNotLoggedInError extends ApplicationError {
|
|
|
241
285
|
this.code = "USER_NOT_LOGGED_IN";
|
|
242
286
|
}
|
|
243
287
|
}
|
|
288
|
+
class DeviceAuthorizationPendingError extends ApplicationError {
|
|
289
|
+
constructor(options) {
|
|
290
|
+
super("Authorization is still pending", options);
|
|
291
|
+
this.code = "AUTHORIZATION_PENDING";
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
class DeviceAuthorizationSlowDownError extends ApplicationError {
|
|
295
|
+
constructor(options) {
|
|
296
|
+
super("Polling too frequently. Slow down and retry later.", options);
|
|
297
|
+
this.code = "SLOW_DOWN";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
class DeviceAccessDeniedError extends ApplicationError {
|
|
301
|
+
constructor(options) {
|
|
302
|
+
super("The user denied the device authorization request", options);
|
|
303
|
+
this.code = "ACCESS_DENIED";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
class DeviceCodeExpiredError extends ApplicationError {
|
|
307
|
+
constructor(options) {
|
|
308
|
+
super("The device code expired or has already been consumed", options);
|
|
309
|
+
this.code = "EXPIRED_TOKEN";
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
class DeviceTransientServerError extends ApplicationError {
|
|
313
|
+
constructor(options) {
|
|
314
|
+
super("The authorization server returned a transient error. The exchange can be safely retried.", options);
|
|
315
|
+
this.code = "TRANSIENT_SERVER_ERROR";
|
|
316
|
+
}
|
|
317
|
+
}
|
|
244
318
|
|
|
319
|
+
function parseErrorCode(error) {
|
|
320
|
+
if (!error || typeof error !== "object") {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
const candidateError = error;
|
|
324
|
+
return candidateError.code ?? candidateError.error?.code ?? null;
|
|
325
|
+
}
|
|
326
|
+
function parseErrorMessage(error) {
|
|
327
|
+
if (!error || typeof error !== "object") {
|
|
328
|
+
return "Failed to exchange device code for tokens";
|
|
329
|
+
}
|
|
330
|
+
const candidateError = error;
|
|
331
|
+
return candidateError.message ?? candidateError.error?.message ?? "Failed to exchange device code for tokens";
|
|
332
|
+
}
|
|
333
|
+
function throwDeviceGrantError(error) {
|
|
334
|
+
const code = parseErrorCode(error);
|
|
335
|
+
if (code === "authorization_pending") {
|
|
336
|
+
throw new DeviceAuthorizationPendingError({ cause: error });
|
|
337
|
+
}
|
|
338
|
+
if (code === "slow_down") {
|
|
339
|
+
throw new DeviceAuthorizationSlowDownError({ cause: error });
|
|
340
|
+
}
|
|
341
|
+
if (code === "access_denied") {
|
|
342
|
+
throw new DeviceAccessDeniedError({ cause: error });
|
|
343
|
+
}
|
|
344
|
+
if (code === "expired_token") {
|
|
345
|
+
throw new DeviceCodeExpiredError({ cause: error });
|
|
346
|
+
}
|
|
347
|
+
if (code === "temporarily_unavailable") {
|
|
348
|
+
throw new DeviceTransientServerError({ cause: error });
|
|
349
|
+
}
|
|
350
|
+
throw new ApplicationError(parseErrorMessage(error), { cause: error });
|
|
351
|
+
}
|
|
245
352
|
class ApplicationService {
|
|
246
353
|
/**
|
|
247
354
|
* Creates a new ApplicationService instance.
|
|
@@ -282,6 +389,41 @@ class ApplicationService {
|
|
|
282
389
|
}
|
|
283
390
|
return response.data;
|
|
284
391
|
}
|
|
392
|
+
async startDeviceAuthorizationFlow(requesterApplicationId, targetApplicationId) {
|
|
393
|
+
const response = await this.client.applications.startDeviceAuthorizationFlow(requesterApplicationId, targetApplicationId);
|
|
394
|
+
if (!response.data) {
|
|
395
|
+
throw new Error("No data returned from the API", { cause: response.error });
|
|
396
|
+
}
|
|
397
|
+
return response.data;
|
|
398
|
+
}
|
|
399
|
+
async getDeviceAuthorizationContext(userCode) {
|
|
400
|
+
const response = await this.client.applications.getDeviceAuthorizationContext(userCode);
|
|
401
|
+
if (!response.data) {
|
|
402
|
+
throw new Error("No data returned from the API", { cause: response.error });
|
|
403
|
+
}
|
|
404
|
+
return response.data;
|
|
405
|
+
}
|
|
406
|
+
async approveDeviceAuthorizationFlow(userCode, organizationId) {
|
|
407
|
+
const response = await this.client.applications.approveDeviceAuthorizationFlow(userCode, organizationId);
|
|
408
|
+
if (!response.data) {
|
|
409
|
+
throw new Error("No data returned from the API", { cause: response.error });
|
|
410
|
+
}
|
|
411
|
+
return response.data;
|
|
412
|
+
}
|
|
413
|
+
async denyDeviceAuthorizationFlow(userCode) {
|
|
414
|
+
const response = await this.client.applications.denyDeviceAuthorizationFlow(userCode);
|
|
415
|
+
if (!response.data) {
|
|
416
|
+
throw new Error("No data returned from the API", { cause: response.error });
|
|
417
|
+
}
|
|
418
|
+
return response.data;
|
|
419
|
+
}
|
|
420
|
+
async exchangeDeviceCodeForTokens(deviceCode) {
|
|
421
|
+
const response = await this.client.applications.exchangeDeviceCodeForTokens(deviceCode);
|
|
422
|
+
if (!response.data) {
|
|
423
|
+
throwDeviceGrantError(response.error);
|
|
424
|
+
}
|
|
425
|
+
return response.data;
|
|
426
|
+
}
|
|
285
427
|
/**
|
|
286
428
|
* Completes an authorization flow for a specific application.
|
|
287
429
|
*
|
|
@@ -877,4 +1019,4 @@ function extractTokenPayload(token) {
|
|
|
877
1019
|
return payload;
|
|
878
1020
|
}
|
|
879
1021
|
|
|
880
|
-
export { ApplicationError, AuthClient, AuthorizationFlowError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, extractTokenPayload, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
|
|
1022
|
+
export { ApplicationError, AuthClient, AuthorizationFlowError, DeviceAccessDeniedError, DeviceAuthorizationPendingError, DeviceAuthorizationSlowDownError, DeviceCodeExpiredError, DeviceTransientServerError, EmailRequired, InvalidCallbackURL, InvalidSocialProvider, JWTPayload, JWTPayloadUser, JWTPayloadWorkspace, RefreshTokenExpiredError, Roles, UserNotLoggedInError, ac, extractTokenPayload, isTokenExpired, memberAdditionalFields, organizationAdditionalFields, rolesAccessControl, userAdditionalFields, validateToken };
|