-
Notifications
You must be signed in to change notification settings - Fork 0
[DX-547] Add OAuth2 PKCE login flow as default authentication method #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a7fc9df
3fda271
05b8ae1
9e8402d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { Args, Flags } from "@oclif/core"; | ||
|
|
||
| import { ControlBaseCommand } from "../../control-base-command.js"; | ||
| import { OAuthClient } from "../../services/oauth-client.js"; | ||
| import { promptForConfirmation } from "../../utils/prompt-confirmation.js"; | ||
|
|
||
| export default class AccountsLogout extends ControlBaseCommand { | ||
|
|
@@ -88,6 +89,21 @@ export default class AccountsLogout extends ControlBaseCommand { | |
| } | ||
| } | ||
|
|
||
| // Revoke OAuth tokens if this is an OAuth account | ||
| if (this.configManager.getAuthMethod(targetAlias) === "oauth") { | ||
| const oauthTokens = this.configManager.getOAuthTokens(targetAlias); | ||
| if (oauthTokens) { | ||
| const oauthClient = new OAuthClient({ | ||
| controlHost: flags["control-host"], | ||
| }); | ||
| // Best-effort revocation -- don't block on failure | ||
| await Promise.all([ | ||
| oauthClient.revokeToken(oauthTokens.accessToken), | ||
| oauthClient.revokeToken(oauthTokens.refreshToken), | ||
| ]).catch(() => {}); | ||
|
Comment on lines
+96
to
+103
|
||
| } | ||
| } | ||
|
|
||
| // Remove the account | ||
| const success = this.configManager.removeAccount(targetAlias); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ import chalk from "chalk"; | |
|
|
||
| import { AblyBaseCommand } from "./base-command.js"; | ||
| import { ControlApi, App } from "./services/control-api.js"; | ||
| import { OAuthClient } from "./services/oauth-client.js"; | ||
| import { TokenRefreshMiddleware } from "./services/token-refresh-middleware.js"; | ||
| import { BaseFlags, ErrorDetails } from "./types/cli.js"; | ||
|
|
||
| export abstract class ControlBaseCommand extends AblyBaseCommand { | ||
|
|
@@ -16,6 +18,7 @@ export abstract class ControlBaseCommand extends AblyBaseCommand { | |
| */ | ||
| protected createControlApi(flags: BaseFlags): ControlApi { | ||
| let accessToken = flags["access-token"] || process.env.ABLY_ACCESS_TOKEN; | ||
| let tokenRefreshMiddleware: TokenRefreshMiddleware | undefined; | ||
|
|
||
| if (!accessToken) { | ||
| const account = this.configManager.getCurrentAccount(); | ||
|
|
@@ -26,6 +29,17 @@ export abstract class ControlBaseCommand extends AblyBaseCommand { | |
| } | ||
|
|
||
| accessToken = account.accessToken; | ||
|
|
||
| // Set up token refresh middleware for OAuth accounts | ||
| if (this.configManager.getAuthMethod() === "oauth") { | ||
| const oauthClient = new OAuthClient({ | ||
| controlHost: flags["control-host"], | ||
| }); | ||
| tokenRefreshMiddleware = new TokenRefreshMiddleware( | ||
| this.configManager, | ||
| oauthClient, | ||
| ); | ||
|
Comment on lines
+34
to
+41
|
||
| } | ||
| } | ||
|
|
||
| if (!accessToken) { | ||
|
|
@@ -37,6 +51,7 @@ export abstract class ControlBaseCommand extends AblyBaseCommand { | |
| return new ControlApi({ | ||
| accessToken, | ||
| controlHost: flags["control-host"], | ||
| tokenRefreshMiddleware, | ||
| }); | ||
| } | ||
|
|
||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use configured host fallback when creating
OAuthClient.At Line [97], revocation host is sourced only from
flags["control-host"]. If users rely on configured host values, revocation can target the wrong endpoint and silently not revoke tokens.As per coding guidelines, "Use configuration for endpoint URLs (controlHost) instead of hardcoding endpoint URLs, following the pattern: flags.controlHost || config.controlHost || 'control.ably.net'."
🤖 Prompt for AI Agents