serverless-appsync/serverless-appsync-simulator

ApiKey not working

MarkusLC opened this issue ยท 10 comments

Describe the bug
Affter setting the apikey under the cunstom configuration of appsync-simulator, i am sitll getting "UnauthorizedException: Invalid API key"

Thank you @MarkusLC for reporting.
Can you share your setup and how you are trying to access the API?

Of course!

appsync-simulator:
apiKey: ${file(./stages/config.${self:provider.stage}.json):API-KEY}
watch: false
lambda:
loadLocalEnv: true

I am trying to make a query that use ApiKey authentication.

@MarkusLC Thank you for your feedback

I see you are using the GraphiQL. Unfortunately, GraphiQL hardcodes the API key.

Also see Issue #36

For testing locally, you can either use da2-fakeApiId123456 or you can use another GraphQL client such as insomnia or altair

@MarkusLC Thank you for your feedback

I see you are using the GraphiQL. Unfortunately, GraphiQL hardcodes the API key.

Also see Issue #36

For testing locally, you can either use da2-fakeApiId123456 or you can use another GraphQL client such as insomnia or altair

@bboure I am trying to use altair like you suggested.

I am having hard time finding the right format to give the apiKey and value. Any suggestions?

Screenshot (3610)

@appdatasoft header name should be x-api-key (not API_KEY)

@appdatasoft header name should be x-api-key (not API_KEY)

@skix123 Thank you! I tried with both
{"headers":
{"x-api-key":"da2-fakeApiId123456"}}

{"headers":
{"x-api-key":"0123456789"}}

I am getting the following in results. What am I doing wrong
I am trying to connect to serverless-appsync-simulator
AppSync Simulator: AppSync endpoint: http://192.168.254.13:20002/graphql
AppSync Simulator: GraphiQl: http://192.168.254.13:20002
offline: Starting Offline: dev/us-east-1.
offline: Offline [http for lambda] listening on http://localhost:3002
offline: Function names exposed for local invocation by aws-sdk:

{
"error": {},
"text": "<!doctype html><html lang="en"><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>Amplify GraphiQL Explorer</title><link href="/static/css/2.c8e0a9fd.chunk.css" rel="stylesheet"><link href="/static/css/main.006d8c2f.chunk.css" rel="stylesheet">You need to enable JavaScript to run this app.<div id="root"><script>!function(e){function r(r){for(var n,i,a=r[0],l=r[1],c=r[2],p=0,s=[];p<a.length;p++)i=a[p],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&s.push(o[i][0]),o[i]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(f&&f(r);s.length;)s.shift()();return u.push.apply(u,c||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,a=1;a<t.length;a++){var l=t[a];0!==o[l]&&(n=!1)}n&&(u.splice(r--,1),e=i(i.s=t[0]))}return e}var n={},o={1:0},u=[];function i(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,i),t.l=!0,t.exports}i.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,a=document.createElement("script");a.charset="utf-8",a.timeout=120,i.nc&&a.setAttribute("nonce",i.nc),a.src=function(e){return i.p+"static/js/"+({}[e]||e)+"."+{3:"5711cfe3"}[e]+".chunk.js"}(e);var l=new Error;u=function(r){a.onerror=a.onload=null,clearTimeout(c);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;l.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",l.name="ChunkLoadError",l.type=n,l.request=u,t1}o[e]=void 0}};var c=setTimeout((function(){u({type:"timeout",target:a})}),12e4);a.onerror=a.onload=u,document.head.appendChild(a)}return Promise.all(r)},i.m=e,i.c=n,i.d=function(e,r,t){i.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,r){if(1&r&&(e=i(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(i.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)i.d(t,n,function(r){return e[r]}.bind(null,n));return t},i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,"a",r),r},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.p="/",i.oe=function(e){throw console.error(e),e};var a=this["webpackJsonpamplify-graphiql-explorer"]=this["webpackJsonpamplify-graphiql-explorer"]||[],l=a.push.bind(a);a.push=r,a=a.slice();for(var c=0;c<a.length;c++)r(a[c]);var f=l;t()}([])</script><script src="/static/js/2.bfe1bf03.chunk.js"></script><script src="/static/js/main.523ef268.chunk.js"></script>"
}
Screen Shot 2021-04-10 at 5 24 51 AM

@MarkusLC Thank you for your feedback

I see you are using the GraphiQL. Unfortunately, GraphiQL hardcodes the API key.

Also see Issue #36

For testing locally, you can either use da2-fakeApiId123456 or you can use another GraphQL client such as insomnia or altair

I've just had the same issue, I solved using the hardcoded key on my serverless.yaml as indicated here
I think this is something worthy to be in the doc, even though being amazons source code problem.