在Graphql平台上使用AWS Cognito用户池验证AppSync变异
这是一个非常基本的场景,我想在Graphql Playerd上测试AppSync变异,该变异与API密钥身份验证配合良好 除了API密钥验证之外,我还附加了一个额外的授权提供程序 突变:在Graphql平台上使用AWS Cognito用户池验证AppSync变异,graphql,aws-appsync,Graphql,Aws Appsync,这是一个非常基本的场景,我想在Graphql Playerd上测试AppSync变异,该变异与API密钥身份验证配合良好 除了API密钥验证之外,我还附加了一个额外的授权提供程序 突变: type Mutation { createPitch(gameID: ID!, pitchID: Int!, pitchEvent: PitchInput!): Pitch @aws_api_key predictPitch(userID: String!, gamePitchID: Str
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"
}
我已经尝试了授权
标题,并且与x-api-key
一起使用。
到目前为止,一切都没起作用。我很确定我错过了一点点
{
"error": {
"errors": [
{
"errorType": "UnauthorizedException",
"message": "Valid authorization header not provided."
}
]
}
}
注意:JWT令牌AccessToken
是通过aws cli生成的
aws-cognito-idp-admin-initiate-auth
我必须添加@aws-cognito\u-user\u-pool
类型预测
以及我的变异
type Prediction @aws_cognito_user_pools {
gameID
gamePitchID
}
此外,从Cognito开始,我必须使用idToken,如下所示:
{
"Authorization": "xxxxxxxxxx"
}
请注意
载体
丢失。如果只是授权头,我还使用Cognito用户池对查询进行身份验证,除了查询定义中的指令外,我对查询访问的所有对象(类型)也有相同的指令。在这两种情况下(授权和API密钥),我都尝试过,如果我用查询和查询试图访问的对象定义这两个指令(aws_cognito_user_pools和aws_API_Key),它就会起作用。因此,对于您的情况,您可以尝试添加带有“Pitch”和“prediction”的指令。也许这能给你一些提示。看来我的评论对你很有用。我很高兴这有帮助!这很有帮助,谢谢。我还发现我没有在AppSync中启用“Amazon Cognito用户池”作为授权设置,因此出现了“UnauthorizedException”错误。