Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
breaking: refactor AuthContextProvider interfaces, remove token
Browse files Browse the repository at this point in the history
  • Loading branch information
Dara Hayes authored and wtrocki committed Jul 19, 2019
1 parent 6d2d7a1 commit eb5b86d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
11 changes: 6 additions & 5 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -143,7 +142,9 @@ export class Auth {
}

}

export interface AuthContext {
header: any;
token: string;
headers: {
[headerName: string]: any
};
}
8 changes: 5 additions & 3 deletions packages/sync/src/auth/AuthContextProvider.ts
Original file line number Diff line number Diff line change
@@ -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
};
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/sync/src/links/AuthLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/sync/src/links/WebsocketLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit eb5b86d

Please sign in to comment.