ait*_*han 3 graphql aws-appsync
一个非常基本的场景,我想在 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
}
Run Code Online (Sandbox Code Playgroud)
predictPitch
在 graphql 游乐场上调用突变:
mutation PredictPitch($prediction:PredictionInput) {
predictPitch(userID: "12345", gamePitchID: "29fb2xx-xxxxx-xxxxx-1",
prediction: $prediction ) {
gameID
gamePitchID
}
}
Run Code Online (Sandbox Code Playgroud)
查询变量:
{
"prediction": {
"gameID": "29",
"hitterGuess": "Miss",
"pitcherGuess": "Fastball"
}
}
Run Code Online (Sandbox Code Playgroud)
标题:
{
"X-API-KEY": "da2-o6fs2lq47vbehexxxxxxxx",
"Authorization": "Bearer xxxx-the-pretty-long-jwt-token-from-cognito login"
}
Run Code Online (Sandbox Code Playgroud)
我单独尝试过Authorization
header 以及与x-api-key
. 到目前为止没有任何效果。我很确定我错过了一点点。
{
"error": {
"errors": [
{
"errorType": "UnauthorizedException",
"message": "Valid authorization header not provided."
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
注意: JWT 令牌AccessToken
是通过 aws-cli 生成的
aws cognito-idp admin-initiate-auth
。
ait*_*han 11
我必须在突变的同时添加@aws_cognito_user_pools
类型。Prediction
type Prediction @aws_cognito_user_pools {
gameID
gamePitchID
}
Run Code Online (Sandbox Code Playgroud)
另外,从 Cognito 中我必须像这样使用 idToken:
{
"Authorization": "xxxxxxxxxx"
}
Run Code Online (Sandbox Code Playgroud)
请注意Bearer
缺少。
归档时间: |
|
查看次数: |
5856 次 |
最近记录: |