@glasshome/widget-cli 0.4.10 → 0.4.11
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/package.json +1 -1
- package/src/commands/login.ts +6 -5
- package/src/utils/auth.ts +0 -1
package/package.json
CHANGED
package/src/commands/login.ts
CHANGED
|
@@ -4,10 +4,12 @@ import { log, spinner } from "@clack/prompts";
|
|
|
4
4
|
import open from "open";
|
|
5
5
|
import { getHubUrl, storeToken } from "../utils/auth";
|
|
6
6
|
|
|
7
|
+
// Public client: PKCE authenticates it, no client secret. The redirect is an
|
|
8
|
+
// IP-loopback URI (RFC 8252) registered on the hub.
|
|
7
9
|
const CLIENT_ID = "glasshome-widget-cli";
|
|
8
|
-
const
|
|
10
|
+
const REDIRECT_HOST = "127.0.0.1";
|
|
9
11
|
const REDIRECT_PORT = 9274;
|
|
10
|
-
const REDIRECT_URI = `http
|
|
12
|
+
const REDIRECT_URI = `http://${REDIRECT_HOST}:${REDIRECT_PORT}/callback`;
|
|
11
13
|
const LOGIN_TIMEOUT_MS = 120_000;
|
|
12
14
|
|
|
13
15
|
function base64url(buf: Buffer): string {
|
|
@@ -35,7 +37,7 @@ export async function runLogin(hubUrl?: string): Promise<void> {
|
|
|
35
37
|
}, LOGIN_TIMEOUT_MS);
|
|
36
38
|
|
|
37
39
|
const server = createServer((req: IncomingMessage, res: ServerResponse) => {
|
|
38
|
-
const url = new URL(req.url!, `http
|
|
40
|
+
const url = new URL(req.url!, `http://${REDIRECT_HOST}:${REDIRECT_PORT}`);
|
|
39
41
|
|
|
40
42
|
if (url.pathname !== "/callback") {
|
|
41
43
|
res.writeHead(404);
|
|
@@ -70,7 +72,7 @@ export async function runLogin(hubUrl?: string): Promise<void> {
|
|
|
70
72
|
resolve({ code, receivedState });
|
|
71
73
|
});
|
|
72
74
|
|
|
73
|
-
server.listen(REDIRECT_PORT, () => {
|
|
75
|
+
server.listen(REDIRECT_PORT, REDIRECT_HOST, () => {
|
|
74
76
|
const authUrl = new URL(`${hub}/api/auth/oauth2/authorize`);
|
|
75
77
|
authUrl.searchParams.set("client_id", CLIENT_ID);
|
|
76
78
|
authUrl.searchParams.set("redirect_uri", REDIRECT_URI);
|
|
@@ -109,7 +111,6 @@ export async function runLogin(hubUrl?: string): Promise<void> {
|
|
|
109
111
|
redirect_uri: REDIRECT_URI,
|
|
110
112
|
code_verifier: codeVerifier,
|
|
111
113
|
client_id: CLIENT_ID,
|
|
112
|
-
client_secret: CLIENT_SECRET,
|
|
113
114
|
}),
|
|
114
115
|
});
|
|
115
116
|
|
package/src/utils/auth.ts
CHANGED