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

Feat/selfhosted desktop backend auth #3561

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SESSION_SECRET='add some secret here'
REDIRECT_URL="http://localhost:3000"
WHITELISTED_ORIGINS = "http://localhost:3170,http://localhost:3000,http://localhost:3100"
VITE_ALLOWED_AUTH_PROVIDERS = GOOGLE,GITHUB,MICROSOFT,EMAIL
DESKTOP_DEEP_LINK_URL=hoppscotch://auth

# Google Auth Config
GOOGLE_CLIENT_ID="************************************************"
Expand Down
17 changes: 11 additions & 6 deletions packages/hoppscotch-backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RTCookie } from 'src/decorators/rt-cookie.decorator';
import {
AuthProvider,
authCookieHandler,
authDesktopDeepLinkHandler,
authProviderCheck,
throwHTTPErr,
} from './helper';
Expand Down Expand Up @@ -102,12 +103,16 @@ export class AuthController {
async googleAuthRedirect(@Request() req, @Res() res) {
const authTokens = await this.authService.generateAuthTokens(req.user.uid);
if (E.isLeft(authTokens)) throwHTTPErr(authTokens.left);
authCookieHandler(
res,
authTokens.right,
true,
req.authInfo.state.redirect_uri,
);
if (req.authInfo.state.redirect_uri === 'desktop') {
authDesktopDeepLinkHandler(res, authTokens.right);
} else {
authCookieHandler(
res,
authTokens.right,
true,
req.authInfo.state.redirect_uri,
);
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/hoppscotch-backend/src/auth/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export const authCookieHandler = (
return res.status(HttpStatus.OK).redirect(redirectUrl);
};

export const authDesktopDeepLinkHandler = (
res: Response,
authTokens: AuthTokens,
) => {
const desktopDeepLinkUrl = process.env.DESKTOP_DEEP_LINK_URL;
return res
.status(HttpStatus.OK)
.redirect(
`${desktopDeepLinkUrl}?access_token=${authTokens.access_token}&refresh_token=${authTokens.refresh_token}`,
);
};

/**
* Decode the cookie header from incoming websocket connects and returns a auth token pair
* @param rawCookies cookies from the websocket connection
Expand Down
222 changes: 0 additions & 222 deletions packages/hoppscotch-common/src/components.d.ts

This file was deleted.

6 changes: 6 additions & 0 deletions packages/hoppscotch-selfhost-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"@platform/auth": "^0.1.106",
"@tauri-apps/api": "^1.3.0",
"@tauri-apps/cli": "^1.3.0",
"@urql/core": "^4.1.1",
"@vueuse/core": "^10.4.1",
"axios": "^0.21.4",
"buffer": "^6.0.3",
"cookie": "^0.5.0",
"dioc": "workspace:^",
"environments.api": "link:@platform/environments/environments.api",
"event": "link:@tauri-apps/api/event",
Expand All @@ -29,10 +31,13 @@
"rxjs": "^7.8.1",
"shell": "link:@tauri-apps/api/shell",
"stream-browserify": "^3.0.0",
"subscriptions-transport-ws": "^0.11.0",
"tauri": "link:@tauri-apps/api/tauri",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1",
"tauri-plugin-websocket-api": "github:tauri-apps/tauri-plugin-websocket#v1",
"util": "^0.12.4",
"vue": "^3.2.45",
"wonka": "^6.3.4",
"workbox-window": "^6.5.4"
},
"devDependencies": {
Expand All @@ -46,6 +51,7 @@
"@graphql-typed-document-node/core": "^3.2.0",
"@intlify/vite-plugin-vue-i18n": "^6.0.1",
"@rushstack/eslint-patch": "^1.1.4",
"@types/cookie": "^0.5.1",
"@types/lodash-es": "^4.17.9",
"@types/node": "^18.7.10",
"@typescript-eslint/eslint-plugin": "^5.19.0",
Expand Down
70 changes: 69 additions & 1 deletion packages/hoppscotch-selfhost-desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tauri = { version = "1.4.1", features = [
] }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-deep-link = { git = "https://github.com/FabianLars/tauri-plugin-deep-link", branch = "main" }
tauri-plugin-websocket = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-window-state = "0.1.0"
reqwest = "0.11.20"
serde_json = "1.0.107"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn main() {
tauri_plugin_deep_link::prepare("io.hoppscotch.desktop");

tauri::Builder::default()
.plugin(tauri_plugin_websocket::init())
.plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"targets": "all"
},
"security": {
"csp": "none"
"csp": null
},
"updater": {
"active": false
Expand Down