88812

What is the easiest way to detect whether a user is logged in via google apps marketplace?

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

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.

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.

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

Answer1:

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

Recommend

  • Using parses Facebook login api, results in current user null
  • How protective should I be of my Facebook AppId?
  • getResource() to a file on runtime
  • How to find documents with exactly the same array entries as in a query
  • Is it possible to access raw iphone audio output?
  • How to get all Facebook friend`s Id at once?
  • How can I see Python's __builtins__ source code?
  • Integrate two requests into one Javascript
  • How can I encode a filename according to RFC 2231?
  • Using Delphi + Jedi, losing USB data when device sends it “too fast”
  • JsonConverter: Get parent object in ReadJson, without $refs
  • insert a picture into database(sqlite) with java code. what should i do?
  • Efficient User-Agent Regex to find Safari in Python
  • In Java, how can I construct a File from a resource?
  • Shouldn't else be indented in the below code
  • JSON encode and decode on PHP
  • Building Qt project for C++11 standard
  • UWP/C# - Issue with AQS and USB Devices
  • How to make JSON.NET deserialize to Microsoft Date Time?
  • Read text file that is not in the main package in a runnable jar
  • one Local Olampyad Questions on Informatic in 2011
  • How to rebase a series of branches?
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • Shallow update not allowed (git > 1.9)
  • jquery mobile loadPage not working
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Circular dependency while pushing http interceptor
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • How to include full .NET prerequisite for Wix Burn installer
  • Acquiring multiple attributes from .xml file in c#
  • Qt: Run a script BEFORE make
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory
  • How can i traverse a binary tree from right to left in java?
  • UserPrincipal.Current returns apppool on IIS
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF
  • How can I use threading to 'tick' a timer to be accessed by other threads?