这是一个非常基本的场景,我想在Graphql操场上测试一个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 aws cognito-idp admin-initiate-auth
生成的。
发布于 2020-06-11 06:48:21
我不得不在@aws_cognito_user_pools
类型的Prediction
上加上我的突变。
type Prediction @aws_cognito_user_pools {
gameID
gamePitchID
}
此外,从科尼托开始,我不得不像这样使用idToken:
{
"Authorization": "xxxxxxxxxx"
}
请注意,Bearer
丢失了。
https://stackoverflow.com/questions/62311285
复制相似问题