Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat: microsoft SSO auth completed

Balu Babuc63bc28ca035
diff --git a/packages/hoppscotch-backend/.gitignore b/packages/hoppscotch-backend/.gitignore
index 4a0f78da3..3c0649e8e 100644
--- a/packages/hoppscotch-backend/.gitignore
+++ b/packages/hoppscotch-backend/.gitignore
@@ -2,6 +2,8 @@
/dist
/node_modules
+.vscode
+
.env
diff --git a/packages/hoppscotch-backend/src/auth/strategies/microsoft.strategy.ts b/packages/hoppscotch-backend/src/auth/strategies/microsoft.strategy.ts
index b34cc9335..7bf0a6205 100644
--- a/packages/hoppscotch-backend/src/auth/strategies/microsoft.strategy.ts
+++ b/packages/hoppscotch-backend/src/auth/strategies/microsoft.strategy.ts
@@ -15,11 +15,11 @@ export class MicrosoftStrategy extends PassportStrategy(Strategy) {
clientID: process.env.MICROSOFT_CLIENT_ID,
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
callbackURL: process.env.MICROSOFT_CALLBACK_URL,
- scope: process.env.MICROSOFT_SCOPE,
+ scope: [process.env.MICROSOFT_SCOPE],
});
}
- async validate(accessToken, refreshToken, profile, done) {
+ async validate(accessToken: string, refreshToken: string, profile, done) {
const user = await this.usersService.findUserByEmail(
profile.emails[0].value,
);
diff --git a/packages/hoppscotch-backend/src/user/user.service.ts b/packages/hoppscotch-backend/src/user/user.service.ts
index cf0f374a4..af5b38101 100644
--- a/packages/hoppscotch-backend/src/user/user.service.ts
+++ b/packages/hoppscotch-backend/src/user/user.service.ts
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';
import * as O from 'fp-ts/Option';
import { AuthUser, SSOProviderProfile } from 'src/types/AuthUser';
+import { checkNullability } from 'src/utils';
@Injectable()
export class UserService {
@@ -49,12 +50,12 @@ export class UserService {
return createdUser;
}
- async createUserSSO(accessToken, refreshToken, profile) {
+ async createUserSSO(accessToken: string, refreshToken: string, profile) {
const createdUser = await this.prisma.user.create({
data: {
- name: profile.displayName,
+ name: !profile.displayName ? null : profile.displayName,
email: profile.emails[0].value,
- image: profile.photos[0].value,
+ image: !profile.photos ? null : profile.photos[0].value,
accounts: {
create: {
provider: profile.provider,
diff --git a/packages/hoppscotch-backend/src/utils.ts b/packages/hoppscotch-backend/src/utils.ts
index 93ee6d44b..3b2224d9d 100644
--- a/packages/hoppscotch-backend/src/utils.ts
+++ b/packages/hoppscotch-backend/src/utils.ts
@@ -160,3 +160,8 @@ export const authCookieHandler = (
res.status(HttpStatus.OK).redirect('http://localhost:3170/graphql');
} else res.status(HttpStatus.OK).send();
};
+
+export const checkNullability = (data: string | undefined | null) => {
+ if (!data) return null;
+ return data;
+};