Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f4b674

Browse files
committed
Simplify the OAuth flow
1 parent02ac993 commit5f4b674

File tree

3 files changed

+189
-234
lines changed

3 files changed

+189
-234
lines changed

‎src/commands.ts‎

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,11 @@ export class Commands {
305305
}
306306

307307
if(choice==="oauth"){
308-
returnthis.loginWithOAuth(url,client);
308+
returnthis.loginWithOAuth(client);
309309
}elseif(choice==="legacy"){
310-
returnthis.loginWithToken(url,token,client);
310+
constinitialToken=
311+
token||(awaitthis.secretsManager.getSessionToken());
312+
returnthis.loginWithToken(client,initialToken);
311313
}
312314

313315
// User aborted.
@@ -350,10 +352,13 @@ export class Commands {
350352
}
351353

352354
privateasyncloginWithToken(
353-
url:string,
354-
token:string|undefined,
355355
client:CoderApi,
356+
initialToken:string|undefined,
356357
):Promise<{user:User;token:string}|null>{
358+
consturl=client.getAxiosInstance().defaults.baseURL;
359+
if(!url){
360+
thrownewError("No base URL set on REST client");
361+
}
357362
// This prompt is for convenience; do not error if they close it since
358363
// they may already have a token or already have the page opened.
359364
awaitvscode.env.openExternal(vscode.Uri.parse(`${url}/cli-auth`));
@@ -366,7 +371,7 @@ export class Commands {
366371
title:"Coder API Key",
367372
password:true,
368373
placeHolder:"Paste your API key.",
369-
value:token||(awaitthis.secretsManager.getSessionToken()),
374+
value:initialToken,
370375
ignoreFocusOut:true,
371376
validateInput:async(value)=>{
372377
if(!value){
@@ -410,29 +415,17 @@ export class Commands {
410415
* Returns the access token and authenticated user, or null if failed/cancelled.
411416
*/
412417
privateasyncloginWithOAuth(
413-
url:string,
414418
client:CoderApi,
415419
):Promise<{user:User;token:string}|null>{
416420
try{
417421
this.logger.info("Starting OAuth authentication");
418422

419-
// Start OAuth authorization flow
420-
// TODO just pass the client here and do all the neccessary steps (If we are already logged in we'd have the right token and the OAuth client registration saved).
421-
const{ code, verifier}=
422-
awaitthis.oauthSessionManager.startAuthorization(url);
423-
424-
// Exchange authorization code for tokens
425-
consttokenResponse=awaitthis.oauthSessionManager.exchangeToken(
426-
code,
427-
verifier,
428-
);
423+
consttokenResponse=awaitthis.oauthSessionManager.login(client);
429424

430425
// Validate token by fetching user
431426
client.setSessionToken(tokenResponse.access_token);
432427
constuser=awaitclient.getAuthenticatedUser();
433428

434-
this.logger.info("OAuth authentication successful");
435-
436429
return{
437430
token:tokenResponse.access_token,
438431
user,
@@ -491,9 +484,9 @@ export class Commands {
491484
this.logger.info("Logging out");
492485

493486
// Check if using OAuth
494-
// TODO maybe just add this check inside oauthSessionManager
495-
consthasOAuthTokens=awaitthis.secretsManager.getOAuthTokens();
496-
if(hasOAuthTokens){
487+
constisOAuthLoggedIn=
488+
awaitthis.oauthSessionManager.isLoggedInWithOAuth();
489+
if(isOAuthLoggedIn){
497490
this.logger.info("Logging out via OAuth");
498491
try{
499492
awaitthis.oauthSessionManager.logout();

‎src/oauth/clientRegistry.ts‎

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp