Skip to content
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

Add deauthentication #2

Merged
merged 12 commits into from
Dec 23, 2022
Merged

Add deauthentication #2

merged 12 commits into from
Dec 23, 2022

Conversation

Orta21
Copy link
Member

@Orta21 Orta21 commented Dec 22, 2022

No description provided.

@Orta21 Orta21 changed the base branch from master to develop December 22, 2022 18:02
Copy link
Member

@leite08 leite08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple/few comments that I think require action on providers

api/app/src/providers/cronometer.ts Outdated Show resolved Hide resolved
api/app/src/providers/oauth2.ts Outdated Show resolved Hide resolved
api/app/src/providers/oauth2.ts Outdated Show resolved Hide resolved
api/app/src/providers/oura.ts Outdated Show resolved Hide resolved
api/app/src/providers/oura.ts Outdated Show resolved Hide resolved
api/app/src/routes/user.ts Outdated Show resolved Hide resolved
api/app/src/routes/user.ts Outdated Show resolved Hide resolved
api/app/src/routes/user.ts Show resolved Hide resolved
docs/mint.json Show resolved Hide resolved
docs/user/revoke-provider-access.mdx Outdated Show resolved Hide resolved
api/app/src/providers/withings.ts Show resolved Hide resolved
docs/user/revoke-provider-access.mdx Outdated Show resolved Hide resolved
Copy link
Member

@leite08 leite08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment about the util fn, otherwise LGTM!!!

Comment on lines 53 to 59
export const getProviderMapFromConnectUserOrFail = (connectedUser: ConnectedUser, provider: ProviderOptions) => {
if (!connectedUser.providerMap) throw new UnauthorizedError();
const providerData = connectedUser.providerMap[provider];
if (!providerData) throw new UnauthorizedError();

return providerData;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job identifying and reusing code! 🙌

I just suggest we keep these util functions to a minimal - usually not domain-related, otherwise we can quickly have a ton of them; as well, exposing the ConnectedUser's internals adds coupling across the app.

In this case, since we need this behavior across multiple files, maybe move this function to be a command related to ConnectedUser? It could throw NotFoundError and we have the route rethrowing it as an UnauthorizedError.

Also, the function returns a Provider's data, not the map, so maybe rename to getProviderDataOrFail() or something similar?

Copy link
Member

@leite08 leite08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small detail 🕵️

@@ -16,6 +16,7 @@ export const oauthUserTokenResponse = z.object({

export interface OAuth2 {
getAuthUri(state: string): Promise<string>;
revokeProviderAccess(connectedUser: ConnectedUser): Promise<void | string>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why returning void | string? It seems we don't need to return string (maybe just add a await on Withings':

    if (status === 0) {
      await this.oauth.revokeLocal(connectedUser);
      return;
    }

Ideally we wouldn't adjust the interface's contract bc of a specific implementation.

@@ -100,7 +100,7 @@ export class Withings extends Provider implements OAuth2 {
const status = await this.revokeToken(client_id, client_secret, timestamp, nonce, providerData.token)

if (status === 0) {
return this.oauth.revokeLocal(connectedUser);
this.oauth.revokeLocal(connectedUser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await?

async revokeProviderAccess(connectedUser: ConnectedUser): Promise<string> {
return this.oauth.revokeLocal(connectedUser);
async revokeProviderAccess(connectedUser: ConnectedUser): Promise<void> {
this.oauth.revokeLocal(connectedUser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the removed return?

async revokeProviderAccess(connectedUser: ConnectedUser) {
return this.oauth.revokeLocal(connectedUser);
async revokeProviderAccess(connectedUser: ConnectedUser): Promise<void> {
this.oauth.revokeLocal(connectedUser);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

@Goncharo Goncharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 🚢 🚢 🚢 🚢 🚢

@Orta21 Orta21 merged commit 7c2b5e0 into develop Dec 23, 2022
@Orta21 Orta21 deleted the allow_users_deauthenticate#51 branch December 23, 2022 17:27
github-merge-queue bot pushed a commit that referenced this pull request Mar 25, 2024
github-merge-queue bot pushed a commit that referenced this pull request Mar 27, 2024
jonahkaye added a commit that referenced this pull request May 3, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 17, 2024
jonahkaye added a commit that referenced this pull request May 17, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants