Commit cfa1f71
authored
feat-use-api-key-first (#39)
Ticket:
https://linear.app/onkernel/issue/KERNEL-487/cli-set-api-key-auth-priority-higher-than-oauth
## Tested
### Current state
```sh
# Using KERNEL_API_KEY it uses my current org I called it Nov 25 ORG notice last browser name
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel browsers list
Browser ID | Created At | Persisten... | Profile | CDP WS URL | Live View URL
ca3u5hijj15ifurm3ujxztml | 2025-11-25... | 9878979987 | - | httof idle browser in... | https://apterygial-mu...
jo2n7c4zgl70zzlnzgmy3t8h | 2025-11-25... | 1223132213 | - | httof idle browser in... | https://apterygial-mu...
hj5tjjncxfkewvor5fsprck0 | 2025-11-25... | Nov25-Org... | - | httof idle browser in... | https://apterygial-mu...
# Log in with and select org "Mateos org"
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel login
INFO Starting Kernel authentication...
INFO This will open your browser to complete the OAuth flow
INFO Authentication URL:
http://localhost:3002/authorize?client_id=J7i8BKwyFBoyPQN3&code_challenge=XPFk4ct2f3mLWg85mgKPZ01yeFdqQnSlR98Ew2pK87g&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A58432%2Fcallback&response_type=code&scope=openid+email&state=eyJjc3JmIjoiSGk0dWg0c0VBMTRFVzUwY3c1NjltUnZpZkx1S0tnSUsifQ%3D%3D
SUCCESS Authentication successful!
SUCCESS ✓ Successfully authenticated with Kernel!
INFO You can now use other Kernel CLI commands without setting KERNEL_API_KEY
# Now it should browsers from my other org "Mateos org"
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel browsers list
[DEBUG] Using OAuth token authentication (token length: 918 chars)
[DEBUG] Token preview: eyJhbGciOiJSUzI1NiIs...C87PgKujVC4nYMU8zDGA
Browser ID | Created At | Persisten... | Profile | CDP WS URL | Live View URL
tmww8k86b170jh8kqxjtzhqu | 2025-11-25... | mateos-Or... | - | httof idle browser in... | https://apterygial-mu...
```
### After changes
```sh
# Using KERNEL_API_KEY it uses my current org I called it Nov 25 ORG notice last browser name
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel browsers list
Browser ID | Created At | Persistent ID | Profile | CDP WS URL | Live View URL
ca3u5hijj15ifurm3ujxztml | 2025-11-25 13:... | 9878979987 | - | httof idle browser instances in... | https://apterygial-multiflorous...
jo2n7c4zgl70zzlnzgmy3t8h | 2025-11-25 14:... | 1223132213 | - | httof idle browser instances in... | https://apterygial-multiflorous...
hj5tjjncxfkewvor5fsprck0 | 2025-11-25 14:... | Nov25-OrgPer... | - | httof idle browser instances in... | https://apterygial-multiflorous...
# Log in with and select org "Mateos org"
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel login
INFO Starting Kernel authentication...
INFO This will open your browser to complete the OAuth flow
INFO Authentication URL:
http://localhost:3002/authorize?client_id=J7i8BKwyFBoyPQN3&code_challenge=qaTOaQ1yIwkNnde8QHJ2sBT4IKqjBly0EfXQ4Gqoe2c&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A58432%2Fcallback&response_type=code&scope=openid+email&state=eyJjc3JmIjoiaW8xVTluSzh5a0xXR0lkSXFjdnBvb20tc09nelEyZU4ifQ%3D%3D
SUCCESS Authentication successful!
SUCCESS ✓ Successfully authenticated with Kernel!
INFO You can now use other Kernel CLI commands without setting KERNEL_API_KEY
# Now it should browsers from my other org "Mateos org"
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel browsers list
[DEBUG] Using OAuth token authentication (token length: 918 chars)
[DEBUG] Token preview: eyJhbGciOiJSUzI1NiIs...pm2ig2L1X7nM9EASXU7Q
Browser ID | Created At | Persistent ID | Profile | CDP WS URL | Live View URL
tmww8k86b170jh8kqxjtzhqu | 2025-11-25 14:... | mateos-OrgPe... | - | httof idle browser instances in... | https://apterygial-multiflorous...
# Now I trigger re build with my latest changes
➜ cli git:(feat-use-api-key-first) ✗ make build
go build -o bin/kernel ./cmd/kernel
# It gives precedence to API KEY
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel browsers list
Browser ID | Created At | Persistent ID | Profile | CDP WS URL | Live View URL
ca3u5hijj15ifurm3ujxztml | 2025-11-25 13:... | 9878979987 | - | httof idle browser instances in... | https://apterygial-multiflorous...
jo2n7c4zgl70zzlnzgmy3t8h | 2025-11-25 14:... | 1223132213 | - | httof idle browser instances in... | https://apterygial-multiflorous...
hj5tjjncxfkewvor5fsprck0 | 2025-11-25 14:... | Nov25-OrgPer... | - | httof idle browser instances in... | https://apterygial-multiflorous...
# I do logout
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel logout
INFO Logging out...
SUCCESS ✓ Successfully logged out
INFO Run 'kernel login' to authenticate again
# Now login again to "Mateos org"
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel login
INFO Starting Kernel authentication...
INFO This will open your browser to complete the OAuth flow
INFO Authentication URL:
http://localhost:3002/authorize?client_id=J7i8BKwyFBoyPQN3&code_challenge=jQg_U5OE4av1FtB1dBwjibFnSLvSrM1jqXsl8DLa70E&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A58432%2Fcallback&response_type=code&scope=openid+email&state=eyJjc3JmIjoidEEwckg5UWh3cktILWFKNWpNaXctRUlWdFFyTE1ncEMifQ%3D%3D
SUCCESS Authentication successful!
SUCCESS ✓ Successfully authenticated with Kernel!
INFO You can now use other Kernel CLI commands without setting KERNEL_API_KEY
# It still gives precedence to my org named "Nov 25" this is the one in API_KEY
➜ cli git:(feat-use-api-key-first) ✗ ./bin/kernel browsers list
Browser ID | Created At | Persistent ID | Profile | CDP WS URL | Live View URL
ca3u5hijj15ifurm3ujxztml | 2025-11-25 13:58:01 EST | 9878979987 | - | httof idle browser instances in the pops://apte... | https://apterygial-multiflorous-magaly.ngrok-fr...
jo2n7c4zgl70zzlnzgmy3t8h | 2025-11-25 14:05:16 EST | 1223132213 | - | httof idle browser instances in the pops://apte... | https://apterygial-multiflorous-magaly.ngrok-fr...
hj5tjjncxfkewvor5fsprck0 | 2025-11-25 14:08:57 EST | Nov25-OrgPersistent | - | httof idle browser instances in the pops://apte... | https://apterygial-multiflorous-magaly.ngrok-fr...
```1 parent 01dc4cd commit cfa1f71
2 files changed
+24
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
16 | 26 | | |
17 | 27 | | |
18 | 28 | | |
| |||
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
| 42 | + | |
| 43 | + | |
33 | 44 | | |
34 | 45 | | |
35 | 46 | | |
| |||
0 commit comments