-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}; |
Oops, something went wrong.