From 67ebe0f9f82864a60a75ad75601640cf69d68bbf Mon Sep 17 00:00:00 2001 From: "mati108@gmail.com" <34651529+matbenitez@users.noreply.github.com> Date: Mon, 15 Oct 2018 09:38:54 -0300 Subject: [PATCH 1/4] Changing to correct method name --- client/src/auth/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/auth/index.js b/client/src/auth/index.js index ff0bad4ff..61b90eb6e 100644 --- a/client/src/auth/index.js +++ b/client/src/auth/index.js @@ -11,7 +11,7 @@ import { AUTH_CONFIG } from './Auth0' // create by renaming Auth0.sample.js to A const AUTHENTICATE = gql` mutation authenticate($idToken: String!) { - TeamsModuleAuthenticate(idToken: $idToken) { + teams_Authenticate(idToken: $idToken) { alias authId } @@ -189,8 +189,8 @@ class Auth { Log.info('auth.signinOrCreateAccount data:') Log.info(await data) const user = { - authId: await data.TeamsModuleAuthenticate.authId, - alias: await data.TeamsModuleAuthenticate.alias + authId: await data.teams_Authenticate.authId, + alias: await data.teams_Authenticate.alias } setItem('user', JSON.stringify(user)) if (window.location.href.includes(`callback`)) { From 8914586a45facba03da11fbd349f256c2012a9cd Mon Sep 17 00:00:00 2001 From: "mati108@gmail.com" <34651529+matbenitez@users.noreply.github.com> Date: Mon, 15 Oct 2018 09:43:56 -0300 Subject: [PATCH 2/4] Apollo Client fix for authentication --- client/src/graphql/apollo.js | 57 ++++---------------------------- server/src/createRemoteSchema.js | 3 +- 2 files changed, 8 insertions(+), 52 deletions(-) diff --git a/client/src/graphql/apollo.js b/client/src/graphql/apollo.js index f95da4a88..b036dd862 100644 --- a/client/src/graphql/apollo.js +++ b/client/src/graphql/apollo.js @@ -4,9 +4,6 @@ import { InMemoryCache } from 'apollo-cache-inmemory' import { ApolloLink, Observable } from 'apollo-link' import { onError } from 'apollo-link-error' import { setContext } from 'apollo-link-context' -// import { WebSocketLink } from 'apollo-link-ws' -// import { SubscriptionClient } from 'subscriptions-transport-ws' -// import { getMainDefinition } from 'apollo-utilities' import { getItem } from '../utils/local-storage' @@ -15,47 +12,8 @@ const graphqlEndpoint = ? process.env.PROD_GRAPHQL : process.env.DEV_GRAPHQL -/* -const wsUri = graphqlEndpoint.replace(/^http/, 'ws') - -const globalVar = - typeof global !== 'undefined' - ? global - : typeof window !== 'undefined' - ? window - : {} - -const webSocketImpl = globalVar.WebSocket || globalVar.MozWebSocket - -const wsClient = new SubscriptionClient( - wsUri, - { - reconnect: true - }, - webSocketImpl -) - -wsClient.onDisconnected(() => { - // console.log('onDisconnected') -}) - -wsClient.onReconnected(() => { - // console.log('onReconnected') -}) -*/ const httpLink = new HttpLink({ uri: graphqlEndpoint }) -/* -const link = split( - ({ query }) => { - const { kind, operation } = getMainDefinition(query) - return kind === 'OperationDefinition' && operation === 'subscription' - }, - // new WebSocketLink(wsClient), - httpLink -) -*/ - const authRetryLink = onError( ({ graphQLErrors, networkError, operation, forward }) => { if (graphQLErrors) { @@ -96,16 +54,15 @@ const authRetryLink = onError( } ) -const authLink = setContext(async (_, { headers }) => { +const authLink = setContext((_, { headers }) => { // get the authentication token from local storage if it exists - await getItem('access_token').then(token => { - return { - headers: { - ...headers, - Authorization: token ? `Bearer ${token}` : `` - } + const token = localStorage.getItem('access_token') + return { + headers: { + ...headers, + Authorization: token ? `Bearer ${token}` : `` } - }) + } }) const cache = new InMemoryCache().restore(window.__APOLLO_STATE__) diff --git a/server/src/createRemoteSchema.js b/server/src/createRemoteSchema.js index 518ba6cf0..f131c14d2 100644 --- a/server/src/createRemoteSchema.js +++ b/server/src/createRemoteSchema.js @@ -22,11 +22,10 @@ export const createRemoteSchema = async (uri) => { const http = makeDatabaseServiceLink() const authLink = setContext((request, previousContext) => { - console.log(previousContext.graphqlContext.headers) return ( { headers: { - Authorization: previousContext.graphqlContext.headers.Authorization ? previousContext.graphqlContext.headers.Authorization : '' + Authorization: previousContext.graphqlContext.headers.authorization ? previousContext.graphqlContext.headers.authorization : '' } } ) From 7ddc4cd543a48b12f1352fd6d87db9173d611695 Mon Sep 17 00:00:00 2001 From: "mati108@gmail.com" <34651529+matbenitez@users.noreply.github.com> Date: Mon, 15 Oct 2018 09:44:11 -0300 Subject: [PATCH 3/4] Adding Keys Module configuration --- client/src/App.js | 4 ++-- client/src/views/header/index.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 08d9a2fb0..3c17461ba 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -45,8 +45,8 @@ export const MasterApp = () => ( /> } + path='/keys' + render={props => } /> const TeamsLink = props => const UsersLink = props => +const KeyVaultLink = props => const DashboardLink = props => const HomeLink = props => @@ -111,6 +112,9 @@ class Header extends Component { + From f80cd2d543a21211650e1d17e737d04c42b9a151 Mon Sep 17 00:00:00 2001 From: "mati108@gmail.com" <34651529+matbenitez@users.noreply.github.com> Date: Mon, 15 Oct 2018 10:09:10 -0300 Subject: [PATCH 4/4] Fixing authentication workflow --- client/src/auth/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/auth/index.js b/client/src/auth/index.js index 61b90eb6e..47daf01db 100644 --- a/client/src/auth/index.js +++ b/client/src/auth/index.js @@ -182,21 +182,21 @@ class Auth { async signinOrCreateAccount ({ accessToken, idToken, expiresAt }) { try { - const data = await client.mutate({ + const response = await client.mutate({ mutation: AUTHENTICATE, variables: { idToken } }) Log.info('auth.signinOrCreateAccount data:') - Log.info(await data) + Log.info(response) const user = { - authId: await data.teams_Authenticate.authId, - alias: await data.teams_Authenticate.alias + authId: response.data.teams_Authenticate.authId, + alias: response.data.teams_Authenticate.alias } setItem('user', JSON.stringify(user)) if (window.location.href.includes(`callback`)) { - window.location.href = '/dashboard' + window.location.href = '/' } - return data + return response.data } catch (err) { return console.log('Sign in or create account error: ', err) }