Endpoints with oAuth: Get Current ClientId

I just started building with Endpoints in the Google App Engine, and everything seems to be working fine. My API rejects non-whitelisted client identifiers and allows multiple users to whitelist.

One thing that I currently cannot work with, although it gets the client ID, which calls my endpoint.

This seems trivial, but I cannot figure out where to look.

+4
source share
2 answers

In python libraries, the client identifier is part of the user object. You can get the same information from an instance com.google.appengine.api.users.Userthat returns endpoint authentication.

Link: https://cloud.google.com/appengine/docs/java/endpoints/getstarted/backend/code_walkthrough#oauth_protecting_a_method

0
source

In your comment, you mentioned that you really want to determine which version of your application you are currently using. For this or similar purposes, my entire project with my application engine has a small Util class containing something like this:

/**
 * Whether this is a development server or production environment
 */
public static final boolean DEBUG = (SystemProperty.environment.value() != SystemProperty.Environment.Value.Production);

/**
 * AppId this application is running under (works in production environment)
 */
public static final String APP_ID = SystemProperty.applicationId.get();

/**
 * The mail domain for this application
 */
public static final String MAIL_DOMAIN = AppengineEnv.APP_ID + ".appspotmail.com";

, DEBUG . , , APP_ID, GAE, "myappid_beta", "myappid_alpha" ..

, , , , , - , Android. , , .

- . - , , , . :

class BusinessLogic {
    public static void doAwesomeStuff(String version, ManyMoreParams){ ... }
}

@Api (
    version = "beta",
    ...
)
class BetaEndpoints {
   private static final String VERSION = "beta",
   @ApiMethod( ... )
   public void doStuff(){
      BusinessLogic.doAwesomeStuff(VERSION, moreparams);
   }
}

@Api (
    version = "alpha",
    ...
)
class BetaEndpoints {
   private static final String VERSION = "alpha",
   @ApiMethod( ... )
   public void doStuff(){
      BusinessLogic.doAwesomeStuff(VERSION, moreparams);
   }
}
0

Source: https://habr.com/ru/post/1608044/


All Articles