From eb5b86dff41731a5b66eb3bd8d17f415163baf75 Mon Sep 17 00:00:00 2001 From: Dara Hayes Date: Fri, 19 Jul 2019 12:00:23 +0100 Subject: [PATCH] breaking: refactor AuthContextProvider interfaces, remove token --- packages/auth/src/Auth.ts | 11 ++++++----- packages/sync/src/auth/AuthContextProvider.ts | 8 +++++--- packages/sync/src/links/AuthLink.ts | 4 ++-- packages/sync/src/links/WebsocketLink.ts | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/auth/src/Auth.ts b/packages/auth/src/Auth.ts index aa98127d..fac82dc2 100644 --- a/packages/auth/src/Auth.ts +++ b/packages/auth/src/Auth.ts @@ -126,10 +126,9 @@ export class Auth { tokenUpdate.success(() => { if (this.auth.token) { resolve({ - header: { + headers: { "Authorization": "Bearer " + this.auth.token - }, - token: this.auth.token + } }); } else { reject("No keycloak token available"); @@ -143,7 +142,9 @@ export class Auth { } } + export interface AuthContext { - header: any; - token: string; + headers: { + [headerName: string]: any + }; } diff --git a/packages/sync/src/auth/AuthContextProvider.ts b/packages/sync/src/auth/AuthContextProvider.ts index 0a71d4db..413c0151 100644 --- a/packages/sync/src/auth/AuthContextProvider.ts +++ b/packages/sync/src/auth/AuthContextProvider.ts @@ -1,9 +1,11 @@ /** - * Contains header and auth token information that can be supplied to graphql requests + * Contains header information that can be provided in GraphQL requests + * and in connectionParams for websocket connections */ export interface AuthContext { - header: any; - token: string; + headers: { + [headerName: string]: any + }; } /** diff --git a/packages/sync/src/links/AuthLink.ts b/packages/sync/src/links/AuthLink.ts index 821c0e98..3cebd4c9 100644 --- a/packages/sync/src/links/AuthLink.ts +++ b/packages/sync/src/links/AuthLink.ts @@ -5,9 +5,9 @@ import { DataSyncConfig } from "../config/DataSyncConfig"; export const createAuthLink = (config: DataSyncConfig): ApolloLink => { const asyncHeadersLink = setContext(async (operation, previousContext) => { if (config.authContextProvider) { - const { header } = await config.authContextProvider(); + const { headers } = await config.authContextProvider(); return { - headers: header + headers }; } }); diff --git a/packages/sync/src/links/WebsocketLink.ts b/packages/sync/src/links/WebsocketLink.ts index 8aa6db7c..a59570ae 100644 --- a/packages/sync/src/links/WebsocketLink.ts +++ b/packages/sync/src/links/WebsocketLink.ts @@ -9,8 +9,8 @@ export const defaultWebSocketLink = (userOptions: DataSyncConfig, config: WebSoc // Params that can be used to send authentication token etc. connectionParams: async () => { if (userOptions.authContextProvider) { - const { header } = await userOptions.authContextProvider(); - return { ...header }; + const { headers } = await userOptions.authContextProvider(); + return headers; } }, connectionCallback: options.connectionCallback,