Commit e9439901 authored by Matija Obreza's avatar Matija Obreza
Browse files

Store API clientId in applicationConfig.clientId

- needed for Google auth
parent 8cfc2df1
...@@ -37,7 +37,7 @@ const prerenderer = (html, errHtml) => (req, res) => { ...@@ -37,7 +37,7 @@ const prerenderer = (html, errHtml) => (req, res) => {
res.header('Access-Control-Allow-Headers', 'X-Requested-With'); res.header('Access-Control-Allow-Headers', 'X-Requested-With');
const store = createStore(rootReducer, {} as any, applyMiddleware(thunk, routerMiddleware(createMemoryHistory))); const store = createStore(rootReducer, {} as any, applyMiddleware(thunk, routerMiddleware(createMemoryHistory)));
// Only send public data to client // Only send public data to client
store.dispatch(configure({ frontendPath: config.frontendPath, apiUrl: config.apiUrl, googleClientId: config.googleClientId })); store.dispatch(configure({ frontendPath: config.frontendPath, apiUrl: config.apiUrl, googleClientId: config.googleClientId, clientId: config.clientId }));
console.log(`Processing request`, req._parsedOriginalUrl); console.log(`Processing request`, req._parsedOriginalUrl);
const pathname = req._parsedOriginalUrl.pathname; const pathname = req._parsedOriginalUrl.pathname;
......
...@@ -3,11 +3,13 @@ import {CONFIGURE_APPLICATION, SET_LANG} from 'constants/applicationConfig'; ...@@ -3,11 +3,13 @@ import {CONFIGURE_APPLICATION, SET_LANG} from 'constants/applicationConfig';
const INITIAL_STATE: { const INITIAL_STATE: {
clientId: string;
googleClientId: string; googleClientId: string;
apiUrl: string; apiUrl: string;
frontendPath: string; frontendPath: string;
lang: string, lang: string,
} = { } = {
clientId: process.env.CLIENT_ID || '',
googleClientId: process.env.GOOGLE_CLIENT_ID || '', googleClientId: process.env.GOOGLE_CLIENT_ID || '',
apiUrl: process.env.CATALOG_API_URL || 'http://localhost:8080', apiUrl: process.env.CATALOG_API_URL || 'http://localhost:8080',
frontendPath: '', frontendPath: '',
......
...@@ -62,9 +62,13 @@ export class LoginService { ...@@ -62,9 +62,13 @@ export class LoginService {
}); });
} }
public static verifyGoogleToken(googleClientId: string, tokenId) { /**
* @param clientId our OAuth Client ID
* @param tokenId Token returned by Google Auth
*/
public static verifyGoogleToken(clientId: string, tokenId) {
const form = new FormData(); const form = new FormData();
form.append('clientId', googleClientId); form.append('clientId', clientId);
form.append('tokenId', tokenId); form.append('tokenId', tokenId);
return axiosBackend.post(VERIFY_GOOGLE_TOKEN_URL, form) return axiosBackend.post(VERIFY_GOOGLE_TOKEN_URL, form)
......
...@@ -62,8 +62,8 @@ export const verifyGoogleToken = (payload) => { ...@@ -62,8 +62,8 @@ export const verifyGoogleToken = (payload) => {
}; };
export const verifyGoogleTokenRequest = (tokenId) => (dispatch, getState) => { export const verifyGoogleTokenRequest = (tokenId) => (dispatch, getState) => {
const googleClientId = getState().applicationConfig.googleClientId; const clientId = getState().applicationConfig.clientId;
return LoginService.verifyGoogleToken(googleClientId, tokenId) return LoginService.verifyGoogleToken(clientId, tokenId)
.then((data) => { .then((data) => {
saveCookies(data, data.exp * 1000 || new Date().getTime() + data.expires_in * 1000); saveCookies(data, data.exp * 1000 || new Date().getTime() + data.expires_in * 1000);
return dispatch(loginApp(data)); return dispatch(loginApp(data));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment