简体   繁体   中英

How do I add Google Account authentication to Google Cloud Endpoints in Python

I'm trying to make a Google Cloud Endpoints backend for my Android app that uses a user's Google Account for authentication. I've found that the Java API contains annotations for OAuth scopes, but the python documentation only makes a single reference to that.

Here is the annotation I'm using on the endpoint:

@endpoints.api(name='notes', version='v1',
           description='Notes API',
           allowed_client_ids=[CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID],
           audiences=[AUDIENCE],
           scopes=['https://www.googleapis.com/auth/userinfo.email'])

But the generated code doesn't have any scopes:

/**
 * Available OAuth 2.0 scopes for use with the .
 *
 * @since 1.4
 */
public class NotesScopes {

  private NotesScopes() {
  }
}

Even the generated service class seems to be missing pieces:

/**
 * The default encoded root URL of the service. This is determined when the library is generated
 * and normally should not be changed.
 *
 * @since 1.7
 */
public static final String DEFAULT_ROOT_URL = "https://None/_ah/api/";

/**
 * The default encoded service path of the service. This is determined when the library is
 * generated and normally should not be changed.
 *
 * @since 1.7
 */
public static final String DEFAULT_SERVICE_PATH = "notes/v1/";

I'm assuming that I'm missing some annotation or config option. Does anyone know what it might be?

The scopes attribute in the annotation isn't used in the Android auth flow, which is one of the reasons it's not included in the generated Java code. Instead, Android uses an ID token, which contains sufficient information to represent your user/application to the backend, without requesting a scope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM