@gpdoc/cli 1.1.1 → 1.2.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/lib/auth.js +13 -2
- package/package.json +1 -1
package/lib/auth.js
CHANGED
|
@@ -11,7 +11,10 @@ export class AuthError extends Error {
|
|
|
11
11
|
|
|
12
12
|
const DEFAULT_ISSUER = 'https://auth.gpdoc.io/';
|
|
13
13
|
const DEFAULT_AUDIENCE = 'https://gpdoc.us.auth0.com/api/v2/';
|
|
14
|
-
|
|
14
|
+
// This is GPDoc's public native client. Unlike the browser client, it is
|
|
15
|
+
// explicitly approved for Auth0's Device Authorization Grant.
|
|
16
|
+
const DEFAULT_CLIENT_ID = 'hSllIhEMtrPrLtPZpYnNf0MOQbreziL8';
|
|
17
|
+
const DEFAULT_SCOPE = 'openid profile email offline_access';
|
|
15
18
|
|
|
16
19
|
function credentialPath(env) {
|
|
17
20
|
if (env.GPDOC_CREDENTIALS_PATH) return path.resolve(env.GPDOC_CREDENTIALS_PATH);
|
|
@@ -64,6 +67,7 @@ function configuration(env) {
|
|
|
64
67
|
issuer,
|
|
65
68
|
audience: env.GPDOC_AUTH0_AUDIENCE || DEFAULT_AUDIENCE,
|
|
66
69
|
clientId: env.GPDOC_AUTH0_CLIENT_ID || DEFAULT_CLIENT_ID,
|
|
70
|
+
scope: env.GPDOC_AUTH0_SCOPE || DEFAULT_SCOPE,
|
|
67
71
|
deviceAuthorizationEndpoint: new URL('oauth/device/code', issuer).toString(),
|
|
68
72
|
tokenEndpoint: new URL('oauth/token', issuer).toString(),
|
|
69
73
|
};
|
|
@@ -112,9 +116,16 @@ export async function createAuthManager({ env = process.env, fetchImpl = globalT
|
|
|
112
116
|
const { response, payload } = await requestJson(fetchImpl, config.deviceAuthorizationEndpoint, {
|
|
113
117
|
method: 'POST',
|
|
114
118
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
115
|
-
body: new URLSearchParams({
|
|
119
|
+
body: new URLSearchParams({
|
|
120
|
+
client_id: config.clientId,
|
|
121
|
+
audience: config.audience,
|
|
122
|
+
scope: config.scope,
|
|
123
|
+
}),
|
|
116
124
|
});
|
|
117
125
|
if (!response.ok || typeof payload.device_code !== 'string' || typeof payload.user_code !== 'string' || typeof payload.verification_uri !== 'string') {
|
|
126
|
+
if (payload.error === 'unauthorized_client') {
|
|
127
|
+
throw new AuthError('AUTH_DEVICE_FLOW_UNAVAILABLE', 'The configured GPDoc Auth0 client does not support terminal device authorization.');
|
|
128
|
+
}
|
|
118
129
|
throw new AuthError('AUTH_FAILED', 'GPDoc could not start device authorization.');
|
|
119
130
|
}
|
|
120
131
|
const intervalSeconds = Math.max(1, Number(payload.interval || 5));
|