检测用户是否通过Google Apps市场登录的最简单方法是什么? [英] What is the easiest way to detect whether a user is logged in via google apps marketplace?

查看:99
本文介绍了检测用户是否通过Google Apps市场登录的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,用户可以使用google oauth2登录.

I have a web application which users log into using google oauth2.

我有此应用程序的google应用程序市场列表,并且部分Google oauth2用户不需要向我的应用程序授予权限,因为他们的google应用程序域管理员在安装应用程序市场列表时就这样做了.

I have a google apps marketplace listing for this application, and some portion of the google oauth2 users didn't need to grant permission to my application because their google apps domain administrator did it while installing the apps marketplace listing.

我希望能够检测到这第二组用户,以分析使用应用程序市场列表登录到我的应用程序的频率.目前,所有google oauth2登录名都与我的应用程序相同.

I'd like to be able to detect this second group of users, to analyze how frequently the apps marketplace listing is being used to log into my application. At the moment all google oauth2 logins look the same to my application.

是否可以通过简单的API调用来确定当前用户是否在该组中?

Is there a simple API call I can make to find out whether the current user is in this group?

推荐答案

我使用以下代码来查找给定appId和目标域的市场列表信息:

I use this code for finding out marketplace listing info for given appId and target domain:

InputStream p12File = Config.class.getResourceAsStream(Config.SERVICE_ACCOUNT_PRIVATE_KEY_RESOURCE_PATH);
PrivateKey serviceAccountPrivateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), p12File, "notasecret", "privatekey", "notasecret");

JsonFactory jsonFactory = new JacksonFactory();
HttpTransport t = GoogleNetHttpTransport.newTrustedTransport();

GoogleCredential.Builder bgc = new GoogleCredential.Builder()
            .setTransport(t)
            .setJsonFactory(jsonFactory)
            .setServiceAccountScopes(Collections.singleton("https://www.googleapis.com/auth/appsmarketplace.license"))
            .setServiceAccountPrivateKey(serviceAccountPrivateKey)
            .setServiceAccountId(Config.SERVICE_ACCOUNT_ID);

GoogleCredential gc = bgc.build();
String token = gc.getAccessToken();
if(token == null) {
  gc.refreshToken();
  token = gc.getAccessToken();
}

HttpGet request = new HttpGet("https://www.googleapis.com/appsmarket/v2/customerLicense/" + applicationId + "/" + customerDomain);
request.setHeader("Authorization", "Bearer " + token);

DefaultHttpClient client = new DefaultHttpClient(httpParams);
HttpResponse resp = client.execute(request);
// ... read API JSON response

这篇关于检测用户是否通过Google Apps市场登录的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆