📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added github sso for auth & provider support
Blue Mouse49030828b610
diff --git a/public/locales/en.json b/public/locales/en.jsonindex 16119f725..6ed0115be 100644--- a/public/locales/en.json+++ b/public/locales/en.json@@ -305,7 +305,8 @@"checkLeakedPassword": "Check if password is leaked","checkLeakedPasswordDesc": "When enabled we check your password with the <db>{{database}}</db> database. We don't send your password to the service. First we hash your password (using SHA1) and send only the first 5 characters of that hash to the service. The service returns all leaked passwords that start with those 5 characters. At our end we check if one of these matches with your password. We show you a warning if it has been leaked before. We never store your password in plain text.","addedOn": "Added on",- "continueWithGoogle": "Continue with Google"+ "continueWithGoogle": "Continue with Google",+ "continueWithGithub": "Continue with Github"}},"features": {diff --git a/src/api/index.ts b/src/api/index.tsindex a989fe162..d72fd2d60 100644--- a/src/api/index.ts+++ b/src/api/index.ts@@ -809,9 +809,11 @@ export const confirmTransferProject = (uuid: string) =>: error.response.data.message})-export const generateGoogleAuthURL = () =>+export const generateSSOAuthURL = (provider: string) =>api- .post('v1/auth/google/generate')+ .post('v1/auth/sso/generate', {+ provider,+ }).then((response): unknown => response.data).catch((error) => {debug('%s', error)diff --git a/src/components/GithubAuth.tsx b/src/components/GithubAuth.tsxnew file mode 100644index 000000000..6403b24c6--- /dev/null+++ b/src/components/GithubAuth.tsx@@ -0,0 +1,80 @@+import React from 'react'+import { useTranslation } from 'react-i18next'+import { useSelector } from 'react-redux'+import cx from 'clsx'++import Button from 'ui/Button'+import { StateType } from 'redux/store/index'+import GithubDarkSVG from 'ui/icons/GithubDark'+import GithubLightSVG from 'ui/icons/GithubLight'+import { SSO_PROVIDERS } from 'redux/constants'++interface IGoogleAuth {+ setIsLoading: (isLoading: boolean) => void,+ authSSO: (provider: string, dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void+ callback?: any,+ dontRemember?: boolean,+ isMiniButton?: boolean,+ className?: string+}++const GithubAuth: React.FC<IGoogleAuth> = ({+ setIsLoading, authSSO, dontRemember, callback, isMiniButton, className,+}) => {+ const { t } = useTranslation()+ const { theme } = useSelector((state: StateType) => state.ui.theme)++ const googleLogin = async () => {+ setIsLoading(true)+ authSSO(+ SSO_PROVIDERS.GITHUB,+ dontRemember as boolean,+ t,+ callback,+ )+ }++ if (isMiniButton) {+ return (+ <Button+ className={cx(className, 'border-indigo-100 dark:text-gray-50 dark:border-gray-700 dark:bg-gray-700 dark:hover:bg-gray-600')}+ onClick={googleLogin}+ secondary+ regular+ >+ {theme === 'dark' ? (+ <GithubLightSVG className='w-5 h-5' />+ ) : (+ <GithubDarkSVG className='w-5 h-5' />+ )}+ </Button>+ )+ }++ return (+ <Button+ className={cx(className, 'border-indigo-100 dark:text-gray-50 dark:border-gray-700 dark:bg-gray-700 dark:hover:bg-gray-600')}+ onClick={googleLogin}+ secondary+ regular+ >+ <>+ {theme === 'dark' ? (+ <GithubLightSVG className='w-5 h-5 mr-2' />+ ) : (+ <GithubDarkSVG className='w-5 h-5 mr-2' />+ )}+ {t('auth.common.continueWithGithub')}+ </>+ </Button>+ )+}++GithubAuth.defaultProps = {+ dontRemember: false,+ isMiniButton: false,+ callback: () => { },+ className: '',+}++export default GithubAuthdiff --git a/src/components/GoogleAuth.tsx b/src/components/GoogleAuth.tsxindex d7764347c..3b4508c0d 100644--- a/src/components/GoogleAuth.tsx+++ b/src/components/GoogleAuth.tsx@@ -4,10 +4,11 @@ import cx from 'clsx'import Button from 'ui/Button'import GoogleGSVG from 'ui/icons/GoogleG'+import { SSO_PROVIDERS } from 'redux/constants'interface IGoogleAuth {setIsLoading: (isLoading: boolean) => void,- authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void+ authSSO: (provider: string, dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => voidcallback?: any,dontRemember?: boolean,isMiniButton?: boolean,@@ -22,6 +23,7 @@ const GoogleAuth: React.FC<IGoogleAuth> = ({const googleLogin = async () => {setIsLoading(true)authSSO(+ SSO_PROVIDERS.GOOGLE,dontRemember as boolean,t,callback,diff --git a/src/pages/Auth/Signin/Signin.container.tsx b/src/pages/Auth/Signin/Signin.container.tsxindex e737ade5b..16034accf 100644--- a/src/pages/Auth/Signin/Signin.container.tsx+++ b/src/pages/Auth/Signin/Signin.container.tsx@@ -25,9 +25,8 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({message: error,}))},- authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => {- console.log('dispatching authSSO')- dispatch(sagaActions.authSSO(dontRemember, t, callback))+ authSSO: (provider: string, dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => {+ dispatch(sagaActions.authSSO(provider, dontRemember, t, callback))},})diff --git a/src/pages/Auth/Signin/Signin.tsx b/src/pages/Auth/Signin/Signin.tsxindex a9559c95c..e6d3931f7 100644--- a/src/pages/Auth/Signin/Signin.tsx+++ b/src/pages/Auth/Signin/Signin.tsx@@ -8,6 +8,7 @@ import _isString from 'lodash/isString'import Title from 'components/Title'import GoogleAuth from 'components/GoogleAuth'+import GithubAuth from 'components/GithubAuth'import { withAuthentication, auth } from 'hoc/protected'import routes from 'routes'import Input from 'ui/Input'@@ -34,10 +35,10 @@ interface ISignin {password: string,dontRemember: boolean},- callback: (result: boolean, twoFARequired: boolean) => void) => void,+ callback: (result: boolean, twoFARequired: boolean) => void) => void,loginSuccess: (user: IUser) => void,loginFailed: (error: string) => void,- authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void+ authSSO: (provider: string, dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void}const Signin = ({@@ -254,13 +255,22 @@ const Signin = ({{t('auth.signin.button')}</Button></div>- <GoogleAuth- className='mt-4'- setIsLoading={setIsLoading}- authSSO={authSSO}- callback={loginCallback}- dontRemember={form.dontRemember}- />+ <div className='space-x-5'>+ <GoogleAuth+ className='mt-4'+ setIsLoading={setIsLoading}+ authSSO={authSSO}+ callback={loginCallback}+ dontRemember={form.dontRemember}+ />+ <GithubAuth+ className='mt-4'+ setIsLoading={setIsLoading}+ authSSO={authSSO}+ callback={loginCallback}+ dontRemember={form.dontRemember}+ />+ </div></form></div></Title>diff --git a/src/pages/Auth/Signup/BasicSignup.tsx b/src/pages/Auth/Signup/BasicSignup.tsxindex 72caf781d..72d8bb2e4 100644--- a/src/pages/Auth/Signup/BasicSignup.tsx+++ b/src/pages/Auth/Signup/BasicSignup.tsx@@ -17,6 +17,7 @@ import { HAVE_I_BEEN_PWNED_URL } from 'redux/constants'import { trackCustom } from 'utils/analytics'import { useAppDispatch } from 'redux/store'import GoogleAuth from 'components/GoogleAuth'+import GithubAuth from 'components/GithubAuth'interface ISignUpForm {email: string,@@ -60,8 +61,8 @@ const BasicSignup = (): JSX.Element => {}}- const authSSO = () => {- dispatch(sagaActions.authSSO(form.dontRemember, t, signUpCallback))+ const authSSO = (provider: string) => {+ dispatch(sagaActions.authSSO(provider, form.dontRemember, t, signUpCallback))}const onSubmit = (data: ISignUpForm) => {@@ -190,11 +191,18 @@ const BasicSignup = (): JSX.Element => {<p className='text-sm mt-2 mb-2 text-center text-gray-500 dark:text-gray-100'>{t('auth.socialisation.orSingUpWith')}</p>- <GoogleAuth- setIsLoading={setIsLoading}- authSSO={authSSO}- isMiniButton- />+ <div className='space-x-5'>+ <GoogleAuth+ setIsLoading={setIsLoading}+ authSSO={authSSO}+ isMiniButton+ />+ <GithubAuth+ setIsLoading={setIsLoading}+ authSSO={authSSO}+ isMiniButton+ />+ </div></div></form>)diff --git a/src/pages/Auth/Signup/Signup.container.tsx b/src/pages/Auth/Signup/Signup.container.tsxindex 3fbaba0ec..6eebdce45 100644--- a/src/pages/Auth/Signup/Signup.container.tsx+++ b/src/pages/Auth/Signup/Signup.container.tsx@@ -15,8 +15,8 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({}) => string, callback: (res: any) => void) => {dispatch(sagaActions.signupAsync(data, t, callback))},- authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => {- dispatch(sagaActions.authSSO(dontRemember, t, callback))+ authSSO: (provider: string, dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => {+ dispatch(sagaActions.authSSO(provider, dontRemember, t, callback))},})diff --git a/src/pages/Auth/Signup/Signup.tsx b/src/pages/Auth/Signup/Signup.tsxindex 8fa589518..31e6699cf 100644--- a/src/pages/Auth/Signup/Signup.tsx+++ b/src/pages/Auth/Signup/Signup.tsx@@ -9,6 +9,7 @@ import _isEmpty from 'lodash/isEmpty'import Title from 'components/Title'import GoogleAuth from 'components/GoogleAuth'+import GithubAuth from 'components/GithubAuth'import { withAuthentication, auth } from 'hoc/protected'import routes from 'routes'import Input from 'ui/Input'@@ -41,7 +42,7 @@ interface ISignup {t: (key: string, options?: {[key: string]: string | number,}) => string, callback: (res: any) => void) => void,- authSSO: (dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void+ authSSO: (provider: string, dontRemember: boolean, t: (key: string) => string, callback: (res: any) => void) => void}const Signup = ({ signup, authSSO }: ISignup): JSX.Element => {@@ -251,13 +252,22 @@ const Signup = ({ signup, authSSO }: ISignup): JSX.Element => {{t('auth.signup.button')}</Button></div>- <GoogleAuth- className='mt-4'- setIsLoading={setIsLoading}- authSSO={authSSO}- callback={signUpCallback}- dontRemember={form.dontRemember}- />+ <div className='space-x-5'>+ <GoogleAuth+ className='mt-4'+ setIsLoading={setIsLoading}+ authSSO={authSSO}+ callback={signUpCallback}+ dontRemember={form.dontRemember}+ />+ <GithubAuth+ className='mt-4'+ setIsLoading={setIsLoading}+ authSSO={authSSO}+ callback={signUpCallback}+ dontRemember={form.dontRemember}+ />+ </div></form></div></Title>diff --git a/src/pages/UserSettings/components/Socialisations.tsx b/src/pages/UserSettings/components/Socialisations.tsxindex d0b4c3152..99f17ff4a 100644--- a/src/pages/UserSettings/components/Socialisations.tsx+++ b/src/pages/UserSettings/components/Socialisations.tsx@@ -8,12 +8,12 @@ import {import Button from 'ui/Button'import Google from 'ui/icons/GoogleG'import { IUser } from 'redux/models/IUser'-import { SOCIALISATIONS } from 'redux/constants'+import { SSO_PROVIDERS } from 'redux/constants'const AVAILABLE_SOCIALISATIONS = [{name: 'Google',- key: SOCIALISATIONS.GOOGLE,+ key: SSO_PROVIDERS.GOOGLE,Icon: Google,},]@@ -24,7 +24,7 @@ const AVAILABLE_SOCIALISATIONS = [* @returns {[boolean, boolean]} - [isConnected, isUnlinkable]*/const getStatusByUser = (user: IUser, socialisation: string) => {- if (socialisation === SOCIALISATIONS.GOOGLE) {+ if (socialisation === SSO_PROVIDERS.GOOGLE) {const connected = user.googleIdconst unlinkable = !user.registeredWithGooglereturn [connected, unlinkable]diff --git a/src/redux/constants/index.ts b/src/redux/constants/index.tsindex 98dd5a010..dc689b100 100644--- a/src/redux/constants/index.ts+++ b/src/redux/constants/index.ts@@ -415,6 +415,7 @@ export const SSO_ACTIONS = Object.freeze({AUTH: 'auth',})-export const SOCIALISATIONS = Object.freeze({+export const SSO_PROVIDERS = Object.freeze({GOOGLE: 'google',+ GITHUB: 'github',})diff --git a/src/redux/sagas/actions/index.ts b/src/redux/sagas/actions/index.tsindex a3bf89e0c..1280ed09d 100644--- a/src/redux/sagas/actions/index.ts+++ b/src/redux/sagas/actions/index.ts@@ -43,10 +43,10 @@ const loginAsync = (credentials: {})// currently only google is supported, in future we should provide a variable specifying the provider-const authSSO = (dontRemember: boolean, t: (key: string) => string = () => '', callback: (res: any) => void = () => { }) => ({+const authSSO = (provider: string, dontRemember: boolean, t: (key: string) => string = () => '', callback: (res: any) => void = () => { }) => ({type: types.AUTH_SSO,payload: {- dontRemember, callback, t,+ dontRemember, callback, t, provider,},})diff --git a/src/redux/sagas/auth/workers/sso_auth.ts b/src/redux/sagas/auth/workers/sso_auth.tsindex bc1b2cba7..9ab91faee 100644--- a/src/redux/sagas/auth/workers/sso_auth.ts+++ b/src/redux/sagas/auth/workers/sso_auth.ts@@ -4,7 +4,7 @@ import { authActions } from 'redux/reducers/auth'import { errorsActions } from 'redux/reducers/errors'import { setAccessToken } from 'utils/accessToken'import {- getJWTByGoogleHash, generateGoogleAuthURL,+ getJWTByGoogleHash, generateSSOAuthURL,} from 'api'import { setRefreshToken } from 'utils/refreshToken'import { openBrowserWindow } from 'utils/generic'@@ -20,10 +20,11 @@ interface ISSOAuth {callback: (isSuccess: boolean, is2FA: boolean) => voiddontRemember: booleant: (key: string) => string+ provider: string}}-export default function* ssoAuth({ payload: { callback, dontRemember, t } }: ISSOAuth) {+export default function* ssoAuth({ payload: { callback, dontRemember, t, provider } }: ISSOAuth) {const authWindow = openBrowserWindow('', AUTH_WINDOW_WIDTH, AUTH_WINDOW_HEIGHT)if (!authWindow) {@@ -37,7 +38,7 @@ export default function* ssoAuth({ payload: { callback, dontRemember, t } }: ISStry {const {uuid, auth_url: authUrl, expires_in: expiresIn,- } = yield call(generateGoogleAuthURL)+ } = yield call(generateSSOAuthURL, provider)// Set the URL of the authentification browser windowauthWindow.location = authUrldiff --git a/src/redux/sagas/auth/workers/sso_link.ts b/src/redux/sagas/auth/workers/sso_link.tsindex e7beba389..757e07aa9 100644--- a/src/redux/sagas/auth/workers/sso_link.ts+++ b/src/redux/sagas/auth/workers/sso_link.ts@@ -4,7 +4,7 @@ import { authActions } from 'redux/reducers/auth'import { errorsActions } from 'redux/reducers/errors'import { alertsActions } from 'redux/reducers/alerts'import {- linkByGoogleHash, generateGoogleAuthURL, authMe,+ linkByGoogleHash, generateSSOAuthURL, authMe,} from 'api'import { openBrowserWindow } from 'utils/generic'@@ -34,7 +34,7 @@ export default function* ssoLink({ payload: { callback, t } }: ISSOLink) {try {const {uuid, auth_url: authUrl, expires_in: expiresIn,- } = yield call(generateGoogleAuthURL)+ } = yield call(generateSSOAuthURL)// Set the URL of the authentification browser windowauthWindow.location = authUrldiff --git a/src/redux/sagas/auth/workers/sso_unlink.ts b/src/redux/sagas/auth/workers/sso_unlink.tsindex d30ce497f..46fc9929a 100644--- a/src/redux/sagas/auth/workers/sso_unlink.ts+++ b/src/redux/sagas/auth/workers/sso_unlink.ts@@ -8,7 +8,7 @@ import { alertsActions } from 'redux/reducers/alerts'import {unlinkGoogle, authMe,} from 'api'-import { SOCIALISATIONS } from 'redux/constants'+import { SSO_PROVIDERS } from 'redux/constants'export interface ISSOUnlink {payload: {@@ -19,13 +19,13 @@ export interface ISSOUnlink {}export default function* ssoUnlink({ payload: { provider, t, callback } }: ISSOUnlink) {- if (!_includes(_values(SOCIALISATIONS), provider)) {+ if (!_includes(_values(SSO_PROVIDERS), provider)) {callback(false)return}try {- if (provider === SOCIALISATIONS.GOOGLE) {+ if (provider === SSO_PROVIDERS.GOOGLE) {yield call(unlinkGoogle)}diff --git a/src/ui/icons/GithubDark.tsx b/src/ui/icons/GithubDark.tsxnew file mode 100644index 000000000..4a56b621f--- /dev/null+++ b/src/ui/icons/GithubDark.tsx@@ -0,0 +1,20 @@+import React from 'react'+import PropTypes from 'prop-types'++const GithubDarkSVG = ({ className }: {+ className?: string,+}): JSX.Element => (+ <svg className={className} viewBox='0 0 100 100'>+ <path fillRule='evenodd' clipRule='evenodd' d='M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z' fill='#24292f'/>+ </svg>+)++GithubDarkSVG.propTypes = {+ className: PropTypes.string,+}++GithubDarkSVG.defaultProps = {+ className: '',+}++export default GithubDarkSVGdiff --git a/src/ui/icons/GithubLight.tsx b/src/ui/icons/GithubLight.tsxnew file mode 100644index 000000000..449601215--- /dev/null+++ b/src/ui/icons/GithubLight.tsx@@ -0,0 +1,20 @@+import React from 'react'+import PropTypes from 'prop-types'++const GithubLightSVG = ({ className }: {+ className?: string,+}): JSX.Element => (+ <svg className={className} viewBox='0 0 100 100'>+ <path fillRule='evenodd' clipRule='evenodd' d='M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z' fill='#fff'/>+ </svg>+)++GithubLightSVG.propTypes = {+ className: PropTypes.string,+}++GithubLightSVG.defaultProps = {+ className: '',+}++export default GithubLightSVG