Skip to content

Commit

Permalink
added google sigin in feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bryng001 committed Sep 27, 2024
1 parent 433024a commit f440300
Show file tree
Hide file tree
Showing 25 changed files with 217 additions and 4 deletions.
3 changes: 3 additions & 0 deletions td.server/src/config/env.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import env from '../env/Env.js';
import GithubEnv from '../env/Github.js';
import GitlabEnv from "../env/Gitlab";
import ThreatDragonEnv from '../env/ThreatDragon.js';
import GoogleEnv from '../env/Google.js';

const tryLoadDotEnv = () => {
const github = new GithubEnv();
const gitlab = new GitlabEnv();
const bitbucket = new BitbucketEnv();
const encryption = new EncryptionEnv();
const threatDragon = new ThreatDragonEnv();
const google = new GoogleEnv();
env.get().addProvider(github);
env.get().addProvider(gitlab);
env.get().addProvider(encryption);
env.get().addProvider(bitbucket);
env.get().addProvider(threatDragon);
env.get().addProvider(google);
env.get().hydrate();
};

Expand Down
1 change: 1 addition & 0 deletions td.server/src/controllers/configcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const getConfig = () => ({
bitbucketEnabled: env.get().config.BITBUCKET_CLIENT_ID !== undefined && env.get().config.BITBUCKET_CLIENT_ID !== null,
githubEnabled: env.get().config.GITHUB_CLIENT_ID !== undefined && env.get().config.GITHUB_CLIENT_ID !== null,
gitlabEnabled: env.get().config.GITLAB_CLIENT_ID !== undefined && env.get().config.GITLAB_CLIENT_ID !== null,
googleEnabled: env.get().config.GOOGLE_CLIENT_ID !== undefined && env.get().config.GOOGLE_CLIENT_ID !== null,
localEnabled: true,
});

Expand Down
25 changes: 25 additions & 0 deletions td.server/src/env/Google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Env } from './Env.js';

class GoogleEnv extends Env {
constructor () {
super('Google');
}

get prefix () {
return 'GOOGLE_';
}

// Note that the actual env var will be prepended with GOOGLE_
get properties () {
return [
{ key: 'CLIENT_ID', required: false },
{ key: 'CLIENT_SECRET', required: false },
{ key: 'SCOPE', required: false, defaultValue: 'openid email profile' },
{ key: 'REDIRECT_URI', required: false, defaultValue: 'http://localhost:8080/oauth-return' },
{ key: 'TOKEN_URL', required: false, defaultValue: 'https://oauth2.googleapis.com/token' },
{ key: 'USER_INFO_URL', required: false, defaultValue: 'https://www.googleapis.com/oauth2/v1/userinfo' }
];
}
}

export default GoogleEnv;
82 changes: 82 additions & 0 deletions td.server/src/providers/google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @name google
* @description Identity provider for Google OAuth
*/
import axios from 'axios';
import env from '../env/Env.js';

const name = 'google';

/**
* Determines if the Google provider is configured
* @returns {Boolean}
*/
const isConfigured = () => Boolean(env.get().config.GOOGLE_CLIENT_ID);

/**
* Gets the Google OAuth Login URL
* @returns {String}
*/
const getOauthRedirectUrl = () => {
const scope = env.get().config.GOOGLE_SCOPE || 'openid email profile';
const redirectUri = env.get().config.GOOGLE_REDIRECT_URI;
return `https://accounts.google.com/o/oauth2/auth?response_type=code&scope=${scope}&client_id=${env.get().config.GOOGLE_CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}`;
};

/**
* Gets the return URL for our application, returning from Google
* @param {string} code
* @returns {String}
*/
const getOauthReturnUrl = (code) => {
let returnUrl = `/#/oauth-return?code=${code}`;
if (env.get().config.NODE_ENV === 'development') {
returnUrl = `http://localhost:8080${returnUrl}`;
}
return returnUrl;
};

/**
* Finishes the OAuth login, issues a JWT
* @param {String} code
* @returns {String} jwt
*/
const completeLoginAsync = async (code) => {
const url = `https://oauth2.googleapis.com/token`;
const body = {
client_id: env.get().config.GOOGLE_CLIENT_ID,
client_secret: env.get().config.GOOGLE_CLIENT_SECRET,
code,
grant_type: 'authorization_code',
redirect_uri: env.get().config.GOOGLE_REDIRECT_URI
};
const options = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};

const providerResp = await axios.post(url, new URLSearchParams(body), options);

const tokenInfoUrl = `https://www.googleapis.com/oauth2/v1/userinfo?access_token=${providerResp.data.access_token}`;
const userInfo = await axios.get(tokenInfoUrl);

const user = {
username: userInfo.data.name,
email: userInfo.data.email,
picture: userInfo.data.picture
};

return {
user,
opts: providerResp.data
};
};

export default {
completeLoginAsync,
getOauthReturnUrl,
getOauthRedirectUrl,
isConfigured,
name
};
4 changes: 3 additions & 1 deletion td.server/src/providers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import bitbucket from './bitbucket.js';
import github from './github.js';
import gitlab from "./gitlab";
import google from './google.js';

/**
* An immutable object containing all
Expand All @@ -10,7 +11,8 @@ import gitlab from "./gitlab";
const all = Object.freeze({
github,
gitlab,
bitbucket
bitbucket,
google
});

/**
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const ara = {
displayName: 'Bitbucket',
loginWith: 'تسجيل الدخول باستخدام'
},
google: {
displayName: 'Google',
loginWith: 'تسجيل الدخول باستخدام'
},
local: {
displayName: 'جلسة محلية',
loginWith: 'تسجيل الدخول إلى'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const deu = {
displayName: 'Bitbucket',
loginWith: 'Anmelden mit'
},
google: {
displayName: 'Google',
loginWith: 'Anmelden mit'
},
local: {
displayName: 'Lokale Sitzung',
loginWith: 'Anmelden an'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const ell = {
displayName: 'Bitbucket',
loginWith: 'Είσοδος με'
},
google: {
displayName: 'Google',
loginWith: 'Είσοδος με'
},
local: {
displayName: 'Τοπική Συνεδρία',
loginWith: 'Είσοδος με'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const eng = {
displayName: 'Bitbucket',
loginWith: 'Login with'
},
google: {
displayName: 'Google',
loginWith: 'Login with'
},
local: {
displayName: 'Local Session',
loginWith: 'Login to'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const spa = {
displayName: 'Bitbucket',
loginWith: 'Conectarse con'
},
google: {
displayName: 'Google',
loginWith: 'Conectarse con'
},
local: {
displayName: 'Sesión Local',
loginWith: 'Conectarse con'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const fin = {
displayName: 'Bitbucketissa',
loginWith: 'Kirjaudu sisään'
},
google: {
displayName: 'Google',
loginWith: 'Kirjaudu sisään'
},
local: {
displayName: 'paikallisesti',
loginWith: 'Kirjaudu sisään'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const fra = {
displayName: 'Bitbucket',
loginWith: 'Se connecter avec'
},
google: {
displayName: 'Google',
loginWith: 'Se connecter avec'
},
local: {
displayName: 'une session locale',
loginWith: 'Se connecter avec'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/hi.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const hin = {
displayName: 'Bitbucket',
loginWith: 'से लोगिन करें'
},
google: {
displayName: 'Google',
loginWith: 'से लोगिन करें'
},
local: {
displayName: 'स्थानीय सत्र',
loginWith: 'से लोगिन करें'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const id = {
displayName: 'Bitbucket',
loginWith: 'Masuk dengan'
},
google: {
displayName: 'Google',
loginWith: 'Masuk dengan'
},
local: {
displayName: 'Sesi Lokal',
loginWith: 'Masuk ke'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const jpn = {
displayName: 'Bitbucketで',
loginWith: 'ログイン'
},
google: {
displayName: 'Google',
loginWith: 'ログイン'
},
local: {
displayName: 'ローカルセッション',
loginWith: 'ログイン'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/ms.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const ms = {
displayName: 'Bitbucket',
loginWith: 'Log masuk dengan'
},
google: {
displayName: 'Google',
loginWith: 'Log masuk dengan'
},
local: {
displayName: 'Sesi Tempatan',
loginWith: 'Log masuk ke'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const por = {
displayName: 'Bitbucket',
loginWith: 'Login com'
},
google: {
displayName: 'Google',
loginWith: 'Login com'
},
local: {
displayName: 'Sessão Local',
loginWith: 'Login com'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const rus = {
displayName: 'Bitbucket',
loginWith: 'Login with'
},
google: {
displayName: 'Google',
loginWith: 'Login with'
},
local: {
displayName: 'Local Session',
loginWith: 'Login to'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/uk.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const ukr = {
displayName: 'Bitbucket',
loginWith: 'Login with'
},
google: {
displayName: 'Google',
loginWith: 'Login with'
},
local: {
displayName: 'Local Session',
loginWith: 'Login to'
Expand Down
4 changes: 4 additions & 0 deletions td.vue/src/i18n/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const zho = {
displayName: 'Bitbucket',
loginWith: '登录'
},
google: {
displayName: 'Google',
loginWith: '登录'
},
local: {
displayName: '本地',
loginWith: '登录'
Expand Down
8 changes: 5 additions & 3 deletions td.vue/src/plugins/fontawesome-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import {
faFolderOpen,
faPrint,
faProjectDiagram,
faDiagramProject
faDiagramProject,
} from '@fortawesome/free-solid-svg-icons';

import {faBitbucket, faGithub, faGitlab, faVuejs} from '@fortawesome/free-brands-svg-icons';
import {faBitbucket, faGithub, faGitlab, faVuejs, faGoogle, faGoogleDrive} from '@fortawesome/free-brands-svg-icons';

// Add icons to the library for use
library.add(
Expand Down Expand Up @@ -67,7 +67,9 @@ library.add(
faFolderOpen,
faPrint,
faProjectDiagram,
faDiagramProject
faDiagramProject,
faGoogle,
faGoogleDrive
);

Vue.component('font-awesome-icon', FontAwesomeIcon);
26 changes: 26 additions & 0 deletions td.vue/src/service/provider/google.provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { providerTypes } from './providerTypes.js';

const providerType = providerTypes.google;

const getDashboardActions = () => ([
{
to: `/${providerType}/google/drive`,
key: 'openExisting',
icon: 'google-drive',
iconPreface: 'fab'
},
{
to: `/${providerType}/google/drive?action=create`,
key: 'createNew',
icon: 'plus'
},
{
to: '/demo/select',
key: 'readDemo',
icon: 'cloud-download-alt'
}
]);

export default {
getDashboardActions
};
1 change: 1 addition & 0 deletions td.vue/src/service/provider/providerTypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const providerTypes = {
desktop: 'desktop',
git: 'git',
google: 'google',
local: 'local'
};
Loading

0 comments on commit f440300

Please sign in to comment.