Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you insert Google Glass Mirror credentials from python server side code?

I need some help completing the Mirror Credentials API insertion from my Python server code. We are using the Python Google API library to insert a special auth token into the Mirror API, but I'm getting a blank result from mirror.accounts().insert().execute() where I should be getting at least an error or confirmation that the API token credential we are passing to Google's Mirror API.

Here is our Python server code with some redaction of our secret info, the secret info private keys and client_id's are in a secret .json file we store securely on our server.

with open(os.path.join(os.path.dirname(__file__), 'mirror-credentials.json')) as f:
    credentials_json = json.load(f)
    credentials = SignedJwtAssertionCredentials(
        service_account_name=credentials_json['client_email'],
        private_key=credentials_json['private_key'],
        scope='https://www.googleapis.com/auth/glass.thirdpartyauth',
    )

http = credentials.authorize(httplib2.Http())
mirror = apiclient.discovery.build('mirror', 'v1', http=http)

glass_request = mirror.accounts().insert(
    userToken=$glassware_gallery_user_token,
    accountType='com.mycompany',
    accountName="testAccountName",
    body={
        'features': ["a", "b", "c"],
        'password': $myapp_glass_auth_token,
        'userData': [{"key": "realName", "value": "Rusty Shackleford"}],
        'authTokens': [
        {"type": "drchrono_glass_token", "authToken": $myapp_glass_auth_token}
        ],
    },
)
retValue = glass_request.execute()

Note: $glassware_gallery_user_token is the token we get passed in from the Google App Gallery when we turn our Glassware on (we've already setup our glassware app).

Executing the above code, we get a blank value for retValue, it's an empty dictionary: {} when printed. From the documentation it looks like this should be either an error message or a confirmation.


In response to comment:

Here is a printout of what the request we are sending looks like (got this by inserting print statements into httplib2 source code):

body='{"userData": [{"value": "Rusty Shackleford", "key": "realName"}], "authTokens": [{"authToken": "$omitted_auth_token", "type": "$myapp_glass_token"}], "password": "$omitted_auth_token", "features": ["a", "b", "c"]}',

headers='{'content-length': '305', 'accept-encoding': 'gzip, deflate', 'accept': 'application/json', 'user-agent': 'google-api-python-client/1.2 (gzip)', 'content-type': 'application/json', 'authorization': 'Bearer ya29.hACi3eQf2L2awk3rrLgf1uZQHen2ZANgT_ObBqTNpqrwC6wa_DwjuO9q'}',

request_uri='/mirror/v1/accounts/$my_google_serviceid/$com.myappname/rustyshack?alt=json'

I get a blank dictionary as a response: {}

I can see that this is actually talking to Googles services for 2 reasons:

  1. If I change the user_token to be invalid the code throws an exception.
  2. I can see our API call count in the Google Developer Console counting these attempts as calls against our API quota.

The actual data in the response from Google's servers (printed out in httplib2 has a status code of 204:

'' / '{'fp': , 'status': 204, 'will_close': False, 'chunk_left': 'UNKNOWN', 'length': 0, 'strict': 0, 'reason': 'No Content', 'version': 11, 'debuglevel': 0, 'msg': , 'chunked': 0, '_method': 'POST'}'

@TonyAllevato I'm trying to fetch all accounts on the device with accountManager.getAccounts(); and I'm only getting one account of type "com.google". getAccountsByType("com.xxxxxx") with my app identified supplied during the review process is returning an empty array.

like image 566
MikeN Avatar asked Sep 13 '14 00:09

MikeN


1 Answers

The Insert Mirror API documentation is a little bit incorrect. It returns an empty response with a status header code of 204 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) "No Content" when it is successful. Some parts of the documentation led me to believe it would echo back the credentials in the response, but that was not the case.

On a separate note, I was able to debug why I couldn't get the credentials loading on my Glass by first making sure that I could install my provisional Glassware from the https://google.com/myglass store on my Glass device which makes sure there is connectivity.

like image 174
MikeN Avatar answered Oct 13 '22 21:10

MikeN