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
Fix eslint warnings and TODOs in OAuth module #1425
Conversation
packages/oauth/src/index.ts
Outdated
...queryResult as Installation<'v2', boolean>, | ||
}; | ||
const refreshResponses: OAuthV2TokenRefreshResponse[] = await this.refreshExpiringTokens(tokensToRefresh); | ||
refreshResponses.forEach((refreshResp) => { |
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.
Resolved // eslint-disable-next-line no-restricted-syntax
packages/oauth/src/index.ts
Outdated
|
||
// TODO: related to the above TODO comment as well | ||
// eslint-disable-next-line no-await-in-loop | ||
await this.installationStore.storeInstallation(updatedInstallation); |
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.
If both bot and user tokens are refreshed, the current code saves those refreshed token separately (twice in the loop at maximum). However, this can be done at a time. @misscoded Let me know if you see any issues with this.
packages/oauth/src/index.ts
Outdated
@@ -197,14 +200,17 @@ export class InstallProvider { | |||
const tokensToRefresh: string[] = detectExpiredOrExpiringTokens(authResult, currentUTCSec); | |||
|
|||
if (tokensToRefresh.length > 0) { | |||
const installationUpdates: any = { ...queryResult }; // TODO :: TS |
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.
Resolved the TODO by adding an internal type TokenRefreshInstallationUpdates
packages/oauth/src/index.ts
Outdated
// map/reduce? But will the return value be the same? Does order of this array matter? | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const refreshResp of refreshResponses) { | ||
if (queryResult.authVersion !== 'v2') { |
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.
This is not a common situation at all but this can happen if custom InstallationStore#fetchInstallation()
method returned an unexpected data.
packages/oauth/src/index.ts
Outdated
} catch (error: any) { | ||
throw new AuthorizationError(error.message); | ||
} catch (error) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
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.
still disabling eslint here but this revised one should be slightly clearer
packages/oauth/src/index.ts
Outdated
@@ -529,12 +538,16 @@ export class InstallProvider { | |||
} | |||
|
|||
// Call the failure callback | |||
const codedError: CodedError = error as CodedError; | |||
if (codedError.code === undefined) { |
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.
This never happens as long as bolt-js / @slack/oauth
does not have internal bugs, though. This addition is mainly to satisfy the TS compiler.
packages/oauth/src/index.ts
Outdated
@@ -794,7 +807,7 @@ function callbackFailure( | |||
async function runAuthTest(token: string, clientOptions: WebClientOptions): Promise<AuthTestResult> { | |||
const client = new WebClient(token, clientOptions); | |||
const authResult = await client.auth.test(); | |||
return authResult as any as AuthTestResult; | |||
return authResult as unknown as AuthTestResult; |
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.
this is a recommended way
@@ -63,11 +63,24 @@ export default class FileInstallationStore implements InstallationStore { | |||
throw new Error('enterpriseId is required to fetch data of an enterprise installation'); | |||
} | |||
|
|||
// TODO :: introduce support for user tokens + querying using userId |
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.
Implemented
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.
LGTM!
@filmaj Thanks for your review! To the other reviewers: Still waiting for your responses. Although I've already verified if the change works using the example app, I will add more unit tests to cover more testing patterns before merging this PR (currently we don't have enough tests for this module) |
be254f9
to
939bc4a
Compare
939bc4a
to
593b2ce
Compare
Summary
As a preparation before further development on the OAuth module, this pull request resolves the following issues and TODOs:
Requirements (place an
x
in each[ ]
)