gpt4 book ai didi

graphql - 在 Graphql Playground 上使用 AWS Cognito 用户池验证 AppSync 突变

转载 作者:行者123 更新时间:2023-12-05 08:30:52 25 4
gpt4 key购买 nike

一个非常基本的场景,我想在 Graphql playground 上测试 AppSync 突变,它在 API key 身份验证下运行良好。

除了 API key 身份验证之外,我还附加了一个额外的授权提供程序。

screenshot for additional authorization

突变:

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 Playground 上调用 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 header 并与 x-api-key 结合使用。到目前为止没有任何效果。我很确定我错过了一点点。

{
"error": {
"errors": [
{
"errorType": "UnauthorizedException",
"message": "Valid authorization header not provided."
}
]
}
}

注意: JWT token AccessToken 是通过 aws-cli 生成的aws cognito-idp admin-initiate-auth

最佳答案

我必须在 Prediction 类型上添加 @aws_cognito_user_pools 以及我的突变。

type Prediction @aws_cognito_user_pools {
gameID
gamePitchID
}

此外,在 Cognito 中,我必须像这样使用 idToken:

{
"Authorization": "xxxxxxxxxx"
}

请注意 Bearer 丢失。

关于graphql - 在 Graphql Playground 上使用 AWS Cognito 用户池验证 AppSync 突变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62311285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com