-
Notifications
You must be signed in to change notification settings - Fork 0
Changes to OAuth service and update undefined state #585
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: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ import vscode, { EventEmitter } from "vscode"; | |
| import { OAuthUrlHandler } from "../helpers/handlers/OAuthUrl.handler"; | ||
| import { AuthService } from "./auth.service"; | ||
| import { PromiseAdapter, promiseFromEvent } from "../helpers/eventEmitter.helper"; | ||
| import { ErrorResponse, IOAuthService, OAuthPath, OAuthPlatform, UserInfo } from "../models/shared/IOAuthService"; | ||
|
|
||
| import {ErrorResponse, IOAuthService, OAuthPath, OAuthPlatform, UserInfo} from "../models/shared/IOAuthService"; | ||
|
|
||
| type AuthorizeResponse = { | ||
| code: string; | ||
|
|
@@ -16,21 +17,25 @@ export class OAuthService implements IOAuthService { | |
| */ | ||
| public async authenticate(oAuthPath: OAuthPath): Promise<UserInfo | ErrorResponse> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer rename this function to oAuthenticate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #596 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #597 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #598 |
||
| const oAuthPlatform: OAuthPlatform = oAuthPath === OAuthPath.google ? OAuthPlatform.google : OAuthPlatform.github; | ||
| const eventEmitter = OAuthUrlHandler.getInstance().getEventEmitter(); | ||
| const ee = OAuthUrlHandler.getInstance().getEventEmitter(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change for a much more descriptive variable name
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag rename this to be a much more descriptive variable name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #586 |
||
| const uri = vscode.Uri.parse(`${process.env.API_URL}${oAuthPath}`); | ||
|
|
||
| await vscode.env.openExternal(uri); | ||
|
|
||
| // Register a single listener for the URI callback, in case the user starts the login process multiple times | ||
| // before completing it. | ||
| if (!OAuthService.codeExchangePromise) { | ||
| OAuthService.codeExchangePromise = promiseFromEvent(eventEmitter.event, this.postAuthorization()); | ||
| OAuthService.codeExchangePromise = promiseFromEvent( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this is multiple lines
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag can you collapse this all into one line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #588 |
||
| ee.event, | ||
| this.postAuthorization() | ||
| ); | ||
|
Comment on lines
+28
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag can you collapse this all into one line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #594 |
||
| } | ||
|
|
||
| return Promise.race([ | ||
| OAuthService.codeExchangePromise.promise, | ||
| new Promise<ErrorResponse>((_, reject) => | ||
| setTimeout(() => { | ||
| // TODO we should make this alot simpler | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We fixed this already, maybe add some comments
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag remove this TODO and instead add comments to the return Promise.race on how it works There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #589 |
||
| this.clearCodeExchangePromise(); | ||
| reject({ | ||
| errorType: "cancelled", | ||
|
|
@@ -46,23 +51,24 @@ export class OAuthService implements IOAuthService { | |
| () => | ||
| async (uri: vscode.Uri, resolve: (userInfo: UserInfo) => void, reject: (err: any) => void): Promise<void> => { | ||
| this.clearCodeExchangePromise(); | ||
| const parsedQuery = this.parseQuery(uri) as AuthorizeResponse | ErrorResponse; | ||
| if ((parsedQuery as AuthorizeResponse).code) { | ||
| const parsed_query = this.parseQuery(uri) as AuthorizeResponse | ErrorResponse; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use snake case in this file
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag change this to camelCasing please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #587 |
||
| if ((parsed_query as AuthorizeResponse).code) { | ||
| // Get code from URI, pass to our server to exchange for a JWT & user info. | ||
| const loginResponse = await AuthService.getAuthService().login((parsedQuery as AuthorizeResponse).code); | ||
| const loginResponse = await AuthService.getAuthService().login((parsed_query as AuthorizeResponse).code); | ||
| const userInfo = loginResponse.data; | ||
|
|
||
| resolve(userInfo); | ||
| } else { | ||
| reject({ | ||
| errorType: (parsedQuery as ErrorResponse).errorType, | ||
| errorMessage: (parsedQuery as ErrorResponse).errorMessage, | ||
| errorType: (parsed_query as ErrorResponse).errorType, | ||
| errorMessage: (parsed_query as ErrorResponse).errorMessage, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| private parseQuery(uri: vscode.Uri) { | ||
| return uri.query.split("&").reduce((prev: any, current) => { | ||
| // important to split | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a helpful comment to explain
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag can you remove this unhelpful comment and instead actually comment what this code block is doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #590 |
||
| const queryString = current.split("="); | ||
| prev[queryString[0]] = queryString[1]; | ||
| return prev; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ export class UndefinedTextEditorService implements ITextEditorService { | |
|
|
||
| public async loadData(): Promise<void> { | ||
| await this.getContexts(true); | ||
|
|
||
| } | ||
|
|
||
| public async getDefaultCodices(): Promise<Codex[]> { | ||
|
|
@@ -41,6 +42,7 @@ export class UndefinedTextEditorService implements ITextEditorService { | |
| const defaultCodices = await this.getDefaultCodices(); | ||
| if (defaultCodices.length > 0) { | ||
| const defaultCodex = defaultCodices[0]; | ||
|
|
||
| return new CodexService(defaultCodex.id, UserService.getInstance()); | ||
| } else { | ||
| throw new Error("No active codices at this time."); | ||
|
|
@@ -51,7 +53,7 @@ export class UndefinedTextEditorService implements ITextEditorService { | |
| return new CodexService(codexId, UserService.getInstance()); | ||
| } | ||
|
|
||
| public async getDefaultCodexServiceForRepo(repositoryService: RepositoryService): Promise<CodexService> { | ||
| public async getDefaultCodexServiceForRepo(repositoryService: any): Promise<CodexService> { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some comments explaining what this is for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag add comments explaining what this is for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #591 |
||
| const codex: Codex = await UserService.getInstance() | ||
| .getCCLCodexServiceWrapper() | ||
| .getDefaultCodex(repositoryService.origin); | ||
|
|
@@ -65,6 +67,7 @@ export class UndefinedTextEditorService implements ITextEditorService { | |
| if (force) { | ||
| this.contexts = ( | ||
| await Promise.all( | ||
|
|
||
| this.repositoryServices.map(async (rs) => { | ||
| const codexService = await this.getDefaultCodexServiceForRepo(rs); | ||
| if (codexService) { | ||
|
|
@@ -84,9 +87,7 @@ export class UndefinedTextEditorService implements ITextEditorService { | |
| } | ||
|
|
||
| public async updateContextDecorations(force: boolean): Promise<void> { | ||
| if (force) { | ||
| await this.getContexts(force); | ||
| } | ||
| if (force) await this.getContexts(force); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't all be on one line
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag split this into multiple lines so it's easier to read for my future self There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #595 |
||
| await updateDecorations(this.contexts, LINE_DECORATION, GUTTER_DECORATION, this.textEditor); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ export class UserService implements Singleton, IUserService { | |
| return this.ccl.getContextsService(); | ||
| } | ||
|
|
||
| // TODO clean up comments | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would replace this with a valid comment, in fact this file doesn't have any comments explaining the functions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @echolayer-stag remove this todo and add comments that explain all functions in this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EchoLayer posted a change for your review: #593 |
||
| public getCCLCodexServiceWrapper(): ICCLCodexServiceWrapper { | ||
| if (!this.cclCodexServiceWrapper) { | ||
| this.cclCodexServiceWrapper = new CCLCodexServiceWrapper(this.ccl.getCodexService(), this); | ||
|
|
||
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.
Break this import into multiple lines, way too long
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.
@echolayer-stag can you break this import into multiple lines
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.
Sorry, I couldn't find a solution for this task. I'll polish up on the docs for next time.