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
|
/dist
|
||||||
/node_modules
|
/node_modules
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ export class MicrosoftStrategy extends PassportStrategy(Strategy) {
|
|||||||
clientID: process.env.MICROSOFT_CLIENT_ID,
|
clientID: process.env.MICROSOFT_CLIENT_ID,
|
||||||
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
|
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
|
||||||
callbackURL: process.env.MICROSOFT_CALLBACK_URL,
|
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(
|
const user = await this.usersService.findUserByEmail(
|
||||||
profile.emails[0].value,
|
profile.emails[0].value,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||||||
import { PrismaService } from 'src/prisma/prisma.service';
|
import { PrismaService } from 'src/prisma/prisma.service';
|
||||||
import * as O from 'fp-ts/Option';
|
import * as O from 'fp-ts/Option';
|
||||||
import { AuthUser, SSOProviderProfile } from 'src/types/AuthUser';
|
import { AuthUser, SSOProviderProfile } from 'src/types/AuthUser';
|
||||||
|
import { checkNullability } from 'src/utils';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@@ -49,12 +50,12 @@ export class UserService {
|
|||||||
return createdUser;
|
return createdUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUserSSO(accessToken, refreshToken, profile) {
|
async createUserSSO(accessToken: string, refreshToken: string, profile) {
|
||||||
const createdUser = await this.prisma.user.create({
|
const createdUser = await this.prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
name: profile.displayName,
|
name: !profile.displayName ? null : profile.displayName,
|
||||||
email: profile.emails[0].value,
|
email: profile.emails[0].value,
|
||||||
image: profile.photos[0].value,
|
image: !profile.photos ? null : profile.photos[0].value,
|
||||||
accounts: {
|
accounts: {
|
||||||
create: {
|
create: {
|
||||||
provider: profile.provider,
|
provider: profile.provider,
|
||||||
|
|||||||
@@ -160,3 +160,8 @@ export const authCookieHandler = (
|
|||||||
res.status(HttpStatus.OK).redirect('http://localhost:3170/graphql');
|
res.status(HttpStatus.OK).redirect('http://localhost:3170/graphql');
|
||||||
} else res.status(HttpStatus.OK).send();
|
} 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