Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Using auth0 to integrate with API Gateway

Hi,

Added a simple node.js "Hello World" gcp functions using the link below.

https://cloud.google.com/api-gateway/docs/secure-traffic-console

  1. After deploying, the Url works: https://australia-southeast1-terraform-anam.cloudfunctions.net/function-name

  2. Created an api gateway, added config file.
    If there is no authentication, the gateway url works: https://gateway-name-1oa10ql7.ts.gateway.dev/hello

  3. I followed this to use Auth0 to authenticate users:
    https://cloud.google.com/endpoints/docs/openapi/authenticating-users-auth0

Once I added the auth0 Security tags, I get the error:

{"code":401,"message":"Jwt is missing"}

If I do curl in GCP console, i get the error:

 

 

 

{"code":401,"message":"Jwt issuer is not configured"}

 

 

 



I didnt change anything in the GCP Hello world functions, didnt make any changes in auth0. There is a point in this link which says to add authentication code to my application. Am I missing this or is it something else?

Appreciate any help!

Thanks,

Anam

@christianpaula 

 

 

 

 

# openapi2-functions.yaml
swagger: '2.0'
info:
  title: api-name
  description: Sample API on API Gateway with a Google Cloud Functions backend
  version: 1.0.0
schemes:
  - https
produces:
  - application/json
paths:
  /hello:
    get:
      summary: Greet a user
      operationId: hello
      x-google-backend:
        address: https://australia-southeast1-terraform-anam.cloudfunctions.net/function-name
      responses:
        '200':
          description: A successful response
          schema:
            type: string
      security:
      - auth0_jwt: []  
# securityDefinitions:
#       # This section configures basic authentication with an API key.
#   api_key:
#     type: "apiKey"
#     name: "key"
#     in: "query"
      
securityDefinitions:
  auth0_jwt:
    authorizationUrl: "https://paidright.au.auth0.com/authorize"
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "https://paidright.au.auth0.com"
    x-google-jwks_uri: "https://paidright.au.auth0.com/.well-known/jwks.json"
    x-google-audiences: "https://this_api_gateway"

 

 

 

@christianpaula

can you help?

0 1 966
1 REPLY 1

Hi @anamul321,

Welcome back to Google Cloud Community!

To integrate Auth0 with API Gateway, you need to:

  1. Configure your API Gateway to trust Auth0 as a JWT issuer. You can do this by adding the following configuration to your OpenAPI specification:
YAML
securityDefinitions:
  auth0_jwt:
    authorizationUrl: "https://paidright.au.auth0.com/authorize"
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "https://paidright.au.auth0.com"
    x-google-jwks_uri: "https://paidright.au.auth0.com/.well-known/jwks.json"
    x-google-audiences: "https://this_api_gateway"
  1. Make sure that your client application is sending a valid JWT token in the request. You can use the Auth0 Auth0.js library to generate JWT tokens for your users.

  2. Make sure that the issuer URL in your API Gateway configuration matches the issuer URL in the Auth0 dashboard.

  3. Make sure that the audience in your API Gateway configuration matches the audience in your Auth0 application.

  4. Make sure that the JWT token is being sent in the correct HTTP header. The JWT token should be sent in the Authorization header with the Bearer scheme.

  5. You can use a tool like JWT.io to debug JWT tokens.

Top Labels in this Space