@deploily/deploily-cli 0.1.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/.devcontainer/devcontainer.json +25 -0
- package/.devcontainer/docker-compose.yml +18 -0
- package/.env.example +8 -0
- package/.github/dependabot.yml +12 -0
- package/.github/workflows/publish.yml +39 -0
- package/LICENSE +201 -0
- package/README.md +105 -0
- package/dist/auth/callback.d.ts +3 -0
- package/dist/auth/callback.d.ts.map +1 -0
- package/dist/auth/callback.js +143 -0
- package/dist/auth/callback.js.map +1 -0
- package/dist/auth/index.d.ts +23 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +173 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/commands/auth.d.ts +4 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +90 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/config/constants.d.ts +22 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +25 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/credentials.d.ts +47 -0
- package/dist/storage/credentials.d.ts.map +1 -0
- package/dist/storage/credentials.js +160 -0
- package/dist/storage/credentials.js.map +1 -0
- package/dist/utils/pkce.d.ts +5 -0
- package/dist/utils/pkce.d.ts.map +1 -0
- package/dist/utils/pkce.js +30 -0
- package/dist/utils/pkce.js.map +1 -0
- package/package.json +37 -0
- package/pnpm-workspace.yaml +5 -0
- package/src/auth/callback.ts +159 -0
- package/src/auth/index.ts +238 -0
- package/src/commands/auth.ts +114 -0
- package/src/config/constants.ts +28 -0
- package/src/index.ts +69 -0
- package/src/storage/credentials.ts +188 -0
- package/src/types/index.d.ts +35 -0
- package/src/utils/pkce.ts +36 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
|
|
3
|
+
{
|
|
4
|
+
"name": "Node.js & TypeScript",
|
|
5
|
+
// Use Docker Compose so we can bring up the Keycloak service alongside the dev container.
|
|
6
|
+
"dockerComposeFile": ["docker-compose.yml"],
|
|
7
|
+
// The service in the compose files that VS Code should open a shell in.
|
|
8
|
+
"service": "workspace",
|
|
9
|
+
// Folder inside the container that will be used as the workspace.
|
|
10
|
+
"workspaceFolder": "/workspace",
|
|
11
|
+
// Ensure the external Keycloak service is started when the devcontainer is created.
|
|
12
|
+
// "runServices": ["keycloak"],
|
|
13
|
+
|
|
14
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
|
15
|
+
// "features": {},
|
|
16
|
+
|
|
17
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
|
18
|
+
// "postCreateCommand": "yarn install",
|
|
19
|
+
|
|
20
|
+
// Configure tool-specific properties.
|
|
21
|
+
// "customizations": {},
|
|
22
|
+
|
|
23
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
|
24
|
+
// "remoteUser": "root"
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
services:
|
|
3
|
+
workspace:
|
|
4
|
+
image: mcr.microsoft.com/devcontainers/typescript-node:5-24-trixie
|
|
5
|
+
# Mount the repository root into the container's workspace folder
|
|
6
|
+
volumes:
|
|
7
|
+
- ..:/workspace:cached
|
|
8
|
+
# Keep the container running; VS Code will attach a shell/session.
|
|
9
|
+
command: tail -f /dev/null
|
|
10
|
+
tty: true
|
|
11
|
+
keycloak:
|
|
12
|
+
image: quay.io/keycloak/keycloak:26.6.3
|
|
13
|
+
environment:
|
|
14
|
+
- KC_BOOTSTRAP_ADMIN_USERNAME=admin
|
|
15
|
+
- KC_BOOTSTRAP_ADMIN_PASSWORD=admin
|
|
16
|
+
command: start-dev
|
|
17
|
+
ports:
|
|
18
|
+
- "8080:8080"
|
package/.env.example
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
KEYCLOAK_REALM_URL="http://localhost:8080/realms/deploily"
|
|
2
|
+
KEYCLOAK_CLIENT_ID="deploily"
|
|
3
|
+
KEYCLOAK_CLIENT_SECRET="your-client-secret"
|
|
4
|
+
KEYCLOAK_REDIRECT_URI="http://localhost:8976/callback"
|
|
5
|
+
KEYCLOAK_TOKEN_ENDPOINT="http://localhost:8080/realms/deploily/protocol/openid-connect/token"
|
|
6
|
+
KEYCLOAK_AUTH_ENDPOINT="http://localhost:8080/realms/deploily/protocol/openid-connect/auth"
|
|
7
|
+
KEYCLOAK_LOGOUT_ENDPOINT="http://localhost:8080/realms/deploily/protocol/openid-connect/logout"
|
|
8
|
+
KEYCLOAK_USERINFO_ENDPOINT="http://localhost:8080/realms/deploily/protocol/openid-connect/userinfo"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for more information:
|
|
4
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
5
|
+
# https://containers.dev/guide/dependabot
|
|
6
|
+
|
|
7
|
+
version: 2
|
|
8
|
+
updates:
|
|
9
|
+
- package-ecosystem: "devcontainers"
|
|
10
|
+
directory: "/"
|
|
11
|
+
schedule:
|
|
12
|
+
interval: weekly
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: github.repository_owner == 'deploily'
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout repository
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Node.js
|
|
19
|
+
uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: 18
|
|
22
|
+
registry-url: "https://registry.npmjs.org/"
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: npm i
|
|
26
|
+
|
|
27
|
+
- name: Authenticate with npm
|
|
28
|
+
run: |
|
|
29
|
+
echo "//registry.npmjs.org/:_authToken=${NPM_SECRET_TOKEN}"
|
|
30
|
+
env:
|
|
31
|
+
NPM_SECRET_TOKEN: ${{ secrets.NPM_SECRET_TOKEN }}
|
|
32
|
+
|
|
33
|
+
- name: Check npm authentication
|
|
34
|
+
run: npm whoami
|
|
35
|
+
env:
|
|
36
|
+
NPM_SECRET_TOKEN: ${{ secrets.NPM_SECRET_TOKEN }}
|
|
37
|
+
|
|
38
|
+
- name: Publish package
|
|
39
|
+
run: npm publish --access public
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# deploily-cli
|
|
2
|
+
|
|
3
|
+
Deploily CLI is a native Node.js command-line tool for authenticating with a Keycloak-backed Deploily environment.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- OAuth2 login flow with PKCE
|
|
8
|
+
- Local callback server for browser-based authentication
|
|
9
|
+
- Secure credential storage via `keytar` with file fallback
|
|
10
|
+
- `login`, `logout`, and `whoami` commands
|
|
11
|
+
- TypeScript + native ESM project setup
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Node.js 20+ recommended
|
|
16
|
+
- pnpm
|
|
17
|
+
- A running Keycloak instance
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
1. Install dependencies:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
2. Start Keycloak with Docker Compose:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
docker compose up -d
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
3. Navigate to `http://localhost:8080` and log in with the default admin credentials (`admin` / `admin`)
|
|
34
|
+
- Create a new realm
|
|
35
|
+
- Create a new client and add `http://localhost:8976/callback` as a valid redirect URI
|
|
36
|
+
- Create a new user and assign them to the realm
|
|
37
|
+
|
|
38
|
+
4. Configure your `.env` file with the Keycloak endpoints and client details
|
|
39
|
+
|
|
40
|
+
5. Build and run the CLI:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm build
|
|
44
|
+
node dist/index.js --help
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To invoke it as a shell command named `deploily`, link the current package globally and ensure pnpm's global bin directory is on your `PATH`:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
export PATH="$HOME/.local/share/pnpm/bin:$PATH"
|
|
51
|
+
pnpm setup
|
|
52
|
+
pnpm link --global .
|
|
53
|
+
deploily --help
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If the `deploily` command still is not found, open a new shell session after adding the PATH export or run the CLI directly with:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
node dist/index.js --help
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Docker Compose
|
|
63
|
+
|
|
64
|
+
The repository includes a simple local Keycloak setup in [docker-compose.yml](docker-compose.yml). This starts Keycloak with the default admin credentials `admin` / `admin` on port `8080`.
|
|
65
|
+
|
|
66
|
+
## Commands
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
deploily login
|
|
70
|
+
deploily logout
|
|
71
|
+
deploily whoami
|
|
72
|
+
deploily --help
|
|
73
|
+
deploily --version
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### `login`
|
|
77
|
+
|
|
78
|
+
Opens your browser, starts the local callback server, and completes the OAuth2 PKCE flow against Keycloak.
|
|
79
|
+
|
|
80
|
+
### `logout`
|
|
81
|
+
|
|
82
|
+
Clears locally stored credentials and attempts to log out from Keycloak.
|
|
83
|
+
|
|
84
|
+
### `whoami`
|
|
85
|
+
|
|
86
|
+
Shows the current authenticated user when credentials are available.
|
|
87
|
+
|
|
88
|
+
## Authentication Flow
|
|
89
|
+
|
|
90
|
+
1. The CLI generates a PKCE code verifier, code challenge, and state value.
|
|
91
|
+
2. It opens the Keycloak authorization URL in your browser.
|
|
92
|
+
3. Keycloak redirects back to the local callback server on port `8976`.
|
|
93
|
+
4. The CLI exchanges the authorization code for tokens.
|
|
94
|
+
5. User info is fetched from the Keycloak userinfo endpoint.
|
|
95
|
+
6. Credentials are stored with `keytar`, or in `~/.config/deploily/config.json` if `keytar` is unavailable.
|
|
96
|
+
|
|
97
|
+
## Project Structure
|
|
98
|
+
|
|
99
|
+
- `src/index.ts` - CLI entry point and command routing
|
|
100
|
+
- `src/commands/` - CLI command handlers
|
|
101
|
+
- `src/auth/` - authentication service and callback server
|
|
102
|
+
- `src/config/` - configuration constants
|
|
103
|
+
- `src/storage/` - credential persistence
|
|
104
|
+
- `src/utils/` - PKCE helpers
|
|
105
|
+
- `src/types/` - shared TypeScript types
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["../../src/auth/callback.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGlD,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,CAAC,CA2IzB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
import { URL } from "url";
|
|
3
|
+
import { AUTH_CONFIG } from "../config/constants.js";
|
|
4
|
+
// Start local HTTP server to listen for OAuth callback
|
|
5
|
+
export async function startCallbackServer(expectedState) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const server = http.createServer((req, res) => {
|
|
8
|
+
if (!req.url) {
|
|
9
|
+
res.writeHead(400);
|
|
10
|
+
res.end("Bad request");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const url = new URL(req.url, `http://localhost:${AUTH_CONFIG.CALLBACK_PORT}`);
|
|
14
|
+
const code = url.searchParams.get("code");
|
|
15
|
+
const state = url.searchParams.get("state");
|
|
16
|
+
const error = url.searchParams.get("error");
|
|
17
|
+
const errorDescription = url.searchParams.get("error_description");
|
|
18
|
+
// Handle errors from Keycloak
|
|
19
|
+
if (error) {
|
|
20
|
+
const errorMsg = errorDescription || error;
|
|
21
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
22
|
+
res.end(`
|
|
23
|
+
<!DOCTYPE html>
|
|
24
|
+
<html>
|
|
25
|
+
<head>
|
|
26
|
+
<title>Authentication Failed</title>
|
|
27
|
+
<style>
|
|
28
|
+
body {
|
|
29
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
30
|
+
display: flex;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
align-items: center;
|
|
33
|
+
height: 100vh;
|
|
34
|
+
margin: 0;
|
|
35
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
36
|
+
}
|
|
37
|
+
.container {
|
|
38
|
+
background: white;
|
|
39
|
+
padding: 40px;
|
|
40
|
+
border-radius: 8px;
|
|
41
|
+
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
|
|
42
|
+
max-width: 500px;
|
|
43
|
+
text-align: center;
|
|
44
|
+
}
|
|
45
|
+
h1 { color: #e74c3c; margin-top: 0; }
|
|
46
|
+
p { color: #555; line-height: 1.6; }
|
|
47
|
+
code { background: #f5f5f5; padding: 2px 6px; border-radius: 3px; }
|
|
48
|
+
</style>
|
|
49
|
+
</head>
|
|
50
|
+
<body>
|
|
51
|
+
<div class="container">
|
|
52
|
+
<h1>Authentication Failed</h1>
|
|
53
|
+
<p>Error: <code>${escapeHtml(errorMsg)}</code></p>
|
|
54
|
+
<p>Please try again with: <code>deploily login</code></p>
|
|
55
|
+
</div>
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
58
|
+
`);
|
|
59
|
+
server.close();
|
|
60
|
+
reject(new Error(`Authentication failed: ${errorMsg}`));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Validate callback
|
|
64
|
+
if (!code || !state) {
|
|
65
|
+
res.writeHead(400);
|
|
66
|
+
res.end("Missing code or state parameter");
|
|
67
|
+
server.close();
|
|
68
|
+
reject(new Error("Missing code or state parameter"));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Validate state parameter (CSRF protection)
|
|
72
|
+
if (state !== expectedState) {
|
|
73
|
+
res.writeHead(403);
|
|
74
|
+
res.end("Invalid state parameter");
|
|
75
|
+
server.close();
|
|
76
|
+
reject(new Error("State parameter mismatch"));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Success response
|
|
80
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
81
|
+
res.end(`
|
|
82
|
+
<!DOCTYPE html>
|
|
83
|
+
<html>
|
|
84
|
+
<head>
|
|
85
|
+
<title>Authentication Successful</title>
|
|
86
|
+
<style>
|
|
87
|
+
body {
|
|
88
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
89
|
+
display: flex;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
align-items: center;
|
|
92
|
+
height: 100vh;
|
|
93
|
+
margin: 0;
|
|
94
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
95
|
+
}
|
|
96
|
+
.container {
|
|
97
|
+
background: white;
|
|
98
|
+
padding: 40px;
|
|
99
|
+
border-radius: 8px;
|
|
100
|
+
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
|
|
101
|
+
max-width: 500px;
|
|
102
|
+
text-align: center;
|
|
103
|
+
}
|
|
104
|
+
h1 { color: #27ae60; margin-top: 0; }
|
|
105
|
+
p { color: #555; line-height: 1.6; }
|
|
106
|
+
</style>
|
|
107
|
+
</head>
|
|
108
|
+
<body>
|
|
109
|
+
<div class="container">
|
|
110
|
+
<h1>Authentication Successful</h1>
|
|
111
|
+
<p>You have successfully authenticated with Deploily.</p>
|
|
112
|
+
<p>You can close this window and return to your terminal.</p>
|
|
113
|
+
</div>
|
|
114
|
+
</body>
|
|
115
|
+
</html>
|
|
116
|
+
`);
|
|
117
|
+
server.close();
|
|
118
|
+
resolve({ code, state });
|
|
119
|
+
});
|
|
120
|
+
server.listen(AUTH_CONFIG.CALLBACK_PORT, "localhost", () => {
|
|
121
|
+
// Server is listening
|
|
122
|
+
});
|
|
123
|
+
// Set a timeout for the callback
|
|
124
|
+
const timeout = setTimeout(() => {
|
|
125
|
+
server.close();
|
|
126
|
+
reject(new Error("Callback timeout: No response from Keycloak"));
|
|
127
|
+
}, 300000); // 5 minutes
|
|
128
|
+
server.on("close", () => {
|
|
129
|
+
clearTimeout(timeout);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function escapeHtml(text) {
|
|
134
|
+
const map = {
|
|
135
|
+
"&": "&",
|
|
136
|
+
"<": "<",
|
|
137
|
+
">": ">",
|
|
138
|
+
'"': """,
|
|
139
|
+
"'": "'",
|
|
140
|
+
};
|
|
141
|
+
return text.replace(/[&<>"']/g, (m) => map[m]);
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=callback.js.map
|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,sBAAsB;QACxB,CAAC,CAAC,CAAA;QAEF,iCAAiC;QACjC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,MAAM,CAAC,KAAK,EAAE,CAAA;YACd,MAAM,CAAC,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC,CAAA;QAClE,CAAC,EAAE,MAAM,CAAC,CAAA,CAAC,YAAY;QAEvB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACtB,YAAY,CAAC,OAAO,CAAC,CAAA;QACvB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,GAAG,GAA2B;QAClC,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,QAAQ;KACd,CAAA;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuthContext, TokenResponse, UserInfo } from "../types/index.js";
|
|
2
|
+
declare class AuthenticationService {
|
|
3
|
+
private client;
|
|
4
|
+
constructor();
|
|
5
|
+
private buildClientAuthHeaders;
|
|
6
|
+
generateAuthorizationUrl(): {
|
|
7
|
+
url: string;
|
|
8
|
+
context: AuthContext;
|
|
9
|
+
};
|
|
10
|
+
exchangeCodeForToken(code: string, codeVerifier: string): Promise<TokenResponse>;
|
|
11
|
+
refreshAccessToken(refreshToken: string): Promise<TokenResponse>;
|
|
12
|
+
getUserInfo(accessToken: string): Promise<UserInfo>;
|
|
13
|
+
storeTokens(token: TokenResponse, userEmail?: string): Promise<void>;
|
|
14
|
+
getValidAccessToken(): Promise<string | null>;
|
|
15
|
+
logout(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if user is authenticated
|
|
18
|
+
*/
|
|
19
|
+
isAuthenticated(): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
export declare const authService: AuthenticationService;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,WAAW,EAEX,aAAa,EACb,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAE1B,cAAM,qBAAqB;IACzB,OAAO,CAAC,MAAM,CAAe;;IAQ7B,OAAO,CAAC,sBAAsB;IAkB9B,wBAAwB,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE;IAwB3D,oBAAoB,CACxB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,aAAa,CAAC;IA8CnB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA4BhE,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAoBnD,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcpE,mBAAmB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAyB7C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B7B;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;CAI1C;AAED,eAAO,MAAM,WAAW,uBAA8B,CAAA"}
|