如何使用 Firebase Auth 作为 OIDC 向 Amplify GraphQL 发出经过身份验证的请求?

cor*_*san 6 javascript amazon-cognito react-native firebase-authentication aws-amplify

我需要有关设置 Firebase Auth + Amplify GraphQL 的帮助。我正在尝试使用联合签名securetoken.google.com/PROJECT-ID作为提供者登录,它似乎可以正常登录,因为当我打电话时Auth.currentAuthenticatedUser()我得到了令牌,而在侦听集线器"signIn"事件时我得到了令牌。我的问题是向我的 GraphQL API 发出经过身份验证的请求。

const signIn = async () => {
  try {
    // already logged in using firebase so I just need to get the token from the current user
    const tokenResult = await currentUser?.getIdTokenResult()
    await Auth.federatedSignIn('securetoken.google.com/PROJECT-ID', {
      token: tokenResult?.token,
    })
    const res = await Auth.currentAuthenticatedUser()
    console.log('token', res.token) // eyjhxxxxxxxxxx...
  } catch (error) {
    // ...
  }
}
Run Code Online (Sandbox Code Playgroud)
const client = new AWSAppSyncClient({
  url: AppSyncConfig.aws_appsync_graphqlEndpoint,
  region: AppSyncConfig.aws_appsync_region,
  auth: {
    type: AppSyncConfig.aws_appsync_authenticationType,
    jwtToken: () => getToken(),
  },
})

const getToken = async () => {
  const token = await Cache.getItem('@accessToken')
  return token
}
Run Code Online (Sandbox Code Playgroud)

打电话时Auth.currentSession()我得到"No current user". 此外,当我尝试获取数据时,我确实在 Authorization 标头中看到了令牌。

Noo*_*ani 0

尝试删除 aws-exports.js 中的 cookie 存储配置可能会解决该问题。也许这对你有帮助。

更多讨论请参见Link-1Link-2