authentication against google in java

Google, Yahoo and others allows to authenticate users using OpenID protocol. Some pages are here and openid4j .

In my last post I have mentioned about google data libraries which is actually APIs for most of the google services, including to authenticate users and much more. GData libraries are let’s say higher level layer which handles all the openid pain for you. 2 simple lines of code and you are authenticate 🙂

Here is simple example


<project xmlns="" xmlns:xsi=""xsi:schemaLocation="">



Simple java project:

package com.majecek.gdata;

public class App
 public static void main( String[] args )
 GoogleService myService = new CalendarService("some_apps");
 try {
 myService.setUserCredentials("userLogin".concat(""), "password");
 //if success then succes authentication occures
 System.out.println("success authentication");
 } catch (AuthenticationException e) {
 //if not then invalid credentials has been set
 //invalid username or password
 System.out.println("invalid authentication");

Example can be downloaded from google code repository. It is maven project.

I have updated and uploaded this example to github. Read README.

The bigest advantage is that we don’t need to handle any “openid” tricks, just creates service against google service (in my example Calendar) and call “setUserCredentials” which already authenticate user.

Credits go also @Petr Olivka

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s