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

1

6

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.

Overhang answered 13/9, 2014 at 0:27 Comment(5)
Nothing immediately jumps out to me as being wrong there. Is there any way that you can you provide a raw dump of the request to and response from the server, before the client library does its Python data type conversion?Cestar
@TonyAllevato I'm printing request we build from the Mirror API Python object. I don't know how to dig into the actual API code any deeper. Are there working Python examples of GDK authentication I can look at and follow?Overhang
I'm personally offering an additional $250 Outback steakhouse gift card to someone who can help me fix this problem.Overhang
The 204 (no content) response code is a success error code, and other users have reported that even though the API call returns a null/empty response, they've had the account be available on Glass after that ( #25278972). Can you check whether it's made it or not to the AccountManager on the device? This could just be behavior that's inconsistent with our docs.Cestar
@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.Overhang
O
1

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.

Overhang answered 23/9, 2014 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.