Setting up Firebase for authentication on AWS AppSync

Viewed 29

I have Firebase running as an AuthN/Identity provider with an email sign up option and sign in with google.

Currently trying out to make a POC on AWS Amplify, without having to migrate users onto Cognito.

So following the docs I have added the following decorator on the graphql model:

type SampleModel @model @auth(rules: [{ allow: private, provider: oidc}]) {
  id: ID!
} 

And on doing amplify push provisioned the issuer url in the format of

https://securetoken.google.com/<PROJECT-ID>

It seems to have set it up correctly, looking into AppSync it now uses both API token and OpenID Connect as auth methods.

However, I am getting 401 on all requests, I tried doing the following in the app itself:

Amplify.configure({
  ...awsconfig,
  API: {
    graphql_headers: async () => {
      const token = await firebase.auth().currentUser?.getIdToken();

      return {
        authorization: `Bearer ${token}`,
      };
    },
  },

to supposedly pass in the header, however that did not work out, initially I thought that maybe I am misusing this lambda, and I am pretty sure I am, but I also tried manually running the query in AppSync's web interface and keep getting unathourized.

I also tried setting the issuer url as

https://securetoken.google.com/

and setting the <PROJECT-ID> from Firebase as the client-id, however that also did not workout.

Referencing this question over here https://stackoverflow.com/a/65136446/15320139 I checked whether or not https://securetoken.google.com/<PROJECT-ID>//.well-known/openid-configuration returns a config and it indeed does.

  • Any suggestions on what should I change in AppSync to make this work, and if this can actually work?
  • Advice on how to correctly pass the token from the RN app would also be highly appreciated!

Update

Removing setting Client ID as blank in AppSync and only going with https://securetoken.google.com/<PROJECT-ID>/ did the trick for running queries inside AppSync, but still no clue how to pass the token in the code.

0 Answers
Related