【发布时间】:2020-09-30 07:46:01
【问题描述】:
一个非常基本的场景,我想在 Graphql Playground 上测试 AppSync 突变,该突变在 API 密钥身份验证中运行良好。
除了 API 密钥身份验证之外,我还附加了一个额外的授权提供程序。
变异:
type Mutation {
createPitch(gameID: ID!, pitchID: Int!, pitchEvent: PitchInput!): Pitch
@aws_api_key
predictPitch(userID: String!, gamePitchID: String!, prediction: PredictionInput): Prediction
@aws_cognito_user_pools
}
在 graphql 操场上调用 predictPitch 突变:
mutation PredictPitch($prediction:PredictionInput) {
predictPitch(userID: "12345", gamePitchID: "29fb2xx-xxxxx-xxxxx-1",
prediction: $prediction ) {
gameID
gamePitchID
}
}
查询变量:
{
"prediction": {
"gameID": "29",
"hitterGuess": "Miss",
"pitcherGuess": "Fastball"
}
}
标题:
{
"X-API-KEY": "da2-o6fs2lq47vbehexxxxxxxx",
"Authorization": "Bearer xxxx-the-pretty-long-jwt-token-from-cognito login"
}
我已经尝试单独使用Authorization 标头并与x-api-key 结合使用。
到目前为止没有任何效果。我很确定我错过了一点点。
{
"error": {
"errors": [
{
"errorType": "UnauthorizedException",
"message": "Valid authorization header not provided."
}
]
}
}
注意: JWT 令牌 AccessToken 是通过 aws-cli 生成的
aws cognito-idp admin-initiate-auth.
【问题讨论】:
-
在只有 Authorization 标头的情况下,我还使用 Cognito 用户池对查询进行身份验证,除了查询定义中的指令之外,我对所有对象(类型)也有相同的指令查询正在访问。在这两种情况下(授权和 API 密钥),我尝试过,如果我用查询和查询试图访问的对象定义两个指令(aws_cognito_user_pools 和 aws_api_key),它就可以工作。因此,对于您的情况,您可以尝试使用“Pitch”和“Pridiction”添加指令。也许这可以给你一些提示。
标签: graphql aws-appsync