title: Verifying a Google ID Token in Django
body: <p>I have a React Native Android app which uses Google Sign-In to get the users profile and email information and produces an ID token (using <a href="https://github.com/react-native-community/google-signin" rel="nofollow noreferrer">https://github.com/react-native-community/google-signin</a>). The sign in works and I am displaying the users name, email, photo etc on the app.</p>
  
  <p>I am then trying to send the ID token to a Django + DRF backend so that it can be validated and a relevant user account created and/or logged in. I am following the instructions here: <a href="https://developers.google.com/identity/sign-in/web/backend-auth" rel="nofollow noreferrer">https://developers.google.com/identity/sign-in/web/backend-auth</a></p>
  
  <p>Here is my code for the endpoint. For now I have just been copying the ID token produced by the app and sending it to the backend via Postman.</p>
  
  <pre><code>class GoogleView(APIView):
      def post(self, request):
          token = {'idToken': request.data.get('idToken')}
          print(token)
  
          try:
              idinfo = id_token.verify_oauth2_token(token, requests.Request(), MY_APP_CLIENT_ID)
              print(idinfo)
  
              if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
                  raise ValueError('Wrong issuer.')
  
              return Response(idinfo)
          except ValueError:
              # Invalid token
              content = {'message': 'Invalid token'}
              return Response(content)
  </code></pre>
  
  <p>When I send the POST request, the first print statement runs confirming that the token was received correctly. However the second print statement never runs and I always get the 'Invalid token' response. So, I believe verify_oauth2_token is failing somehow but it doesn't give me anymore information.</p>
  
  <p>I have never used Google Sign In before so it's entirely possible I've missed something obvious. Would appreciate any help!</p>