serverless-appsync-plugin icon indicating copy to clipboard operation
serverless-appsync-plugin copied to clipboard

Support authenticationType: API_KEY

Open DaleLJefferson opened this issue 8 years ago • 12 comments

I'm attempting to use API_KEY authentication and I can't work out the correct format. Looking at the code it would seem that a userPoolConfig is always required.

appSync:
    authenticationType: API_KEY
.request("AppSync", "updateGraphqlApi", {
        apiId: resolvedConfig.apiId,
        authenticationType: resolvedConfig.authenticationType,
        name: resolvedConfig.name,
        userPoolConfig: {
          awsRegion: resolvedConfig.region,
          defaultAction: resolvedConfig.userPoolConfig.defaultAction, // userPoolConfig is null NPE
          userPoolId: resolvedConfig.userPoolConfig.userPoolId
    }
})

DaleLJefferson avatar Feb 15 '18 09:02 DaleLJefferson

@DaleJefferson API_KEY is not a recommended way to authenticate the GraphQL API but supported by AWS AppSync. We currently only support Cognito User Pool Authentication but can look into supporting API_KEY in coming days. If you are interested, we can work together and add that feature in ;)

sid88in avatar Feb 15 '18 13:02 sid88in

I'm using API_KEY while in development. It seems to all work if you make a small change.

.request("AppSync", "updateGraphqlApi", {
        apiId: resolvedConfig.apiId,
        authenticationType: resolvedConfig.authenticationType,
        name: resolvedConfig.name,
        userPoolConfig: resolvedConfig.userPoolConfig ? {
          awsRegion: resolvedConfig.region,
          defaultAction: resolvedConfig.userPoolConfig.defaultAction,
          userPoolId: resolvedConfig.userPoolConfig.userPoolId
        } : undefined
})

It's not a very robust solution but it's allowing me to continue evaluating serverless-appsync-plugin

Great project btw, if we decide to using this project I would love to contribute 👍

DaleLJefferson avatar Feb 19 '18 12:02 DaleLJefferson

Hey @DaleJefferson thanks for using the plugin. I have started a thread on API_KEY here: https://github.com/sid88in/serverless-appsync-plugin/pull/51 basically the setup should create the key for you. And btw always looking forward to more contributions @DaleJefferson ;)

sid88in avatar Feb 19 '18 15:02 sid88in

Ha, just ran into this myself! Thanks @DaleJefferson for quick patch.

shortjared avatar Feb 19 '18 18:02 shortjared

Thanks for the API_Key support, appreciated that for development.

For production, we're interested in using an AWS_IAM from our Lambda functions - is there a timeline or road map planned for supporting AWS_IAM as an authenticationType?

jwondrusch avatar Feb 21 '18 21:02 jwondrusch

@jwondrusch we can create the roadmap together ;) If you are interested we can work together to add it! Maybe you can propose a design and we can review? Feel free to ping me on twitter @sidg_sid

sid88in avatar Feb 21 '18 22:02 sid88in

@sid88in Sure, I'll reach out on twitter after the weekend.

jwondrusch avatar Feb 21 '18 23:02 jwondrusch

API_KEY is awesome for development. I am certainly interested in this feature as well :-)

maziarz avatar Feb 28 '18 05:02 maziarz

hey everyone! update/create api key functionality is now available ;) 🎉 Thanks for your inputs! Let me know if anything is missing. @jwondrusch is going to work on adding custom IAM Auth in coming days! stay tuned 🔈

sid88in avatar Mar 03 '18 00:03 sid88in

@sid88in, so awesome! Thanks for adding this feature..

maziarz avatar Mar 03 '18 14:03 maziarz

This is not completed yet.

Here is one error case:

  1. deploy-appsync by choosing AMAZON_COGNITO_USER_POOLS
  2. I want to use API_KEY method later, so I've changed some config and did update-appsync It pops up error.

So I've checked the code. You didn't call createAPIKey() if it has no API_KEY yet when the user update existing AppSync endpoint.

updateAPIKey API is used to change just expiration date of existing API key. so I think you should call createAPIKey API and we don't have to set apiKey in serverless.yml

Pls fix this issue Thanks

harleyguru avatar Apr 25 '18 09:04 harleyguru

Hi, Im also planning to use AWS_IAM for authentication but will use the API_KEY during development.

It appears that if using API_KEY, it still requires a valid definition in serverless.yml for the userPoolConfig. If you remove it, it complains about "Cannot read property 'defaultAction' of undefined"

I'll see if I can provide some guidance on that as well as how to implement IAM so we get that working as well.

fellars avatar May 18 '18 22:05 fellars