Google Cloud Endpoints + Firebase Auth: method_info is not set

后端 未结 4 1730
一整个雨季
一整个雨季 2021-01-15 17:15

So I am running the sample code provided by Google:

package com.neat.backend;
/**
 * An endpoint class we are exposing
 */
@Api(
        name = \"myApi\",
           


        
相关标签:
4条回答
  • 2021-01-15 17:32

    It took me a while and a bit of debugging to realize that the filter that is supposed to inject method_info was not being fired.

    I could fix it by modifying the mapping in web.xml adding the following dispatcher tags:

    <filter-mapping>
        <filter-name>endpoints-api-configuration</filter-name>
        <servlet-name>EndpointsServlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    
    0 讨论(0)
  • 2021-01-15 17:32

    I got the same error message, and eventually tracked it down to making a request with a trailing / in the URL where my API did not specify one. The trailing slash only causes an error for calls that provide an authorization token.

    Apparently ControlFilter (and therefore also GoogleAppEngineControlFilter) did not recognize it as a valid endpoint and therefore did not bother attaching method_info to the request. But then EndpointsServlet thought it was valid and tried to authenticate without all the needed info!

    The fix was easy: remove the trailing slash from the URL in my request. Tracking down the problem, however, was not! I see this was not your problem, but maybe this answer will help someone else.

    0 讨论(0)
  • 2021-01-15 17:41

    @Kevendra's answer highlights that this issue can be caused if an openapi.json file is missing a reference to the endpoint API method. Firebase may be using this to reference and discover the API method.

    From the Google OpenAPI Overview:

    Basic structure of an OpenAPI document:

    An OpenAPI document describes the surface of your REST API, and defines information such as:

    The name and description of the API. The individual endpoints (paths) in the API. How the callers are authenticated.

    Follow these steps to regenerate and deploy the openapi.json file:


    generate:

    $ mvn clean package endpoints-framework:openApiDocs -DskipTests
    
    • mvn clean - run a Maven goal to clean your project. package - compile and package it
    • endpoints-framework:openApiDocs generate OpenAPI documents. This will generate the openapi.json file at the location: target/openapi-docs/openapi.json- see generating and deploying an api configuration.
    • -DskipTests skips running any tests, to avoid any test failure due to the openapi.json not yet being generated

    deploy:

    (As a precaution you can first validate the project ID returned from the following command to make sure that the service isn't created in the wrong project - gcloud config list project)

      $ gcloud endpoints services deploy target/openapi-docs/openapi.json
    

    Deploys the openapi.json file from its generated location (in the 'generate' step above). See the Google docs on Deploying the OpenAPI document

    0 讨论(0)
  • 2021-01-15 17:42

    generat and deploy the OpenAPI configuration file

    $ mvn clean package endpoints-framework:openApiDocs -DskipTests
    $ gcloud endpoints services deploy target/openapi-docs/openapi.json
    $ mvn appengine:run 
    
    0 讨论(0)
提交回复
热议问题