Merge pull request #8 from AAVikings/master

Baseline for authentication workflow
This commit is contained in:
z@tOr authored and GitHub committed 2018-10-15 10:20:24 -03:00
commit bf5bc3f981
5 files changed
+21 -62

No files matched your search

+2 -2
View File
@@ -45,8 +45,8 @@ export const MasterApp = () => (
/>
<Route
exact
path='/key-vault'
render={props => <KeyVault {...props} auth={auth} />}
path='/keys'
render={props => <KeyVault {...props} />}
/>
<Route
exact
+7 -7
View File
@@ -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
}
@@ -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.TeamsModuleAuthenticate.authId,
alias: await data.TeamsModuleAuthenticate.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)
}
+7 -50
View File
@@ -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__)
+4 -1
View File
@@ -24,7 +24,7 @@ import AALogo from '../../assets/advanced-algos/aa-logo-dark.svg'
const AboutLink = props => <Link to='/about' {...props} />
const UsersLink = props => <Link to='/users' {...props} />
const TeamsLink = props => <Link to='/teams' {...props} />
const KeyVaultLink = props => <Link to='/key-vault' {...props} />
const KeyVaultLink = props => <Link to='/keys' {...props} />
const DashboardLink = props => <Link to='/dashboard' {...props} />
const HomeLink = props => <Link to='/' {...props} />
@@ -114,6 +114,9 @@ class Header extends Component {
<Button component={KeyVaultLink} color='inherit'>
Key Vault
</Button>
<Button component={KeyVaultLink} color='inherit'>
API Keys
</Button>
<Button component={AboutLink} color='inherit'>
About
</Button>
+1 -2
View File
@@ -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 : ''
}
}
)