A library for making OAuth with Google easier!
GlassAuth is an easy to use library designed to make authentication with a Google Account easier. Have you seen applications using QR codes to send OAuth tokens to Glass? That's not quite a good idea. GlassAuth makes use of Google's OAuth for Devices. All the user has to do is enter a code here.
GlassAuth takes care of making a slick sign in process (with UI and all), and makes authorized HTTPS requests in just a few lines.
It is expected that you have a project setup at the Google Developer Console, with the Google+ API enabled and OAuth certificates generated.
- Clone the source of this application and include it as a library in your Glass project.
- In the GlassAuth library, go to
src/com/victor/kaiser/pendergrast/auth/setup/AuthConstants.java
and set theCLIENT_ID
andCLIENT_SECRET
according to what you generated at the Google Developer Console. - Use manifest merger, or declare the
AuthActivity
in your manifest like so:<activity android:name="com.victork.kaiser.pendergrast.auth.AuthActivity" />
- In your UI, have the user sign in by starting an
AuthActivity
- Later, you can confirm the user is signed in by calling
AuthHelper.isAuthenticated()
- Use
AuthHttpsRequest
to make authenticated requests. You can add JSON parameters and change the HTTP request method to whatever you need. TheOnResponseListener
you specify will be called when a response is received. AuthHttpsTask request = new AuthHttpsTask(context, url, json, "POST", listener); request.execute();
The onResponse(boolean success, String response)
method in OnResponseListener
may not behave as you expect. success
only indicates if the HTTPS request returned 200 "good" code. Response
is simply the response from the server.
For some more background on this method, see my GlassNotes repo, or this presentation.