Note that there are some explanatory texts on larger screens.

plurals
  1. POMarketplace app + Provisioning API: check if user is admin
    primarykey
    data
    text
    <p>I'm trying to check if a user is admin of their Google Apps domain, in an app installed from the Google Apps marketplace.</p> <p>I added this to manifest.xml:</p> <pre><code>&lt;Scope id="Provisioning API"&gt; &lt;Url&gt;https://apps-apis.google.com/a/feeds/user/#readonly&lt;/Url&gt; &lt;Reason&gt;This application can list domain users to give them permissions.&lt;/Reason&gt; &lt;/Scope&gt; </code></pre> <p>Then I set a test handler to get it working:</p> <pre><code>from google.appengine.ext import webapp from google.appengine.ext.webapp import util import gdata.alt.appengine import gdata.apps.service import gdata.auth # App id, key and secret from the Google Apps Marketplace. APPLICATION_ID = 'XXX' CONSUMER_KEY = 'XXX' CONSUMER_SECRET = 'XXX' class SetupHandler(webapp.RequestHandler): def get(self, *args): # The domain where this app is installed. domain = 'my_customer_domain.com' # A username to check. username = 'webmaster' sig_method = gdata.auth.OAuthSignatureMethod.HMAC_SHA1 service = gdata.apps.service.AppsService(source='tipfy-com', domain=domain) service.SetOAuthInputParameters(sig_method, CONSUMER_KEY, consumer_secret=CONSUMER_SECRET, two_legged_oauth=True, requestor_id=APPLICATION_ID) service.ssl = True service.debug = True gdata.alt.appengine.run_on_appengine(service) lookup_user = service.RetrieveUser(username) if lookup_user.login.admin == 'true': res = username + ' is an admin.' else: res = username + ' is not an admin.' self.response.out.write(res) app = webapp.WSGIApplication([ ('/.*', SetupHandler), ], debug=True) def main(): util.run_wsgi_app(app) if __name__ == '__main__': main() </code></pre> <p>But I get a 401 response ("Unknown authorization header"). I don't know what I'm doing incorrectly or how to debug it further. </p> <ul> <li>Is the manifest entry correct? </li> <li>Splitting <code>user.email()</code> is ok to get the user's username and domain? (I debugged it and in my case it was: I got 'webmaster' and 'example.com', which was the user and Google Apps domain where the app was installed). </li> </ul> <p>What am I missing?</p> <p><strong>Edit:</strong> For some reason, the admin panel didn't ask permission to grant access to the provided scopes. After I granted it, the code above worked. So take it as a working example!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload