feat: microsoft SSO auth completed
This commit is contained in:
2
packages/hoppscotch-backend/.gitignore
vendored
2
packages/hoppscotch-backend/.gitignore
vendored
@@ -2,6 +2,8 @@
|
||||
/dist
|
||||
/node_modules
|
||||
|
||||
.vscode
|
||||
|
||||
.env
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user