在 Graphql 操场上使用 AWS Cognito 用户池验证 AppSync 突变
Authenticating AppSync mutation using AWS Cognito User pool on Graphql playground
一个非常基本的场景,我想在 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"
}
}
Headers:
{
"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 令牌 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 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"
}
}
Headers:
{
"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 令牌 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
。