Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-appsync-auth-link: replace aws-sdk dependency with @aws-sdk alternatives #625

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/aws-appsync-auth-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"test-watch": "jest --watch"
},
"dependencies": {
"aws-sdk": "^2.814.0",
"@aws-crypto/sha256-universal": "^1.1.0",
"@aws-sdk/signature-v4": "^3.6.1",
"@aws-sdk/types": "^3.6.1",
"debug": "2.6.9"
},
"devDependencies": {
Expand Down
12 changes: 7 additions & 5 deletions packages/aws-appsync-auth-link/src/auth-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
* Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { Sha256 } from '@aws-crypto/sha256-universal';
import { SignatureV4 } from '@aws-sdk/signature-v4';
import { ApolloLink, Observable } from '@apollo/client';
import { print } from 'graphql/language/printer';

import { Signer } from './signer';
import * as Url from 'url';

import { userAgent } from "./platform";
import { Credentials, CredentialsOptions } from 'aws-sdk/lib/credentials';
import { Credentials, CredentialProvider, HttpRequest } from '@aws-sdk/types';

const packageInfo = require("../package.json");

Expand Down Expand Up @@ -88,12 +89,13 @@ const iamBasedAuth = async ({ credentials, region, url }, operation, forward) =>

const { host, path } = Url.parse(url);

const formatted = {
const formatted: HttpRequest = {
...formatAsRequest(operation, {}),
service, region, url, host, path
};

const { headers } = Signer.sign(formatted, { access_key: accessKeyId, secret_key: secretAccessKey, session_token: sessionToken });
const signatureV4 = new SignatureV4({ credentials: { accessKeyId, secretAccessKey, sessionToken }, region, service, sha256: Sha256 });
const { headers } = await signatureV4.sign(formatted);

operation.setContext({
...origContext,
Expand All @@ -113,7 +115,7 @@ type KeysWithType<O, T> = {
type AuthOptionsNone = { type: AUTH_TYPE.NONE };
type AuthOptionsIAM = {
type: KeysWithType<typeof AUTH_TYPE, AUTH_TYPE.AWS_IAM>,
credentials: (() => Credentials | CredentialsOptions | Promise<Credentials | CredentialsOptions | null>) | Credentials | CredentialsOptions | null,
credentials: (() => Credentials | CredentialProvider) | Credentials | null,
};
type AuthOptionsApiKey = {
type: KeysWithType<typeof AUTH_TYPE, AUTH_TYPE.API_KEY>,
Expand Down
1 change: 0 additions & 1 deletion packages/aws-appsync-auth-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ import { AuthLink, AuthOptions, AUTH_TYPE, USER_AGENT_HEADER, USER_AGENT } from
export const createAuthLink = ({ url, region, auth }: { url: string, region: string, auth: AuthOptions }) => new AuthLink({ url, region, auth });

export { AuthLink, AuthOptions, AUTH_TYPE, USER_AGENT_HEADER, USER_AGENT };
export { Signer } from './signer';
5 changes: 0 additions & 5 deletions packages/aws-appsync-auth-link/src/signer/index.ts

This file was deleted.

280 changes: 0 additions & 280 deletions packages/aws-appsync-auth-link/src/signer/signer.ts

This file was deleted.