mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-27 08:27:23 +00:00
* multi org changes * Initial changes * changes * manage sso page * Multi-organization changes * Multi organization changes * multi-org changes * multi-org changes * multi-org changes * multi-org fixes * env variables app.json changes * multi-org-fix * user invitation token fix * multi-org group permission fix * multi-org app privilege * google oauth fix * Remove enable signup for form login * Multi organization fixes * multi-org user invite flow changes * multi-org sign up fix * rebase and multi-org fixes * revert testing logs * test logs revert * migration changes * migration file fix * error message changes * git login for private email fix * dropdown fix * test cases * e2e test cases added * test cases fix * documentation changes * testcases fix * testcases added * replace findOne with findOneOrFail * accept invite testcases * login page fixes * added encrypted tag * review comments * migration fixes * improvements * manage sso loading fix * review comments * migration file changes * new organization creation bug fix * added e2e testcases * added testcases * Update data_sources.controller.ts
29 lines
948 B
TypeScript
29 lines
948 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { OAuth2Client, TokenPayload } from 'google-auth-library';
|
|
import UserResponse from './models/user_response';
|
|
|
|
@Injectable()
|
|
export class GoogleOAuthService {
|
|
constructor() {}
|
|
|
|
#extractDetailsFromPayload(payload: TokenPayload): UserResponse {
|
|
const email = payload.email;
|
|
const userSSOId = payload.sub;
|
|
|
|
const words = payload.name?.split(' ');
|
|
const firstName = words?.[0] || '';
|
|
const lastName = words?.length > 1 ? words[words.length - 1] : '';
|
|
|
|
return { userSSOId, firstName, lastName, email, sso: 'google' };
|
|
}
|
|
|
|
async signIn(token: string, configs: any): Promise<UserResponse> {
|
|
const client: OAuth2Client = new OAuth2Client(configs.clientId);
|
|
const ticket = await client.verifyIdToken({
|
|
idToken: token,
|
|
audience: configs.clientId,
|
|
});
|
|
const payload = ticket.getPayload();
|
|
return this.#extractDetailsFromPayload(payload);
|
|
}
|
|
}
|